CentOS5 php に GD モジュールがインストール出来ない
サーバーのクリーンインストールして、当サーバーは構築してきましたがどうやらPHPにGDモジュールが組み込まれていないことが発覚しました。^^;;
必要なモジュールを次々とインストールさせていきましたがGDは直接動作に必要なく気がつくまでに時間がかかってのではないかと。
とりあえず、入れないことにはWordPressで画像の縮尺やCAPTCHが使えない。
インストールまでの記録を記述していきます。
サーバーの状態
- CentOS 5.6
- PHP 5.2.16
- 64bit Operating System
現状
# yum install php-gd Loaded plugins: fastestmirror, priorities Loading mirror speeds from cached hostfile * base: rsync.atworks.co.jp * extras: rsync.atworks.co.jp * rpmforge: fr2.rpmfind.net * updates: rsync.atworks.co.jp 72 packages excluded due to repository priority protections Setting up Install Process Resolving Dependencies --> Running transaction check ---> Package php-gd.x86_64 0:5.1.6-27.el5_5.3 set to be updated --> Processing Dependency: php-common = 5.1.6-27.el5_5.3 for package: php-gd --> Finished Dependency Resolution php-gd-5.1.6-27.el5_5.3.x86_64 from base has depsolving problems --> Missing Dependency: php-common = 5.1.6-27.el5_5.3 is needed by package php-gd-5.1.6-27.el5_5.3.x86_64 (base) Error: Missing Dependency: php-common = 5.1.6-27.el5_5.3 is needed by package php-gd-5.1.6-27.el5_5.3.x86_64 (base) You could try using --skip-broken to work around the problem You could try running: package-cleanup --problems package-cleanup --dupes rpm -Va --nofiles --nodigest |
これと同様の現象と戦ったブログはこちらです。
ワン!ワワン!ニャ~!
こちらの方は、一度 php-common を yum remove させる方法をとっておられます。
作事を実行しようとすると依存関係のための下記のような削除プログラムがでます。
==================================================================================================================== Package Arch Version Repository Size ==================================================================================================================== Removing: php-common x86_64 5.2.16-jason.1 installed 1.6 M Removing for dependencies: mod_suphp x86_64 0.7.1-1.el5.rf installed 2.1 M php x86_64 5.2.16-jason.1 installed 11 M php-cli x86_64 5.2.16-jason.1 installed 6.6 M php-devel x86_64 5.2.16-jason.1 installed 2.7 M php-ldap x86_64 5.2.16-jason.1 installed 136 k php-mbstring x86_64 5.2.16-jason.1 installed 3.0 M php-mcrypt x86_64 5.2.16-jason.1 installed 110 k php-mysql x86_64 5.2.16-jason.1 installed 733 k php-pdo x86_64 5.2.16-jason.1 installed 408 k php-pear noarch 1:1.9.1-1.jason.1 installed 2.1 M Transaction Summary ==================================================================================================================== Remove 11 Package(s) Reinstall 0 Package(s) Downgrade 0 Package(s) |
最悪この方法でも良いのですが、これは最終手段として別の方法を模索したいと思います。
試行錯誤
僕の取った解決方は、GD自体はすでにyumで入っていますので残りはphp-GDモジュールのみ。
これだけ何とかすればいいので、rpmパッケージで直接GDモジュールを組み込めないかとかをトライしてみました。
rpm パッケージを探してきて、rpm -ivh で実行するも案の定依存性エラー
そりゃ、yumとやっていることは一緒ですからエラーが帰ってくるのはあたりまえですね。
ちょっと期待していたのが、–force と –nodeps オプション
–force 強制的にインストールを実行する
–nodeps 依存性を無視してインストール
まず、forceの結果はインストール自体が上手くいきませんでした^^;;
nodepsはインストール自体は無事に完了できます。
php.iniにextention=gd.soでモジュールを指定して、apacheを再起動すると、モジュール読み込みエラーがログに出力されます orz
依存性もなにも、php-common自体はすでに導入済みのハズなのでこれで行けそうなもんですがそんな単純な問題ではないようです。
解決方
さすがにコレは出来るだろうと思って最後まで暖めていたのが、ソースコードからのコンパイルインストール。
結論から言ってこれは上手くいきました。
まずは、環境が整っているかを確認します。
# gdlib-config --version 2.0.33 # php -v 5.2.16 # locate libjpeg /usr/lib/libjpeg.so.62 /usr/lib/libjpeg.so.62.0.0 /usr/lib/jvm/java-1.6.0-openjdk-1.6.0.0.x86_64/jre/lib/amd64/libjpeg.so /usr/lib64/libjpeg.so /usr/lib64/libjpeg.so.62 /usr/lib64/libjpeg.so.62.0.0 ~省略~ # locate libpng/usr/lib/libpng.so.3 /usr/lib/libpng.so.3.10.0 /usr/lib/libpng12.so.0 /usr/lib/libpng12.so.0.10.0 /usr/lib64/libpng.a /usr/lib64/libpng.so /usr/lib64/libpng.so.3 /usr/lib64/libpng.so.3.10.0 /usr/lib64/libpng12.a /usr/lib64/libpng12.so /usr/lib64/libpng12.so.0 /usr/lib64/libpng12.so.0.10.0 |
上記ですべてそろっていることが確認出来ました。
libjpeg と libpng はyumでインストール出来るので入っていない場合はインストールしておきます。
続いてインストールされているphpと同一のバージョンのソースコードを取ってきます。
php-gdモジュールのソースコードはphpの言語ソースコードに同梱されています。
phpの各バージョンはこちらからダウンロードできます。
https://www.php.net/downloads.php
僕のサーバーにはいっているphpのバージョンは 5.2.16 ですので同じバージョンのソースコードをダウンロード、展開します。
GDモジュールのソースコードはext/gdの中に入っています。
# tar zxvf php-5.2.16.tar.gz # cd php-5.2.16/ext/gd # phpize Configuring for: PHP Api Version: 20041225 Zend Module Api No: 20060613 Zend Extension Api No: 220060519 aclocal # ./configure ~中略~ checking for the location of libjpeg... no checking for the location of libpng... no checking for the location of libz... no checking for the location of libXpm... no checking for FreeType 1.x support... no checking for FreeType 2... no checking for T1lib support... no checking whether to enable truetype string function in GD... no checking whether to enable JIS-mapped Japanese font support in GD... no checking for fabsf... no checking for floorf... no If configure fails try --with-jpeg-dir=<DIR> configure: error: libpng.(a|so) not found. |
なにおっ
さきほどlibpngの存在を確認下にもかかわらず、libpngが見つからないというエラー。
今度は明示的にconfigureにディレクトリを指定してあげることにします。
./configure --enable-gd-native-ttf --enable-gd-jis-conv --enable-shared --wi th-gd --with-jpeg-dir=/usr --with-png-dir=/usr --with-zlib-dir=/usr --with-xpm-dir=/u sr --with-ttf=/usr --with-freetype-dir=/usr --with-t1lib=/usr ~中略~ checking for gawk... gawk checking for GD support... yes, shared checking for the location of libjpeg... /usr checking for the location of libpng... /usr checking for the location of libz... /usr checking for the location of libXpm... /usr checking for FreeType 1.x support... /usr checking for FreeType 2... /usr checking for T1lib support... /usr checking whether to enable truetype string function in GD... yes checking whether to enable JIS-mapped Japanese font support in GD... yes configure: error: libjpeg.(a|so) not found. |
orz
libpngは無事認識した物のこんどはlibjpegですか、そうですかそうですか。
ディレクトリを指定して、pngは認識してjpegが認識しない・・・
この違いはどこだろうと考えたところ、libにlibjpeg.soが入っていないw
単純に64bit OSなので、libではなく、lib64を見に行かなければなりません。
32bit OSでしたら、おそらくこの問題に引っかからずに無事configureが通ったのではないかと。
では、configure にlibではなくlib64を見に行く指定を追加します。
–with-libdir=lib64
がそれにあたります。
# ./configure --with-libdir=lib64 --enable-gd-native-ttf --enable-gd-jis-conv --enable-shared --with-gd --with-jpeg-dir=/usr --with-png-dir=/usr --with-zlib-dir=/u sr --with-xpm-dir=/usr --with-ttf=/usr --with-freetype-dir=/usr --with-t1lib=/usr ~中略~ checking whether to enable truetype string function in GD... yes checking whether to enable JIS-mapped Japanese font support in GD... yes checking for jpeg_read_header in -ljpeg... yes checking for png_write_image in -lpng... yes checking for XpmFreeXpmImage in -lXpm... yes checking for FT_New_Face in -lfreetype... yes checking for FreeType 1 support... no - FreeType 2.x is to be used instead configure: error: Your t1lib distribution is not installed correctly. Please reinstall it. |
お・・・
またエラーです。
t1libが入っていないか再インストールとのことなので・・・
# yum install t1lib.x86_64 t1lib-devel.x86_64 |
でインストール
再度configureを実行させます。
# ./configure --with-libdir=lib64 --enable-gd-native-ttf --enable-gd-jis-conv --enable-shared --with-gd --with-jpeg-dir=/usr --with-png-dir=/usr --with-zlib-dir=/u sr --with-xpm-dir=/usr --with-ttf=/usr --with-freetype-dir=/usr --with-t1lib=/usr ~中略~ checking dynamic linker characteristics... GNU/Linux ld.so checking how to hardcode library paths into programs... immediate configure: creating ./config.status config.status: creating config.h |
やったー!
無事configureが実行されました。
続いて
# make ---------------------------------------------------------------------- Libraries have been installed in: /home/admin/src/php/php-5.2.16/ext/gd/modules If you ever happen to want to link against installed libraries in a given directory, LIBDIR, you must either use libtool, and specify the full pathname of the library, or use the `-LLIBDIR' flag during linking and do at least one of the following: - add LIBDIR to the `LD_LIBRARY_PATH' environment variable during execution - add LIBDIR to the `LD_RUN_PATH' environment variable during linking - use the `-Wl,--rpath -Wl,LIBDIR' linker flag - have your system administrator add LIBDIR to `/etc/ld.so.conf' See any operating system documentation about shared libraries for more information, such as the ld(1) and ld.so(8) manual pages. ---------------------------------------------------------------------- Build complete. Don't forget to run 'make test'. # make install |
無事、makeもmake installも通りました。
これでphpの所定の位置にモジュールが出力されているハズですので・・・
php.iniのextentionの書かれているあたりに下記を追加します。
extension=gd.so
で、apacheを再起動させログを確認。。。
エラー無し。
では、phpinfoで確認
ジャッジャーン
無事、GDモジュールが認識いたしました。
結構大変な作業でした。
よほどな理由がなければ、やはりyumでphp-commonをremoveさせてから再インストールさせたほうが簡単で早いと思います。
関連のありそうなエントリ