本文章紧接上一篇CentOS7.0下编译安装Nginx 1.10.0。来完成经常使用的web开发集成环境lnmp的基本搭建,本篇来记录php的安装,仍是那些步骤。
php
安装编译工具、依赖包及下载源码包html
解压编译mysql
安装linux
启动nginx
因为在上篇文章中编译工具什么的都安装完了,因此直接进行下一步,下载PHP源码包web
wget http://cn2.php.net/distributions/php-5.6.21.tar.gz
tar -zxvf php-5.6.21.tar.gz
./configure --prefix=/usr/local/php/5.6.21 --enable-fpm
本配置也只是简单地配置了安装目录和支持php-fpm。其余的配置好比mysql,ssl之类的能够后期在配置文件里面加。
可是我配置完给我报了这么一个错误。sql
configure: error: xml2-config not found. Please check your libxml2 installation.
原来是缺乏了一个依赖包,下载安装从新配置便可:vim
yum install libxml2-devel
配置成功后会给出如下提示:centos
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
make
编译时间较长,请耐心等待,不出意外,编译成功为出现如下提示:api
Build complete. Don't forget to run 'make test'.
make install
能够在安装以前先运行下make test
,不过我不习惯先运行make test
,由于我是一枚业余写代码的段子手。
安装完以后给出提示
Installing PHP CLI binary: /usr/local/php/5.6.21/bin/ Installing PHP CLI man page: /usr/local/php/5.6.21/php/man/man1/ Installing PHP FPM binary: /usr/local/php/5.6.21/sbin/ Installing PHP FPM config: /usr/local/php/5.6.21/etc/ Installing PHP FPM man page: /usr/local/php/5.6.21/php/man/man8/ Installing PHP FPM status page: /usr/local/php/5.6.21/php/php/fpm/ Installing PHP CGI binary: /usr/local/php/5.6.21/bin/ Installing PHP CGI man page: /usr/local/php/5.6.21/php/man/man1/ Installing build environment: /usr/local/php/5.6.21/lib/php/build/ Installing header files: /usr/local/php/5.6.21/include/php/ Installing helper programs: /usr/local/php/5.6.21/bin/ program: phpize program: php-config Installing man pages: /usr/local/php/5.6.21/php/man/man1/ page: phpize.1 page: php-config.1 Installing PEAR environment: /usr/local/php/5.6.21/lib/php/ [PEAR] Archive_Tar - installed: 1.4.0 [PEAR] Console_Getopt - installed: 1.4.1 [PEAR] Structures_Graph- installed: 1.1.1 [PEAR] XML_Util - installed: 1.3.0 [PEAR] PEAR - installed: 1.10.1 Wrote PEAR system config file at: /usr/local/php/5.6.21/etc/pear.conf You may want to add: /usr/local/php/5.6.21/lib/php to your php.ini include_path /root/php-5.6.21/build/shtool install -c ext/phar/phar.phar /usr/local/php/5.6.21/bin ln -s -f phar.phar /usr/local/php/5.6.21/bin/phar Installing PDO headers: /usr/local/php/5.6.21/include/php/ext/pdo/
安装完成后还须要更改nginx配置文件使之支持php文件
vim /etc/nginx/nginx.conf
更改的地方以下图所示
而后重启nginx,启动php-fpm
/usr/local/nginx/sbin/nginx -s reload //重启nginx /usr/local/php/5.6.21/sbin/php-fpm //启动php-fpm
此时就应该都ok了,在html目录下新建一测试文件index.php
<?php phpinfo();
打开浏览器访问,出现如图信息,good,安装完毕。
附:php-fpm启动,中止命令
killall php-fpm //中止命令 /usr/local/php/5.6.21/sbin/php-fpm //启动命令
仍是那句话,以上各步出现错误请根据错误提示解决,通常都不是大错误,也可留言,我们共同讨论?。