一、安装PHP
1.安装php及插件 服务器默认安装的是php5.4版本的,如需安装高版本请参考第四节
#yum install php php-mysql php-common php-gd php-xml php-mbstring php-ldap php-pear php-xmlrpc
2.安装php-fpm
#yum install -y php-fpm
3.启动php-fpm
#service php-fpm start
4.检查启动是否成功
#service php-fpm status
5.设置开机自启动
#systemctl enable php-fpm.service
6.检查开机自启动是否设置成功
#systemctl list-dependencies | grep php-fpm
#ps -ef | grep php-fpm
二、安装nginx
1.安装Nginx所需前置插件:
#yum -y install zlib zlib-devel openssl openssl--devel pcre pcre-devel
2.安装:
#yum -y install nginx
3.启动:
#nginx
4.查看安装版本:
#nginx -v
5.设置开机启动:
#systemctl enable nginx
6.重启nginx命令
#nginx -s reload
三、nginx配置文件加载php项目
1.修改nginx配置文件
#vi /etc/nginx/nginx.conf
2.添加php配置
server {
listen 80;
server_name localhost;
root /www/wwwroot/php-project;
location / {
index index.html index.htm index.php;
}
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
3.把php项目“php-project”放到/www/wwwroot/目录下面,否则会出现权限问题找不到php文件
4.重启nginx
#nginx -s reload
5.配置完成!
四、安装PHP7版本
更换rpm 源,执行下面两个
#rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
#rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
//查看
yum search php71w
安装php7.1 以及扩展
#yum install php71w php71w-fpm php71w-cli php71w-common php71w-devel php71w-gd php71w-pdo php71w-mysql php71w-mbstring php71w-bcmath
3.若php-fpm安装有问题,执行以下命令
yum -y install php* --skip-broken
4.查看版本
#php -v
#php-fpm -v