LoginSignup
1
2

More than 3 years have passed since last update.

Laravel の tinkerで日本語入力ができず色々迷走していたらもっと根本的な問題だった件

Posted at

最初に

以下、当初参考にさせて頂いた記事です。
Laravel の tinker で日本語が入力できなくて困ったけどなんとかなった話

私の場合、先輩より助言を頂き以下の記事を参考に実施してみた。
Laravel の tinker で日本語が入力出来ない

早速進めてみる

記事を見るに、libeditのversionが古い為最新のlibeditを自身で取得、
シンボリックリンクを差し替えるという方法のよう。

*前提:以下の手順はPHPのDocker Container内で行っている。
①今のlibedit がどうなっているか確認

root@6d5cb7f51e5f:/# apt-cache show libedit-dev
Package: libedit-dev
Source: libedit
Version: 3.1-20181209-1
Installed-Size: 486
Maintainer: LLVM Packaging Team <pkg-llvm-team@lists.alioth.debian.org>
Architecture: amd64
Depends: libedit2 (= 3.1-20181209-1), libbsd-dev (>= 0.1.3), libncurses-dev | libtinfo-dev
Description: BSD editline and history libraries (development files)
Description-md5: d563680e6c8f51c40aea576bffaea165
Multi-Arch: same
Homepage: https://www.thrysoee.dk/editline/
Tag: devel::library, implemented-in::c, interface::text-mode,
 role::devel-lib, role::program, suite::bsd, uitoolkit::ncurses,
 use::editing
Section: libdevel
Priority: optional
Filename: pool/main/libe/libedit/libedit-dev_3.1-20181209-1_amd64.deb
Size: 114472
MD5sum: 41ada765583355c35c9fc7dd23267d39
SHA256: 2eb60366c863b0eef054b6bc688dec1fcb526a132a680d3673f75205787a0ddf

②phpのパスを確認

root@6d5cb7f51e5f:/# which php
/usr/local/bin/php

続いて以下コマンドを実行し、どこにリンクが貼られているか確認

root@6d5cb7f51e5f:/# ldd /usr/local/bin/php | grep libedit
    libedit.so.2 => /usr/lib/x86_64-linux-gnu/libedit.so.2 (0x00007fe439006000)

③libedit の最新版をinstallする

# cd /usr/local/src/
# wget https://www.thrysoee.dk/editline/libedit-20191211-3.1.tar.gz
# tar zxvf libedit-20191211-3.1.tar.gz
# cd libedit-20191211-3.1/
# ./configure
...

configure: error: libncurses, libcurses, or libtermcap is required!
上記のようにinstallするように言われるので、以下コマンドでinstallしておく。

# apt-get install -y libncursesw5-dev

続けて以下コマンドを実行する。
# ./configure
# make
# make install

④シンボリックリンクの差し替え

root@6d5cb7f51e5f:/usr/lib/x86_64-linux-gnu# ls -la | grep libedit
lrwxrwxrwx 1 root root    17 Dec 12 2018 libedit.so.2 -> libedit.so.2.0.59
-rw-r--r-- 1 root root  204344 Dec 12 2018 libedit.so.2.0.59

#既に存在しているシンボリックリンクをunlinkする
root@6d5cb7f51e5f:/usr/lib/x86_64-linux-gnu# unlink libedit.so.2

root@6d5cb7f51e5f:/usr/lib/x86_64-linux-gnu# ls -la | grep libedit
-rw-r--r-- 1 root root  204344 Dec 12 2018 libedit.so.2.0.59

#リンクの差し替え
root@6d5cb7f51e5f:/usr/lib/x86_64-linux-gnu# ln -s /usr/local/lib/libedit.so.0 libedit.so.2

root@6d5cb7f51e5f:/usr/lib/x86_64-linux-gnu# ls -la | grep libedit
lrwxrwxrwx 1 root root    27 Feb 22 22:12 libedit.so.2 -> /usr/local/lib/libedit.so.0
-rw-r--r-- 1 root root  204344 Dec 12 2018 libedit.so.2.0.59

⑤パス:/usr/local/libを確認

root@548a9ad5b2fa:/usr/local/lib# ls -la
total 2484
drwxr-xr-x 1 root root   4096 Feb 23 22:08 .
drwxr-xr-x 1 root root   4096 Jan 12 02:27 ..
-rw-r--r-- 1 root root 1646062 Feb 23 22:08 libedit.a
-rwxr-xr-x 1 root root   928 Feb 23 22:08 libedit.la
lrwxrwxrwx 1 root root    17 Feb 23 22:08 libedit.so -> libedit.so.0.0.62
lrwxrwxrwx 1 root root    17 Feb 23 22:08 libedit.so.0 -> libedit.so.0.0.62
-rwxr-xr-x 1 root root  863760 Feb 23 22:08 libedit.so.0.0.62
drwxr-xr-x 1 root root   4096 Jan 12 02:28 php
drwxr-xr-x 2 root root   4096 Feb 23 22:08 pkgconfig
drwxrwsr-x 4 root staff  4096 Jan 25 13:32 python2.7
drwxrwsr-x 3 root staff  4096 Jan 25 13:31 python3.7

ここまでで現状確認の為、tinkerで日本語入力を試みる。
しかし!! 解決しなかったのです。

先輩からの一言 
「PHPのコンテナ内では日本語入力できますか?」

問題の切り分けができていな自分の未熟さを痛感しました。
そもそもコンテナ内で日本語が使えなかったのです。

PHPのDockerfileに以下を追加。

Dockerfile
RUN apt-get update && \
    apt-get install -y locales && \
    echo "ja_JP UTF-8" > /etc/locale.gen && \
    locale-gen && \
    echo "export LANG=ja_JP.UTF-8" >> ~/.bashrc

終局

tinkerで日本語を入力してみる。
*PHPコンテナ内での日本語入力は解決。

>>> App\Models\Company::where('name', "ホゲホゲ会社 大阪支店")->get();
=> Illuminate\Database\Eloquent\Collection {#4193
    App\Models\Company {#3253
     id: 2,
     name: "ホゲホゲ会社 大阪支店",
     email: "hoge@sample.com",
     phone_number: "",
     postal_code: "",
     address: "",
  }
}

やっと解決!!

一から環境構築するにはまだまだ知識不足だということを痛感した反面、
便利ツールに頼らないことでいい経験ができました。
先輩に感謝。

1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2