1、依次执行以下三条命令 安装PHP和一些所需的扩展
rpm -Uvh https://mirror.webtatic.com/yum/el7/epel-release.rpmrpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpmyum -y install php70w-tidy php70w-common php70w-devel php70w-pdo php70w-mysql php70w-gd php70w-ldap php70w-mbstring php70w-mcrypt php70w-fpm
2、输入php -v
验证PHP的安装版本
3、systemctl start php-fpm
启动php服务
4、systemctl enable php-fpm
设为开机启动
5、修改nginx配置文件
在index里添加index.php
让Nginx支持php格式的主页
location /{root /usr/local/webserver/nginx/html;index index.html index.htm index.php;}
注:/usr/share/nginx/html
部分为自己Nginx的路径 其余无须改动
location ~ \.php$ {root html;fastcgi_pass 127.0.0.1:9000;fastcgi_indexindex.php;fastcgi_paramSCRIPT_FILENAME /usr/share/nginx/html$fastcgi_script_name;includefastcgi_params;}
保存退出
6、service nginx reload
重载配置文件
7、测试
输入vi info.php
在html包下创建一个名为info.php的测试页面
输入:
<?php phpinfo();?>
保存
然后再在浏览器输入http://服务器ip地址/info.php
若显示如下图 则PHP环境搭建成功: