LNMP之php安装(centos6.8)

一. PHP介绍 :

     PHP即“超文本预处理器”,是一种通用开源脚本语言。PHP是在服务器端执行的脚本语言,与C语言类似,是常用的网站编程语言。PHP独特的语法混合了C、JavaPerl以及 PHP 自创的语法。利于学习,使用广泛,主要适用于Web开发领域.

二.安装前准备 :

1) PHP官网地址:   https://www.php.net

2) 官网下载php包地址:https://www.php.net/downloads

三.下面开始安装:

# wget  https://www.php.net/distributions/php-5.6.29.tar.gz

# tar -zxvf php-5.6.29.tar.gz

# cd php-5.6.29

./configure --prefix=/usr/local/php --enable-mbstring --with-mcrypt --with-mhash --enable-fpm

make && make install

2.下面开始配置:

# cd  /usr/local/php/etc

# 需要对目录下的php-fpm配置文件备份并且编辑配置

# cp php-fpm.conf.default  php-fpm.conf

# vim php-fpm.conf

#去掉下列变量前面的注释,以避免启动php-fpm时报错

pm.start_servers = 20
pm.min_spare_servers = 5
pm.max_spare_servers = 35
pm.max_requests = 500

:wq 保存 退出

3.配置整合Nginx和PHP

# vim /usr/local/nginx/conf/nginx.conf

location / {
      root /data/nginxwebs;    # 项目目录  
      index index.html index.htm index.php;  # 在原来基础上增加解析index.php 
}

location ~ /.php$ {
  root html;
  fastcgi_pass 127.0.0.1:9000;
  fastcgi_index index.php;
       fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;

  include fastcgi_params; 

}

4.重启nginx以及php进行访问 。

1)重启nginx:/usr/local/nginx/sbin/nginx -s reload

2)重启php    /usr/local/php/sbin/php-fpm 

#以下为本次安装中的报错解决:

1.Error: mcrypt.h not found. Please reinstall libmcrypt ?

yum  install  php-mcrypt  libmcrypt  libmcrypt-devel 

2.还有其他的依赖库报错需要进行安装(仅供参考)

yum install libxml2-devel  

yum install curl curl-devel

## php-fpm ?

1.PHP-FPM是一个PHPFastCGI管理器,是只用于PHP的.

2.相对Spawn-FCGI,PHP-FPM在CPU和内存方面的控制都更胜一筹,而且前者很容易崩溃,必须用crontab进行监控,而PHP-FPM则没有这种烦恼。
3.PHP-FPM提供了更好的PHP进程管理方式,可以有效控制内存和进程、可以平滑重载PHP配置,比spawn-fcgi具有更多优点,所以被PHP官方收录了。
4.在./configure的时候带 –enable-fpm参数即可开启PHP-FPM。

=============使用PHP-FPM来控制PHP-CGI的FastCGI进程==================
/usr/local/php/sbin/php-fpm{start|stop|quit|restart|reload|logrotate}
--start 启动php的fastcgi进程
--stop 强制终止php的fastcgi进程
--quit 平滑终止php的fastcgi进程
--restart 重启php的fastcgi进程
--reload 重新平滑加载php的php.ini
--logrotate 重新启用log文件

致此本次安装完成,以上属个人安装,仅供参考 。

原文地址:https://www.cnblogs.com/victorcode/p/8275527.html