不重新编译PHP,使用PHP GD捆绑扩展 - 解决方案

5

捆绑扩展提供了很多功能。我花了很多时间来编译与我的PHP版本兼容的扩展。以下是说明。

2个回答

15

0, 安装PHP开发包。同时您应该已经安装了带有GD扩展的PHP(但不是捆绑的)。

sudo apt-get install php5-dev

1, 下载所需PHP版本的源代码(例如5.6.18)

wget http://cz2.php.net/get/php-5.6.18.tar.gz/from/this/mirror -O php-5.6.18.tar.gz

2, 解压缩档案

tar -xzf php-5.6.18.tar.gz

3、 进入GD扩展的源代码

cd php-5.6.18/ext/gd/

准备扩展(在该目录下运行phpize命令)。
phpize

5, 现在进行配置命令

5.1, 参数取决于您的Linux发行版。我使用的是以下参数:

--with-freetype-dir=shared,/usr --with-vpx-dir=shared,/usr --with-jpeg-dir=shared,/usr --with-xpm-dir=shared,/usr/X11R6

5.2,获取库路径必须运行此命令,并仅搜索上述指定的搜索参数(5.1)。

php-config --configure-options

5.3,同时为配置添加以下参数(第二个参数是打包版本)

--with-php-config=/usr/bin/php-config --with-gd 

6, 最终配置命令

sudo ./configure --with-php-config=/usr/bin/php-config --with-gd --with-freetype-dir=YOUR_VALUE --with-vpx-dir=YOUR_VALUE --with-jpeg-dir=YOUR_VALUE --with-xpm-dir=YOUR_VALUE

7, 现在运行 make 命令

make

8, 编译完成后,您应该看到类似于以下内容:

Libraries have been installed in:
   /home/jakub/php-5.6.18/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'.

所以在modules目录中,您已经编译了捆绑扩展gd.so。 9、使用您新编译的捆绑扩展替换未捆绑的gd.so。对于我的PHP版本,命令如下:

sudo cp -f ./gd.so /usr/lib/php5/20131226/gd.so

10, 重新启动Apache

sudo service apache2 restart

希望这能有所帮助!并且你会比我花费更少的时间。


谢谢@kuba1999!在安装了libpng 12和16的Ubuntu 16.04上完美运行 :) - Nikolay Nikolov

0

另一种方法:

  1. 前往rpmfind.net并搜索适用于您的php版本的php-gd-bundled。
  2. 提取rpm(rpm2cpio archive_name.rpm | cpio -idmv)
  3. 备份您的gd.so,然后将gd.so从存档复制到您的php lib目录中。

此外,我可以使用以下参数编译一个模块:

#! /bin/sh
#
# Created by configure

'./configure' \
'--with-php-config=/usr/bin/php-config' \
'--with-gd=shared' \
'--with-freetype-dir=/usr' \
'--with-vpx-dir=/usr' \
'--with-jpeg-dir=/usr' \
'--with-xpm-dir=/usr' \
'--with-png-dir=/usr' \
'--with-t1lib=/usr' \
'--enable-gd-native-ttf' \
"$@"

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接