tips:make clean仅清除之前编译所生成可执行文件及配置文件。make distclean要清除所有编译生成文件。
先接上文。
下载PHP源码包。
PHP下载地址。
#下载PHP源码 dell@Ubuntu1601:~/PHP-7.1.3$ wget http://cn2.PHP.net/distributions/PHP-7.1.3.tar.gz #解压源码包 dell@Ubuntu1601:~/PHP-7.1.3$ tar -zxvf httpd-2.4.25.tar.gz 切换到PHP源代码目录 #配置PHP安装选项 dell@Ubuntu1601:~/PHP-7.1.3$ ./configure --prefix=/usr/local/PHP7 --with-apxs=/usr/local/apache2/bin/apxs --wi th-config-file-path=/usr/local/lib --with-MysqL
配置过程中可能会遇到xml2-config not found. Please check your libxml2 installation.错误,需要我们先安装XML2。
checking whether to explicitly link against libgcc... no checking whether to enable short tags by default... yes checking whether to enable dmalloc... no checking whether to enable IPv6 support... yes checking whether to enable DTrace support... no checking how big to make fd sets... using system default Configuring extensions checking size of long... (cached) 8 checking size of int... (cached) 4 checking for int32_t... yes checking for uint32_t... yes checking for sys/types.h... (cached) yes checking for inttypes.h... (cached) yes checking for stdint.h... (cached) yes checking for string.h... (cached) yes checking for stdlib.h... (cached) yes checking for strtoll... yes checking for atoll... yes checking for strftime... (cached) yes checking for gettimeofday... (cached) yes checking whether to enable LIBXML support... yes checking libxml2 install dir... no checking for xml2-config path... configure: error: xml2-config not found. Please check your libxml2 installation. dell@Ubuntu1601:~/PHP-7.1.3$ #安装xml2 dell@Ubuntu1601:~/PHP-7.1.3$ sudo apt install libxml2 libxml2-dev xml2
等待安装完成,重新配置PHP安装选项。
dell@Ubuntu1601:~/PHP-7.1.3$ ./configure --prefix=/usr/local/PHP7 --with-apxs=/usr/local/apache2/bin/apxs --with-config-file-path=/usr/local/lib --with-MysqL
以下是配置成功部分编译配置选项结果。
checking for strip... strip checking if cc supports -fno-rtti -fno-exceptions... no checking for cc option to produce PIC... -fPIC checking if cc PIC flag -fPIC works... yes checking if cc static flag -static works... yes checking if cc supports -c -o file.o... yes checking whether the cc 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 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 PHP7.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/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-apxs,--with-MysqL
注意最后一行提示(警告)。
生成并安装。
dell@Ubuntu1601:~/PHP-7.1.3$ make ... Generating phar.PHP Generating phar.phar PEAR package PHP_Archive not installed: generated phar will require PHP's phar extension be enabled. invertedregexiterator.inc pharcommand.inc directorytreeiterator.inc clicommand.inc directorygraphiterator.inc phar.inc Build complete. Don't forget to run 'make test'. ... dell@Ubuntu1601:~/PHP-7.1.3$ make test #根据机器配置,安装用时可能需要几分钟到几十分钟不等,请耐心等待安装完成。 dell@Ubuntu1601:~/PHP-7.1.3$ sudo make install [sudo] dell 的密码: Installing shared extensions: /usr/local/PHP7/lib/PHP/extensions/no-debug-non-zts-20160303/ Installing PHP CLI binary: /usr/local/PHP7/bin/ Installing PHP CLI man page: /usr/local/PHP7/PHP/man/man1/ Installing PHPdbg binary: /usr/local/PHP7/bin/ Installing PHPdbg man page: /usr/local/PHP7/PHP/man/man1/ Installing PHP CGI binary: /usr/local/PHP7/bin/ Installing PHP CGI man page: /usr/local/PHP7/PHP/man/man1/ Installing build environment: /usr/local/PHP7/lib/PHP/build/ Installing header files: /usr/local/PHP7/include/PHP/ Installing helper programs: /usr/local/PHP7/bin/ program: PHPize program: PHP-config Installing man pages: /usr/local/PHP7/PHP/man/man1/ page: PHPize.1 page: PHP-config.1 Installing PEAR environment: /usr/local/PHP7/lib/PHP/ [PEAR] Archive_Tar - installed: 1.4.2 [PEAR] Console_Getopt - installed: 1.4.1 [PEAR] Structures_Graph- installed: 1.1.1 [PEAR] XML_Util - installed: 1.4.2 [PEAR] PEAR - installed: 1.10.3 Wrote PEAR system config file at: /usr/local/PHP7/etc/pear.conf You may want to add: /usr/local/PHP7/lib/PHP to your PHP.ini include_path /home/dell/PHP-7.1.3/build/shtool install -c ext/phar/phar.phar /usr/local/PHP7/bin ln -s -f phar.phar /usr/local/PHP7/bin/phar Installing PDO headers: /usr/local/PHP7/include/PHP/ext/pdo/ #查看当前目录文件 dell@Ubuntu1601:~/PHP-7.1.3$ ls acinclude.m4 header NEWS README.TESTING2 aclocal.m4 include pear README.UNIX-BUILD-SYSTEM appveyor INSTALL PHP7.spec README.WIN32-BUILD-SYSTEM build install-sh PHP7.spec.in run_002_tmp.fixture buildconf libs PHP.gif run-tests.PHP buildconf.bat libtool PHP.ini-development sapi CODING_STANDARDS LICENSE PHP.ini-production scripts config.guess ltmain.sh README.EXT_SKEL server-tests-config.PHP config.log main README.GIT-RULES server-tests.PHP config.nice makedist README.input_filter sessions config.status Makefile README.MAILINGLIST_RULES snapshot config.sub Makefile.frag README.md stamp-h.in configure Makefile.fragments README.namespaces stub.c configure.in Makefile.gcov README.NEW-OUTPUT-API tests CONTRIBUTING.md Makefile.global README.PARAMETER_PARSING_API travis CREDITS Makefile.objects README.REDIST.BINS TSRM ext makerpm README.RELEASE_PROCESS UPGRADING EXTENSIONS missing README.SELF-CONTAINED-EXTENSIONS UPGRADING.INTERNALS footer mkinstalldirs README.STREAMS vcsclean generated_lists modules README.SUBMITTING_PATCH win32 genfiles netware README.TESTING Zend dell@Ubuntu1601:~/PHP-7.1.3$ sudo cp PHP.ini-development /usr/local/lib/PHP.ini dell@Ubuntu1601:~/PHP-7.1.3$ sudo cp /usr/local/apache2/conf/httpd.conf #修改前注意备份文件 /usr/local/apache2/conf/httpd.conf.bak dell@Ubuntu1601:~/PHP-7.1.3$ sudo vim /usr/local/apache2/conf/httpd.conf #找到以下两行代码修改 #修改完成结果如下 # DirectoryIndex index.html index.PHP #设置apache的默认文件名次序 #AddType application/x-httpd-PHP .PHP .phtml .PHP3 .inc #AddType application/x-httpd-PHP-source .PHPs #设置PHP文件后缀 dell@Ubuntu1601:~/PHP-7.1.3$ sudo /etc/init.d/apachectl restart
vi /usr/local/lib/PHP.ini #参考链接: http://PHP.net/manual/zh/security.globals.PHP #register-golbals = On
安装到这一步,PHP还无法正常解析。
通过参考网上链接,发现Apache没有加载libPHP*.so模块。
#检查Apache模块加载情况 dell@Ubuntu1601:~$ /etc/init.d/apachectl -M Loaded Modules: core_module (static) so_module (static) http_module (static) mpm_event_module (static) authn_file_module (shared) authn_core_module (shared) authz_host_module (shared) authz_groupfile_module (shared) authz_user_module (shared) authz_core_module (shared) access_compat_module (shared) auth_basic_module (shared) reqtimeout_module (shared) filter_module (shared) mime_module (shared) log_config_module (shared) env_module (shared) headers_module (shared) setenvif_module (shared) version_module (shared) unixd_module (shared) status_module (shared) autoindex_module (shared) dir_module (shared) alias_module (shared) #检查Apache配置 dell@Ubuntu1601:~$ /etc/init.d/apachectl -t Syntax OK
接着尝试重新编译安装PHP。
dell@Ubuntu1601:~$ cd PHP-7.1.3/ dell@Ubuntu1601:~/PHP-7.1.3$ ./configure --prefix=/usr/local/PHP7 --with-apxs2=/usr/local/apache2/bin/apxs --w ith-MysqL=/usr/local/MysqL --enable-ftp --with-freetype-dir=/usr/local/freetype --enable-mbstring --with-iconv dell@Ubuntu1601:~/PHP-7.1.3$ make dell@Ubuntu1601:~/PHP-7.1.3$ sudo make install #部分报错信息 Generating phar.PHP Generating phar.phar PEAR package PHP_Archive not installed: generated phar will require PHP's phar extension be enabled. invertedregexiterator.inc pharcommand.inc directorytreeiterator.inc clicommand.inc directorygraphiterator.inc phar.inc Build complete. Don't forget to run 'make test'. Installing PHP SAPI module: apache2handler mkdir: cannot create directory '/usr/local/PHP7': Permission denied mkdir: cannot create directory '/usr/local/PHP7/bin': No such file or directory Makefile:147: recipe for target 'install-sapi' Failed make: [install-sapi] Error 1 (ignored) /usr/local/apache2/build/instdso.sh SH_LIBTOOL='/usr/local/apr//build-1/libtool' libPHP7.la /usr/local/apache2/modules /usr/local/apr//build-1/libtool --mode=install install libPHP7.la /usr/local/apache2/modules/ libtool: install: install .libs/libPHP7.so /usr/local/apache2/modules/libPHP7.so install: cannot create regular file '/usr/local/apache2/modules/libPHP7.so': Permission denied apxs:Error: Command Failed with rc=65536 . Makefile:147: recipe for target 'install-sapi' Failed make: *** [install-sapi] Error 1 dell@Ubuntu1601:~/PHP-7.1.3$
推测需要重新安装PHP。
tips:已经重新安装测试机系统。
最新进展:
#按两下Tab键 #可以看到没有--with-apxs选项 dell@Dell:~/PHP-7.1.3$ ./configure --prefix=/usr/local/PHP7.1 --with Display all 101 possibilities? (y or n) --with-adabas= --with-interbase= --with-pcre-jit --with-apxs2= --with-iodbc= --with-pcre-regex= --with-birdstep= --with-jpeg-dir= --with-pdo-dblib= --with-bz2= --with-kerberos= --with-pdo-firebird= --with-config-file-path= --with-layout= --with-pdo-MysqL= --with-config-file-scan-dir= --with-ldap= --with-pdo-oci= --with-curl= --with-ldap-sasl= --with-pdo-odbc= --with-custom-odbc= --with-libdir= --with-pdo-pgsql= --with-db1= --with-libedit= --with-pear= --with-db2= --with-libexpat-dir= --with-pgsql= --with-db3= --with-libmbfl= --with-pic --with-db4= --with-libxml-dir= --with-png-dir= --with-dbm= --with-libzip= --with-pspell= --with-dbmaker= --with-litespeed --with-qdbm= --with-empress= --with-mcrypt= --with-readline= --with-empress-bcs= --with-mhash= --with-recode= --with-enchant= --with-mm= --with-sapdb= --with-esoob= --with-MysqLi= --with-snmp= --with-EXTENSION= --with-MysqL-sock= --with-solid= --with-fpm-acl --with-ndbm= --with-system-ciphers --with-fpm-group= --with-oci8= --with-tags= --with-fpm-systemd --with-ODBCRouter= --with-tcadb= --with-fpm-user= --with-odbcver= --with-tidy= --with-freetype-dir= --with-onig= --with-tsrm-pth= --with-gd= --with-openssl= --with-tsrm-pthreads --with-gdbm= --with-openssl-dir= --with-tsrm-st --More--
经过两天辛苦排查,终于发现是PHP编译选项有问题。 具体表现在代码
dell@Dell:~/PHP-7.1.3$ ./configure --prefix=/usr/local/PHP7 --with-apxs=/usr/local/apache2/bin/apxs --with-config-file-path=/usr/local/lib --with-MysqL
--with-apxs选项少一个2(--with-apxs2),其他选项可选。
编译完成,检查http配置文件。
#部分代码 dell@Dell:~$ cat /usr/local/apache2.4/conf/httpd.conf |more #LoadModule lbmethod_byrequests_module modules/mod_lbmethod_byrequests.so #LoadModule lbmethod_bytraffic_module modules/mod_lbmethod_bytraffic.so #LoadModule lbmethod_bybusyness_module modules/mod_lbmethod_bybusyness.so #LoadModule lbmethod_heartbeat_module modules/mod_lbmethod_heartbeat.so LoadModule unixd_module modules/mod_unixd.so #LoadModule dav_module modules/mod_dav.so LoadModule status_module modules/mod_status.so LoadModule autoindex_module modules/mod_autoindex.so #LoadModule info_module modules/mod_info.so #LoadModule cgid_module modules/mod_cgid.so #LoadModule dav_fs_module modules/mod_dav_fs.so #LoadModule vhost_alias_module modules/mod_vhost_alias.so #LoadModule negotiation_module modules/mod_negotiation.so LoadModule dir_module modules/mod_dir.so #LoadModule actions_module modules/mod_actions.so #LoadModule speling_module modules/mod_speling.so #LoadModule userdir_module modules/mod_userdir.so LoadModule alias_module modules/mod_alias.so #LoadModule rewrite_module modules/mod_rewrite.so LoadModule PHP7_module modules/libPHP7.so <IfModule unixd_module> # # If you wish httpd to run as a different user or group,you must run # httpd as root initially and it will switch. # --更多--
dell@dell-OptiPlex-390:~/PHP-7.1.3$ sudo cp PHP.ini-production /usr/local/lib/PHP.ini
编译Apache配置文件。
dell@DELL:~/SoftwareSource/PHP-7.1.4$ sudo vim /usr/local/apache2.2/conf/httpd.conf #添加index.PHP 167 <IfModule dir_module> 168 DirectoryIndex index.html index.PHP #添加支持PHP 169 </IfModule> 318 AddType application/x-compress .Z 319 AddType application/x-gzip .gz .tgz AddType application/x-httpd-PHP .PHP .phtml AddType application/x-httpd-PHP-source .PHPs
#编辑PHPinfo.PHP dell[@Dell](https://my.oschina.net/u/725578):~$ sudo vim /usr/local/apache2.4/htdocs/PHPinfo.PHP #PHPinfo.PHP <?PHP PHPinfo(); ?>
以下是编译成功与浏览器运行截图。
编译过程中还可能遇到
dell[@Dell](https://my.oschina.net/u/725578):~/PHP-7.1.3$ make install Installing PHP SAPI module: apache2handler mkdir: cannot create directory '/usr/local/PHP7.1': Permission denied mkdir: cannot create directory '/usr/local/PHP7.1/bin': No such file or directory Makefile:146: recipe for target 'install-sapi' Failed make: [install-sapi] Error 1 (ignored) /usr/local/apache2.4/build/instdso.sh SH_LIBTOOL='/usr/local/apr/build-1/libtool' libPHP7.la /usr/local/apache2.4/modules /usr/local/apr/build-1/libtool --mode=install install libPHP7.la /usr/local/apache2.4/modules/ libtool: install: install .libs/libPHP7.so /usr/local/apache2.4/modules/libPHP7.so install: cannot create regular file '/usr/local/apache2.4/modules/libPHP7.so': Permission denied apxs:Error: Command Failed with rc=65536 . Makefile:146: recipe for target 'install-sapi' Failed make: *** [install-sapi] Error 1
错误,请以root权限重新运行安装程序。
dell[@Dell](https://my.oschina.net/u/725578):~/PHP-7.1.3$ sudo make install Installing PHP SAPI module: apache2handler /usr/local/apache2.4/build/instdso.sh SH_LIBTOOL='/usr/local/apr/build-1/libtool' libPHP7.la /usr/local/apache2.4/modules /usr/local/apr/build-1/libtool --mode=install install libPHP7.la /usr/local/apache2.4/modules/ libtool: install: install .libs/libPHP7.so /usr/local/apache2.4/modules/libPHP7.so libtool: install: install .libs/libPHP7.lai /usr/local/apache2.4/modules/libPHP7.la libtool: install: warning: remember to run `libtool --finish /home/dell/PHP-7.1.3/libs' chmod 755 /usr/local/apache2.4/modules/libPHP7.so [activating module `PHP7' in /usr/local/apache2.4/conf/httpd.conf] Installing shared extensions: /usr/local/PHP7.1/lib/PHP/extensions/no-debug-zts-20160303/ Installing PHP CLI binary: /usr/local/PHP7.1/bin/ Installing PHP CLI man page: /usr/local/PHP7.1/PHP/man/man1/ Installing PHPdbg binary: /usr/local/PHP7.1/bin/ Installing PHPdbg man page: /usr/local/PHP7.1/PHP/man/man1/ Installing PHP CGI binary: /usr/local/PHP7.1/bin/ Installing PHP CGI man page: /usr/local/PHP7.1/PHP/man/man1/ Installing build environment: /usr/local/PHP7.1/lib/PHP/build/ Installing header files: /usr/local/PHP7.1/include/PHP/ Installing helper programs: /usr/local/PHP7.1/bin/ program: PHPize program: PHP-config Installing man pages: /usr/local/PHP7.1/PHP/man/man1/ page: PHPize.1 page: PHP-config.1 Installing PEAR environment: /usr/local/PHP7.1/lib/PHP/ [PEAR] Archive_Tar - installed: 1.4.2 [PEAR] Console_Getopt - installed: 1.4.1 [PEAR] Structures_Graph- installed: 1.1.1 [PEAR] XML_Util - installed: 1.4.2 [PEAR] PEAR - installed: 1.10.3 Wrote PEAR system config file at: /usr/local/PHP7.1/etc/pear.conf You may want to add: /usr/local/PHP7.1/lib/PHP to your PHP.ini include_path /home/dell/PHP-7.1.3/build/shtool install -c ext/phar/phar.phar /usr/local/PHP7.1/bin ln -s -f phar.phar /usr/local/PHP7.1/bin/phar Installing PDO headers: /usr/local/PHP7.1/include/PHP/ext/pdo/