写在前面的话

本文章紧接上一篇CentOS7.0下编译安装Nginx 1.10.0。来完成常用的web开发集成环境lnmp的基本搭建,本篇来记录php的安装,还是那些步骤。

  • 安装编译工具、依赖包及下载源码包

  • 解压编译

  • 安装

  • 启动

编译安装

下载源码

由于在上篇文章中编译工具什么的都安装完了,所以直接进行下一步,下载PHP源码包

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之类的可以后期在配置文件里面加。

但是我配置完给我报了这么一个错误。

configure: error: xml2-config not found. Please check your libxml2 installation.

原来是缺少了一个依赖包,下载安装重新配置即可:

yum install libxml2-devel

配置成功后会给出以下提示:

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

编译时间较长,请耐心等待,不出意外,编译成功为出现以下提示:

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

更改的地方如下图所示
image
然后重启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,安装完毕。
image

附:php-fpm启动,停止命令

killall php-fpm   //停止命令
/usr/local/php/5.6.21/sbin/php-fpm   //启动命令

还是那句话,以上各步出现错误请根据错误提示解决,一般都不是大错误,也可留言,咱们共同讨论?。



lbool
30 声望2 粉丝

To be is to do!