一、问题描述:
ThinkPHP做文字水印 ,出现报错Call to undefined function imagettftext(),发现是gd库出现了问题
通过phpInfo()查看 gd库已经开启,但是里边没有freeType 和jpeg的支持 但有png的支持
估计是 freetype 跟 jpeg没有安装
二、解决方法:
yum install freetype* yum install libjpeg*
装完后 找一下库装到哪里去了
find / -name freetype
结果在 /usr/include/freetype2/ 文件夹中
同理 libjpeg 在 /usr/include 中
然后进入php源代码的 php源代码(下载的代码)/ext/gd文件夹中 利用phpize进行拓展安装
(我的php安装在/usr/local/php72中)
/usr/local/php72/bin/phpize ./configure --with-freetype-dir=/usr/include/freetype2 --with-jpeg-dir=/usr/include --with-php-config=/usr/local/php72/bin/php-config
make && make install
到此 完成了php中GD库到重新编译,重启后问题圆满解决
三、如果上面没有解决、重新编译安装php(我当时就重新编译后解决了)
进入php的源码目录
#首先make clean make clean #配置 ./configure --prefix=/usr/local/php72 --enable-fpm --with-mysqli --with-zlib --with-curl --with-gd --with-jpeg-dir --with-freetype-dir --with-png-dir --with-openssl --with-pdo-mysql --enable-mbstring --enable-xml --enable-session --enable-ftp --enable-pdo
#运行编译和安装命令 make && make installt
添加PHP和PHP-fpm配置文件
cp /usr/local/src/php72/php.ini-production /etc/php.ini cd /usr/local/php72/etc/ cp php-fpm.conf.default php-fpm.conf sed -i 's@;pid = run/php-fpm.pid@pid = /usr/local/php72/var/run/php-fpm.pid@' php-fpm.conf
添加PHP-FPM启动脚本
cp /usr/local/src/php72/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm chmod +x /etc/init.d/php-fpm
添加PHP-FPM至服务列表并设置开机自启
chkconfig --add php-fpm chkconfig --list php-fpm chkconfig php-fpm on
启动服务。
service php-fpm start
通过phpInfo()查看