Feng’ Blog

CentOS7 nginx+PHP7 简易环境搭建
先把yum源换成国内的阿里云镜像源(当然不换也可以),先备份一下原来的源镜像文件,以免出错后可以恢复:mv /et...
扫描右侧二维码阅读全文
29
2017/11

CentOS7 nginx+PHP7 简易环境搭建

先把yum源换成国内的阿里云镜像源(当然不换也可以),先备份一下原来的源镜像文件,以免出错后可以恢复:

mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup

下载新的CentOS-Base.repo 到/etc/yum.repos.d/,版本根据自己的系统版本选择下载:

CentOS 5
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-5.repo

CentOS 6
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo

CentOS 7
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo

更改/etc/yum.repos.d/CentOS-Media.repo使其为不生效:

enabled=0

运行yum makecache生成缓存:

yum clean all
yum makecache
yum update

安装Nginx

由于yum源中没有我们想要的nginx,那么我们就需要创建一个“/etc/yum.repos.d/nginx.repo”的文件,其实就是新增一个yum源。

vi /etc/yum.repos.d/nginx.repo

把如下内容复制进去:

[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=0
enabled=1

然后保存退出,输入 yum list nginx 查看,
php123123.png

  1. 如果执行命令是这样的显示效果,那么我们的nginx的yum源就配置成功啦!

然后要安装我们的nginx就直接执行:

yum -y install nginx

这样nginx的最新官网版本就安装好了!

启动nginx:

nginx      #启动nginx
# curl 127.0.0.1

nginx就安装成功!

接一下安装php

安装PHP7

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

执行命令安装php7:

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

安装php-fpm:

yum install php70w-fpm php70w-opcache

启动php-fpm:

systemctl start php-fpm

修改 /etc/nginx/conf.d/default.conf 文件,找到下面这段并改为如下所示:

vi /etc/nginx/conf.d/default.conf
location ~ \.php$ {
        root           /usr/share/nginx/html;
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include        fastcgi_params;
}

保存退出。接着重启nginx:

nginx -s reload

打开浏览器,看到如下图说明运行成功:
php3.png
至此环境搭建完成。

Last modification:January 8th, 2019 at 06:33 pm
If you think my article is useful to you, please feel free to appreciate

Leave a Comment