LoginSignup
2
3

More than 3 years have passed since last update.

PHP-GDのJpeg Support と FreeType Support を有効にする

Last updated at Posted at 2020-06-11

はじめに

PHP5系のサーバで、GDがちゃんと動いていないので対応してくれという依頼。

環境調査

# php -r "print_r( gd_info() );"
Array
(
    [GD Version] => bundled (2.0.34 compatible)
    [FreeType Support] =>
    [T1Lib Support] =>
    [GIF Read Support] => 1
    [GIF Create Support] => 1
    [JPG Support] =>
    [PNG Support] => 1
    [WBMP Support] => 1
    [XPM Support] =>
    [XBM Support] => 1
    [JIS-mapped Japanese Font Support] =>
)

うん、GDは入ってるけどJPEGサポートとFreeTypeサポートが動いてない。

OS: Amazon Linux2
PHP: 5.2.17

PHPはyumで入れたものではなくてソースからビルドして入れた形跡がある。

# yum list installed | grep php
php-common.x86_64                     5.4.16-46.amzn2.0.2            @amzn2-core

PHPが5.4.16の時は動いていたっぽい。すでにライブラリはインストールされている、

# yum list installed | grep libjpeg*
libjpeg-turbo.x86_64                  1.2.90-5.amzn2.0.3             installed
libjpeg-turbo-devel.x86_64            1.2.90-5.amzn2.0.3             @amzn2-core
# yum list installed | grep freetype-devel
freetype-devel.x86_64                 2.4.11-15.amzn2.0.2            @amzn2-core

インストール時のオプションを調査する。

# php -i | grep configure | sed -e 's/  /\n/g'
'./configure'
'--prefix=/php-5.2.17' ...()...'--with-gd=shared' ...()...

--with-gdはあるけど--with-jpeg-dir--with-freetype-dirは指定されてない。これを指定するといいんだな。

# find / -name libfreetype*
/usr/lib64/libfreetype.so.6
/usr/lib64/libfreetype.so.6.10.0
/usr/lib64/libfreetype.so
# find / -name libjpeg*
/usr/lib64/libjpeg.so.62
/usr/lib64/libjpeg.so.62.1.0
/usr/lib64/libjpeg.so

指定するのは/usr/lib64だな。

試行錯誤

Qiitaの記事ですごく簡潔でいい記事を見つけたので、このサイトの通りに実行する
https://qiita.com/sh_cs/items/0f5558d5b95b746d58e2

# cd /hoge/php-5.2.17
# ./configure --prefix=/php-5.2.17 (略) --with-gd=shared (略) --with-jpeg-dir=/usr/lib64 --with-freetype-dir=/usr/lib64
# make
# make install
# systemctl restart httpd

これで反映されてるはず。

# php -r "print_r( gd_info() );"
Array
(
    [GD Version] => bundled (2.0.34 compatible)
    [FreeType Support] =>
    [T1Lib Support] =>
    [GIF Read Support] => 1
    [GIF Create Support] => 1
    [JPG Support] =>
    [PNG Support] => 1
    [WBMP Support] => 1
    [XPM Support] =>
    [XBM Support] => 1
    [JIS-mapped Japanese Font Support] =>
)

あれ?変わりなし。

ヒントを見つける

この間、libjpegの再ビルドやパスの見直しなどするも効果なし。諦めかけたところで、以下のStackOverflowのコメントを見つける。

これだあ!!!! make cleanを実行してもう一度やり直すと


# php -r "print_r( gd_info() );"
Array
(
    [GD Version] => bundled (2.0.34 compatible)
    [FreeType Support] => 1
    [FreeType Linkage] => with freetype
    [T1Lib Support] =>
    [GIF Read Support] => 1
    [GIF Create Support] => 1
    [JPG Support] => 1
    [PNG Support] => 1
    [WBMP Support] => 1
    [XPM Support] =>
    [XBM Support] => 1
    [JIS-mapped Japanese Font Support] =>
)

やった!!!

キャッシュが残ってたんですね…。

まとめ

終わってみたらなんてことなかったですが、随分遠回りしました。私の貴重な1日返せ!

参照リンク

2
3
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
2
3