LNMP环境搭建之php安装

和LAMP安装PHP方法有差别,需要开启php-fpm服务

下载php

 cd /usr/local/src/
 wget http://cn2.php.net/distributions/php-5.6.30.tar.gz

解压源码包

 tar zxf php-5.6.30.tar.gz

创建用户

 useradd -s /sbin/nologin php-fpm

配置编译参数

 cd php-5.6.30
 ./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=/usr/local/mysql 
 --with-mysqli=/usr/local/mysql/bin/mysql_config 
 --with-pdo-mysql=/usr/local/mysql 
 --with-mysql-sock=/tmp/mysql.sock 
 --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 
 --with-pear 
 --with-curl 
 --with-openssl

编译安装php

 make && make install

日志和pid

 /usr/local/php/var/log  日志目录
 /usr/local/php/var/run  pid目录

拷贝配置文件php.ini

 cd /usr/local/src/php-5.6.30
 cp php.ini-production /usr/local/php/etc/php.ini
 可以自己指定

拷贝配置文件php-fpm

cd /usr/local/php/etc
mv /usr/local/php/etc/php-fpm.conf.default  php-fpm.conf 
vim php-fpm.conf
[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
listen.mode = 666
user = php-fpm
group = php-fpm
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
#   [global] 定义全局变量
#   listen   可以监听socket,也可以坚挺ip:prot  127.0.0.1:90000,php和nginx通常在一台机器上,他们两者之间的通信用内部的网络就可以了,当然也可以定义其他的ip
# listen.mode  只有监听socket时它才生效

拷贝启动脚本

 cd /usr/local/src/php-5.6.30/sapi/fpm/
 cp init.d.php-fpm  /etc/init.d/php-fpm
 chmod 755 /etc/init.d/php-fpm

加入开机启动项

 chkconfig --add php-fpm
 chkconfig php-fpm on

检查配置有没有错误

/usr/local/php/sbin/php-fpm -t
/usr/local/php/bin/php -m
/usr/local/php/bin/php -i

启动Php

 service php-fpm start

查看进程

 ps aux |grep php-fpm

解析错误案例

linux 下搭建Nginx+php报错
FastCGI sent in stderr: "PHP message: PHP Warning:  Unknown: open_basedir restriction in effect. File(/usr/local/nginx/html/info.php) is not within the allowed path(s):
解决办法:
在php.ini里面在open_basedir里添加上这个目录重启php-fpm即可

转载于:https://blog.51cto.com/chenshengsheng/2103644

原文地址:https://www.cnblogs.com/twodog/p/12137112.html