环境是CentOS7

第一步 安装php, php-fpm

#为什么要安装 php-fpm的呢, 个人理解是php只是解释器, php-fpm是FastCGI进程管理器, 得靠php-fpm提供支持才行。
yum install php php-fpm

第二步 让nginx支持php

#原本第5行是fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name; 需要把/scripts改成$document_root
location ~ \.php$ {
    root           /var/www/strval.com;
    fastcgi_pass   127.0.0.1:9000;
    fastcgi_index  index.php;
    fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
    include        fastcgi_params;
}
#支持path_info模式, \.php后面加正则(.*), 增加第5行和第7行
location ~ \.php(.*)$ {
    root           /var/www/strval.com;
    fastcgi_pass   127.0.0.1:9000;
    fastcgi_index  index.php;
    fastcgi_split_path_info  ^(.+\.php)(.*)$;
    fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
    fastcgi_param  PATH_INFO $fastcgi_path_info;
    include        fastcgi_params;
}
#支持伪静态
在localtion / {}中的最后一行添加
if (!-e $request_filename) {
rewrite ^(.*)$ /index.php/$1 last;
}

第三步 然php-fpm跑起来并重启nginx

systemctl start php-fpm
systemctl enable php-fpm
systemctl restart nginx

# 安装一些扩展,安装之后记得重启PHP
yum install php-mysql php-mysqli php-pdo php-gd libjpeg* php-imap php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-mcrypt php-bcmath php-mhash libmcrypt curl curl-devel