LNMP-PHP安装

一、安装PHP
 
1:下载Php源码包
[root@ghs src]# wget --no-check-certificate http://cn2.php.net/distributions/php-5.6.30.tar.gz
 
2:创建php-fpm用户
[root@ghs src]# useradd -s /sbin/nologin php-fpm
 
3:初始化
[root@ghs php]# cd php-5.6.30
[root@ghs php]# ./configure --prefix=/usr/local/php-fpm --with-config-file-path=/usr/local/php-fpm/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
 
过程出现的错误:
configure: error: Please reinstall the libcurl distribution -easy.h should be in <curl-dir>/include/curl/
解决方法:yum install -y libcurl-devel
configure: error: libxml2 not found. Please check your libxml2 installation.
解决方法:yum install -y libxml2-devel
configure: error: cURL version 7.15.5 or later is required to compile php with cURL support
解决方法:yum install -y curl-devel
configure: error: jpeglib.h not found.
解决方法:yum install -y  libjpeg-devel
configure: error: png.h not found.
解决方法:yum install -y libpng-devel
configure: error: freetype-config not found.
解决方法:yum install -y freetype-devel
configure: error: mcrypt.h not found. Please reinstall libmcrypt.
解决方法:先安装epel源,yum install -y epel-release,借助epel源再安装libmcrypt-devel
yum install -y libmcrypt-devel
 
4:开始编译php环境
[root@ghs php]# make
 
5:安装已经编译完成php环境
[root@ghs php]# make install
 
6:拷贝环境及启动脚本
[root@ghs php]# cp php.ini-production /usr/local/php/etc/php.ini
[root@ghs php]# cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
 
7:设置启动脚本755权限
[root@ghs php]# chmod 755 /etc/init.d/php-fpm
 
8:加入系统服务
[root@ghs php]# chkconfig --add php-fpm
[root@ghs php]# chkconfig php-fpm on
 
9:编写php-fpm的conf文件
[root@ghs php]# vim /usr/local/php-fpm/etc/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
user = php-fpm
group = php-fpm
pm = dynamic ##表示动态的管理下面的
pm.max_children = 50 ##表示子进程最大50个
pm.start_servers = 20 ##表示一开始启动:20
pm.min_spare_servers = 5 ##表示空闲最小不能低于5个
pm.max_spare_servers = 35 ##表示空闲时最大不能大于35个
pm.max_requests = 500 ##表示一个子进程在它的生命周期内处理多少个请求500个
rlimit_files = 1024 ##表示每个进程使用描述符的限制1024
slowlog = /tmp/www slow.log ##此参数表示监控作用
request_slowlog_timeout = 1
 
执行/usr/local/php/sbin/php-fpm -t检查配置文件是否有误
如果出现诸如 “test is successful” 字样,说明配置没有问题。
 
10:启动服务
[root@ghs etc]# service php-fpm start
Starting php-fpm done
[root@host2 etc]# netstat -lnpt
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 2264/master
tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN 77055/php-fpm: mast
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1252/sshd
tcp6 0 0 ::1:25 :::* LISTEN 2264/master
tcp6 0 0 :::22 :::* LISTEN 1252/sshd
 
二、测试PHP解析
 
1:编写新的测试Nginx虚拟主机conf文件
[root@ghs vhosts]# vim /usr/local/nginx/conf/vhosts/test-php.conf
##以下内容加入到配置文件,/data/www为网站目录
server{
listen 80;
server_name localhost;
root /data/www;
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /data/www$fastcgi_script_name;
include fastcgi_params;
}
}
 
2:写php测试解析文件
[root@ghs vhosts]# vim /data/www/1.php
##加入以下内容到文件
<?php
echo "test php scripts.";
?>
 
3:curl测试解析是否显示test php scripts,则表示成功
[root@ghs vhosts]# curl localhost/1.php
test php scripts
posted @ 2019-09-29 20:16  一颗小豆子  阅读(147)  评论(0)    收藏  举报