我爱编程

Centos7下Yum安装nginx 和php

2017-03-22  本文已影响0人  一指弹风

一、安装nginx

安装nginx

方法一 EPEL源

1   yum-y install epel-release

2   yum-y install nginx

方法二 nginx官方源

1   rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm

2   yum -y install nginx

设置防火墙

1   firewall-cmd --permanent --add-service=http

2   firewall-cmd --reload

设置自动启动

systemctl enable nginx

启动nginx

systemctl start nginx

二、安装php

默认的版本太低,采用Yum安装的可以使用下面的方案:

1.检查当前安装的PHP包

yum list installed | grep php

如果有安装的PHP包,先删除他们

yum remove php.x86_64 php-cli.x86_64 php-common.x86_64 php-gd.x86_64 php-ldap.x86_64 php-mbstring.x86_64 php-mcrypt.x86_64 php-mysql.x86_64 php-pdo.x86_64

2. 添加yum源

Centos 5.X
rpm -Uvh http://mirror.webtatic.com/yum/el5/latest.rpm

CentOs 6.x
rpm -Uvh http://mirror.webtatic.com/yum/el6/latest.rpm

CentOs 7.X
rpm -Uvh https://mirror.webtatic.com/yum/el7/epel-release.rpm
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm

如果想删除上面安装的包,重新安装

rpm -qa | grep webstatic

rpm -e  上面搜索到的包即可

3.运行yum install

yum install php55w.x86_64 php55w-cli.x86_64 php55w-common.x86_64 php55w-gd.x86_64 php55w-ldap.x86_64 php55w-mbstring.x86_64 php55w-mcrypt.x86_64 php55w-mysql.x86_64 php55w-pdo.x86_64

yum install php56w.x86_64 php56w-cli.x86_64 php56w-common.x86_64 php56w-gd.x86_64 php56w-ldap.x86_64 php56w-mbstring.x86_64 php56w-mcrypt.x86_64 php56w-mysql.x86_64 php56w-pdo.x86_64

注:如果想升级到5.6把上面的55w换成56w就可以了。

yum install php70w.x86_64 php70w-cli.x86_64 php70w-common.x86_64 php70w-gd.x86_64 php70w-ldap.x86_64 php70w-mbstring.x86_64 php70w-mcrypt.x86_64 php70w-mysql.x86_64 php70w-pdo.x86_64

4.安装PHP FPM

yum install php55w-fpm

yum install php56w-fpm

yum install php70w-fpm

注:如果想升级到5.6把上面的55w换成56w就可以了。

三、配置  /etc/nginx/nginx.conf 文件

location / {
}

下面增加以下内容,注意 fastcgi_param 路径

location ~ .php$ {
          fastcgi_pass  127.0.0.1:9000;
          fastcgi_index  index.php;
          fastcgi_param  SCRIPT_FILENAME  /usr/share/nginx/html$fastcgi_script_name;
          include        fastcgi_params;
}

四、其它

打开防火墙9000端口

firewall-cmd --zone=public --add-port=9000/tcp --permanent

重启服务,并把服务加入系统启动

s

systemctl restart php-fpm.service

systemctl enable nginx.service

systemctl enable php-fpm.service

检查版本

nginx -v

php -v

五、测试

127.0.0.1/index.html   #显示nginx信息

测试Php

默认www位置: /usr/share/nginx/html/

vi index.php
<?php
     phpinfo();
?>

127.0.0.1/index.php  #显示php信息

上一篇 下一篇

猜你喜欢

热点阅读