首页 > 技术文章 > 服务器 gd库扩展开启

corvus 2020-05-13 15:29 原文

./configure
--prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --enable-fpm
--enable-sysvsem --enable-sockets --enable-pcntl --enable-mbstring
--enable-mysqlnd --enable-opcache --enable-shmop --enable-ftp --enable-wddx
--enable-soap --with-mysqli --with-apxs2=/usr/local/apache/bin/apxs --with-pdo-mysql
--with-curl  --with-gd --with-jpeg-dir=/usr/local/jpeg/

1. 进入源码目录

 cd

 /mysoft/php-7.3.11

2. 编译

./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --enable-fpm --enable-sysvsem --enable-sockets --enable-pcntl --enable-mbstring --enable-mysqlnd --enable-opcache --enable-shmop --enable-ftp --enable-wddx --enable-soap --with-mysqli --with-apxs2=/usr/local/apache/bin/apxs --with-pdo-mysql --with-curl  --with-gd --with-jpeg-dir=/usr/local/jpeg/ --with-freetype-dir=/usr/include/freetype2/ --enable-gd-native-ttf

3.

make
&& make install

提示 

 

报错的原因是php中gd库的相关图片能力没有正确开启和引用

通过phpInfo()查看 gd库已经开启,但是里边没有freeType 和jpeg的支持 但有png的支持 

1、如果是 freetype 跟 jpeg没有安装

则安装这两软件

yum install freetype*

yum install libjpeg*

安装之后寻找安装路径find / -name freetype

结果在 /usr/include/freetype2/  文件夹中

同理  libjpeg 在 /usr/include  中

2、进入php源代码的   php源代码(下载的代码)/ext/gd文件夹中 利用phpize进行拓展安装

初始化php组件安装环境:/usr/local/php/bin/phpize

配置gd编译环境:./configure --with-freetype-dir=/usr/include/freetype2 --enable-gd-native-ttf  --with-jpeg-dir=/usr/include   --with-php-config=/usr/local/php/bin/php-config      注意加粗部分,不加这个还是没有开启freetype能力,仍然会报imagettftext函数不存在的错误(第一次没有加这个配置,编译安装gd后还是报错)

编译:make

安装:make install

[root@shop2 gd]# make install
Installing shared extensions:     /usr/local/php5.6.36/lib/php/extensions/no-debug-non-zts-20131226/
Installing header files:           /usr/local/php5.6.36/include/php/
[root@shop2 gd]# cd /usr/local/php5.6.36/lib/php/extensions/no-debug-non-zts-20131226/
[root@shop2 no-debug-non-zts-20131226]# ll
-rwxr-xr-x  1 root root 1401784 Nov 13 16:40 gd.so

安装后到安装的目录查看一下,重启php-fpm,再看phpinfo(),则有完整的gd各个图片库能力了,主要是红框部分

 

再运行程序也不会再报imagettftext函数不存在的错误了

推荐阅读