在 CendOS 6.5 上编译 PHP 5/PHP 7

首先安装一些依赖的软件包:

  1. yum install libmcrypt.x86_64 libpng.x86_64 libjpeg-turbo.x86_64 \
  2. libxml2.x86_64 readline.x86_64 libxml2-devel.x86_64 openssl.x86_64 \
  3. openssl-devel.x86_64 libcurl-devel.x86_64 libjpeg-turbo-devel.x86_64 \
  4. libwebp-devel.x86_64 libpng-devel.x86_64 freetype-devel.x86_64 \
  5. libmcrypt-devel.x86_64 readline-devel.x86_64 gcc.x86_64 pcre-devel.x86_64

然后是正确的配置 PHP7 的编译选项

  1. ./configure -C \
  2. --prefix=/usr/local/php \
  3. --with-readline \
  4. --with-curl \
  5. --with-gd \
  6. --with-iconv \
  7. --with-gettext \
  8. --with-mcrypt \
  9. --with-mysqli \
  10. --with-openssl \
  11. --enable-pcntl \
  12. --enable-soap \
  13. --enable-mbstring \
  14. --with-zlib \
  15. --enable-fpm \
  16. --with-freetype-dir=/usr \
  17. --with-jpeg-dir=/usr \
  18. --with-webp-dir=/usr \
  19. --with-png-dir=/usr

最后执行编译指令:

  1. #使用2个核的意思,看CPU多少决定这个参数
  2. make -j 2
  3. make install

编译完了,要单独编译一下 opcache,虽然我觉得这个应该编译进去到 PHP 解释器里面,
但是目前,我只找到了以扩展方式使用的方法。

  1. cd ext/opcode
  2. /usr/local/php/bin/phpize
  3. ./configure --with-php-config=/usr/local/php/bin/php-config
  4. make -j 2
  5. make install

然后编辑配置文件,添加:

  1. zend_extension=opcache.so

=====

下面是 PHP 5 的编译脚本:

  1. #!/bin/bash
  2.  
  3. yum -yq install  \
  4. libxml2-devel.x86_64 gcc.x86_64 \
  5. openssl-devel.x86_64 libcurl-devel.x86_64 libjpeg-turbo-devel.x86_64 \
  6. libwebp-devel.x86_64 libpng-devel.x86_64 freetype-devel.x86_64 \
  7. libmcrypt-devel.x86_64 readline-devel.x86_64 libtool-ltdl-devel.x86_64
  8.  
  9. ./configure -C \
  10. --prefix=/usr/local/php \
  11. --with-readline \
  12. --with-curl \
  13. --with-gd \
  14. --with-iconv \
  15. --with-gettext \
  16. --with-mcrypt \
  17. --with-mysqli \
  18. --with-pdo-mysql \
  19. --with-openssl \
  20. --enable-pcntl \
  21. --enable-soap \
  22. --enable-mbstring \
  23. --with-zlib \
  24. --enable-fpm \
  25. --with-freetype-dir=/usr \
  26. --with-jpeg-dir=/usr \
  27. --with-png-dir=/usr