CentOS7_LNMP(第三篇)_PHP5.6.14编译安装

CentOS7+Nginx1.95+mariadb10.0.21+php5.6.14

PHP的安装配置

这里要先声明一下,针对Nginx的php安装和针对apache的php安装是有区别的,因为Nginx中的php是以fastcgi的方式结合nginx的,可以理解为nginx代理了php的fastcgi,而apache是把php作为自己的模块来调用的。
php官方下载地址: http://www.php.net/downloads.php
1.解压php
[root@XiaoFeng lnmp]# tar -zxf php-5.6.14.tar.gz
[root@XiaoFeng lnmp]# cd php-5.6.14
2.创建相关账户
[root@XiaoFeng php-5.6.14]# useradd -s /sbin/nologin php-fpm
3.安装依赖组件, libmcrypt这个yum安装不了的话就自己去下找rpm包来安装

1
2
3
4
5
6
root@XiaoFeng php-5.6.14]# rpm -ivh libmcrypt*
警告:libmcrypt-2.5.7-1.1.el3.dag.x86_64.rpm: 头V3 DSA/SHA1 Signature, 密钥 ID 6b8d79e6: NOKEY
准备中...                          ################################# [100%]
正在升级/安装...
  1:libmcrypt-2.5.7-1.1.el3.dag      ################################# [ 50%]
  2:libmcrypt-devel-2.5.7-1.1.el3.dag################################# [100%]


4.配置编译参数

1
2
[root@XiaoFeng php-5.6.14]# ./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --enable-fpm --with-fpm-user=php-fpm --with-fpm-group=php-fpm --with-mysql=mysqlnd  --with-pdo-mysql=mysqlnd --with-mysqli=mysqlnd --with-libxml-dir --with-gd --with-jpeg-dir --with-png-dir --with-freetype-dir --with-iconv-dir --with-zlib-dir --with-mcrypt --enable-soap --enable-gd-native-ttf --enable-ftp --enable-mbstring --enable-exif --disable-ipv6 --with-pear --with-curl --enable-bcmath --enable-mbstring --enable-sockets --with-gd --with-libxml-dir=/usr/local --with-gettext
[root@XiaoFeng php-5.6.14]# make && make install


5.修改配置文件

1
2
3
4
[root@XiaoFeng php-5.6.14]# cp php.ini-production /usr/local/php/etc/php.ini
[root@XiaoFeng php-5.6.14]# cd /usr/local/php/etc/
[root@XiaoFeng etc]# cp php-fpm.conf.default php-fpm.conf
[root@XiaoFeng etc]# vim php-fpm.conf


把如下内容写入该文件:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
[global]
pid = /usr/local/php/var/run/php-fpm.pid
error_log = /usr/local/php/var/log/php-fpm.log
[www]
listen = /tmp/php-fcgi.sock
user = php-fpm
group = php-fpm
listen.owner = nobody
listen.group = nobody
pm = dynamic
pm.max_children = 50
pm.start_servers = 20
pm.min_spare_servers = 5
pm.max_spare_servers = 35
pm.max_requests = 500
rlimit_files = 1024


6.保存配置文件后,检验配置是否正确的方法为:

1
2
[root@XiaoFeng etc]# /usr/local/php/sbin/php-fpm -t
[26-Oct-2015 03:52:16] NOTICE: configuration file /usr/local/php/etc/php-fpm.conf test is successful


如果出现诸如 “test is successful” 字样,说明配置没有问题。
7.启动php-fpm

1
2
3
4
[root@XiaoFeng etc]# cp /lnmp/php-5.6.14/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
[root@XiaoFeng etc]# chmod 755 /etc/init.d/php-fpm
[root@XiaoFeng etc]# service php-fpm start
Starting php-fpm  done


8.让它开机启动,执行:
[root@XiaoFeng etc]# chkconfig php-fpm on
查看是否开机启动:
[root@XiaoFeng etc]# chkconfig --list php-fpm
php-fpm 0:关 1:关 2:开 3:开 4:开 5:开 6:关
检测是否启动:

1
2
3
[root@XiaoFeng etc]# ps aux |grep php-fpm
php-fpm  59814  0.0  0.4 112808  4312 ?        S    03:54   0:00 php-fpm: pool www
php-fpm  59815  0.0  0.4 112808  4316 ?        S    03:54   0:00 php-fpm: pool www


9.PHP已经安装完了,接下来要配置nginx来支持php
[root@XiaoFeng conf]# cd /usr/local/nginx/conf
[root@XiaoFeng conf]# vim nginx.conf
Vim里set nu 显示行号,按行号加入下面内容

  1. user nginx;

  2. index.php
    在65行上面加入下面内容

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    location ~ \.php$ {
               root           html;
               fastcgi_pass   127.0.0.1:9000;
               fastcgi_index  index.php;
               fastcgi_param  SCRIPT_FILENAME  /usr/local/nginx/html$fastcgi_script_name;
    fastcgi_param   REQUEST_METHOD  /usr/local/nginx/html$request_method;
    fastcgi_param   CONTENT_TYPE     /usr/local/nginx/html$content_type;
    fastcgi_param   CONTENT_LENGTH  /usr/local/nginx/html$content_length;
               include        fastcgi_params;
           }

10.在网站目录下写个php页面测试下

1
2
3
4
[root@XiaoFeng html]# vim index.php
<?php
echo phpinfo();
?>


[root@XiaoFeng html]# service nginx restart
11.打开浏览器看到PHP Version 5.6.14页面就完成咯


打 赏

小风博客
请点评论按钮,登录后发表评论
  • 最新评论
  • 总共0条评论