编译 PHP
编译 PHP 5.6.33(atzjg.net)
./configure
make
make test
make install
如果之前有过 make, 则在 ./configure 之后, 不妨执行一下
make clean
然后再执行 make.
注意 make test 可能需要较长时间.
如果服务器正在运行之前编译的 php, 请先停止 php, 然后 make install. 最后启动 php.
关于 PHP 的启动、停止、重启参见问题2275
首先执行下面的 configure 命令(完整的 configure 设置见最后的总结, 这里记录了一些问题)
# ./configure --prefix=/usr/local/php --enable-fpm --with-fpm-user=www-data --with-fpm-group=www-data --with-config-file-path=/usr/local/php/conf --with-config-file-scan-dir=/usr/local/php/conf.d --enable-debug --with-openssl --with-kerberos --with-zlib --enable-calendar --with-curl --with-curlwrappers --with-enchant --enable-ftp --with-gd --with-jpeg-dir=/usr --with-png-dir=/usr --with-vpx-dir=/usr --with-freetype-dir=/usr --with-t1lib --enable-exif --enable-gd-native-ttf --enable-gd-jis-conv --with-gettext --with-gmp --with-mhash --enable-intl --enable-mbstring --with-mcrypt --with-mysql --with-mysqli --enable-pcntl --with-pdo-mysql --with-pdo-pgsql --with-pgsql --with-pspell --with-libedit --with-readline --enable-shmop --with-snmp --enable-soap --enable-sockets --enable-sysvmsg --enable-sysvshm --with-xsl --enable-zip --with-pear --enable-zend-signals --enable-maintainer-zts
如果出现
configure: error: Cannot find enchant
则执行
# sudo apt-get install libenchant-dev
然后继续执行上面的 configure, 出现下面的错误
configure: error: vpx_codec.h not found.
# sudo apt-get install libvpx-dev
继续 configure
configure: error: Unable to locate gmp.h
# sudo apt-get install libgmp-dev
继续 configure
checking for iconv support... yes
checking for iconv... yes
checking if iconv is glibc's... yes
checking if iconv supports errno... no
checking if iconv supports //IGNORE... no
checking if your cpp allows macro usage in include lines... yes
checking for IMAP support... no
checking for IMAP Kerberos support... yes
checking for IMAP SSL support... no
checking for InterBase support... no
checking whether to enable internationalization support... yes
checking for icu-config... no
checking for location of ICU headers and libraries... not found
configure: error: Unable to detect ICU prefix or no failed. Please verify ICU install prefix and make sure icu-config works.
# sudo apt-get install libicu-dev
在 configure 中加入 --with-iconv
'./configure' '--prefix=/usr/local/php' '--enable-fpm' '--with-fpm-user=www-data' '--with-fpm-group=www-data' '--with-config-file-path=/usr/local/php/conf' '--with-config-file-scan-dir=/usr/local/php/conf.d' '--enable-debug' '--with-openssl' '--with-kerberos' '--with-zlib' '--enable-calendar' '--with-curl' '--with-curlwrappers' '--with-enchant' '--enable-ftp' '--with-gd' '--with-jpeg-dir=/usr' '--with-png-dir=/usr' '--with-vpx-dir=/usr' '--with-freetype-dir=/usr' '--with-t1lib' '--enable-exif' '--enable-gd-native-ttf' '--enable-gd-jis-conv' '--with-gettext' '--with-gmp' '--with-mhash' '--enable-intl' '--enable-mbstring' '--with-mcrypt' '--with-mysql' '--with-mysqli' '--enable-pcntl' '--with-pdo-mysql' '--with-pdo-pgsql' '--with-pgsql' '--with-pspell' '--with-libedit' '--with-readline' '--enable-shmop' '--with-snmp' '--with-iconv-dir=/usr/local/lib' '--enable-soap' '--enable-sockets' '--enable-sysvmsg' '--enable-sysvshm' '--with-xsl' '--enable-zip' '--with-pear' '--enable-zend-signals' '--enable-maintainer-zts'
checking for pg_config... not found
configure: error: Cannot find libpq-fe.h. Please specify correct PostgreSQL installation path
# sudo apt-get install postgresql
# sudo apt-get install libpq-dev
checking for PSPELL support... yes
configure: error: Cannot find pspell
#sudo apt-get install libpspell-dev php5-pspell aspell-en
checking for SNMP support... yes
checking OpenSSL dir for SNMP... no
checking for net-snmp-config... /usr/bin/net-snmp-config
checking for init_snmp in -lnetsnmp... no
configure: error: SNMP sanity check failed. Please check config.log for more information.
# sudo apt-get install libsnmp-dev
checking for XSL support... yes
configure: error: xslt-config not found. Please reinstall the libxslt >= 1.1.0 distribution
# sudo apt-get install libxslt-dev
checking if /usr/local/src/php-5.6.33/meta_ccld supports -fno-rtti -fno-exceptions... no
checking for /usr/local/src/php-5.6.33/meta_ccld option to produce PIC... -fPIC
checking if /usr/local/src/php-5.6.33/meta_ccld PIC flag -fPIC works... yes
checking if /usr/local/src/php-5.6.33/meta_ccld static flag -static works... yes
checking if /usr/local/src/php-5.6.33/meta_ccld supports -c -o file.o... yes
checking whether the /usr/local/src/php-5.6.33/meta_ccld linker (/usr/bin/ld -m elf_x86_64) supports shared libraries... yes
checking whether -lc should be explicitly linked in... no
checking dynamic linker characteristics... GNU/Linux ld.so
checking how to hardcode library paths into programs... immediate
checking whether stripping libraries is possible... yes
checking if libtool supports shared libraries... yes
checking whether to build shared libraries... yes
checking whether to build static libraries... yes
creating libtool
appending configuration tag "CXX" to libtool
checking for ld used by g++... /usr/bin/ld -m elf_x86_64
checking if the linker (/usr/bin/ld -m elf_x86_64) is GNU ld... yes
checking whether the g++ linker (/usr/bin/ld -m elf_x86_64) supports shared libraries... yes
checking for g++ option to produce PIC... -fPIC
checking if g++ PIC flag -fPIC works... yes
checking if g++ static flag -static works... yes
checking if g++ supports -c -o file.o... yes
checking whether the g++ linker (/usr/bin/ld -m elf_x86_64) supports shared libraries... yes
checking dynamic linker characteristics... GNU/Linux ld.so
(cached) (cached) checking how to hardcode library paths into programs... immediate
Generating files
configure: creating ./config.status
creating main/internal_functions.c
creating main/internal_functions_cli.c
+--------------------------------------------------------------------+
| License: |
| This software is subject to the PHP License, available in this |
| distribution in the file LICENSE. By continuing this installation |
| process, you are bound by the terms of this license agreement. |
| If you do not agree with the terms of this license, you must abort |
| the installation process at this point. |
+--------------------------------------------------------------------+
Thank you for using PHP.
config.status: creating php5.spec
config.status: creating main/build-defs.h
config.status: creating scripts/phpize
config.status: creating scripts/man1/phpize.1
config.status: creating scripts/php-config
config.status: creating scripts/man1/php-config.1
config.status: creating sapi/cli/php.1
config.status: creating sapi/fpm/php-fpm.conf
config.status: creating sapi/fpm/init.d.php-fpm
config.status: creating sapi/fpm/php-fpm.service
config.status: creating sapi/fpm/php-fpm.8
config.status: creating sapi/fpm/status.html
config.status: creating sapi/cgi/php-cgi.1
config.status: creating ext/phar/phar.1
config.status: creating ext/phar/phar.phar.1
config.status: creating main/php_config.h
config.status: executing default commands
configure: WARNING: unrecognized options: --with-curlwrappers
将 --with-curlwrappers 选项去掉.
The configure flag --with-curlwrappers
is not available anymore in PHP core >= 5.5. The feature has been moved to PECL.
To fix this error:
undefined reference to `libiconv_open'
Run configure like this:
[root@hotstname project-version]# ./configure CFLAGS=-liconv
【总结】建议使用下面的 configure 编译设置
'./configure' 'CFLAGS=-liconv' '--prefix=/usr/local/php' '--enable-fpm' '--with-fpm-user=www-data' '--with-fpm-group=www-data' '--with-config-file-path=/usr/local/php/conf' '--with-config-file-scan-dir=/usr/local/php/conf.d' '--enable-debug' '--with-openssl' '--with-kerberos' '--with-zlib' '--enable-calendar' '--with-curl' '--with-enchant' '--enable-ftp' '--with-gd' '--with-jpeg-dir=/usr' '--with-png-dir=/usr' '--with-vpx-dir=/usr' '--with-freetype-dir=/usr' '--with-t1lib' '--enable-exif' '--enable-gd-native-ttf' '--enable-gd-jis-conv' '--with-gettext' '--with-gmp' '--with-mhash' '--enable-intl' '--enable-mbstring' '--with-mcrypt' '--with-mysql' '--with-mysqli' '--enable-pcntl' '--with-pdo-mysql' '--with-pdo-pgsql' '--with-pgsql' '--with-pspell' '--with-libedit' '--with-readline' '--enable-shmop' '--with-snmp' '--with-iconv-dir=/usr/local/lib' '--enable-soap' '--enable-sockets' '--enable-sysvmsg' '--enable-sysvshm' '--with-xsl' '--enable-zip' '--with-pear' '--enable-zend-signals' '--enable-maintainer-zts'
Generating phar.php
Generating phar.phar
PEAR package PHP_Archive not installed: generated phar will require PHP's phar extension be enabled.
directorytreeiterator.inc
invertedregexiterator.inc
clicommand.inc
pharcommand.inc
directorygraphiterator.inc
phar.inc
Build complete.
Don't forget to run 'make test'.