centos7搭建LNMP环境

原文:https://www.cnblogs.com/lishanlei/p/9055344.html

一、系统镜像源切换

系统:centos7
关闭防火墙和selinux

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

yum -y install wget

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

vim /etc/yum.repos.d/CentOS-Media.repo
enable=0

yum clean all
yum makecache
yum update

二、安装Nginx

##增加一个Nginx的源Nginx.repo
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

yum list |grep Nginx


----------------------------------------------------------------------------------
##安装Nginx
yum -y install Nginx

Nginx    #启动

curl 127.0.0.1    #查看是否有HTML反馈,有的话,代表安装成功

##开机启动
systemctl enable Nginx
systemctl daemon-reload

三、安装MysqL5.7

rpm -Uvh http://dev.MysqL.com/get/MysqL57-community-release-el7-9.noarch.rpm

##查看5.7版本是否已经启用
yum repolist all | grep MysqL

##如果没有启用的话,我们可以修改文件
/etc/yum.repos.d/MysqL-community.repo

##把MysqL57的enabled改为1就可以了,其他的版本改为0

yum repolist enabled | grep MysqL


---------------------------------------------------------------------------------
##安装
yum -y install MysqL-community-server

##启动
service MysqLd start

##开机启动设置
systemctl enable MysqLd
systemctl daemon-reload


---------------------------------------------------------------------------------
##MysqL安装完成之后会在LOG文件(/var/log/MysqLd.log)中生成一个root的认密码
grep 'temporary password' /var/log/MysqLd.log

##登录MysqL修改root密码,xxxxxx代指密码
MysqL -u root -p                            #这里的密码就是刚才日志文件里的密码
MysqL> set password=password('xxxxxx');                    #进去以后改root密码,有复杂度要求,设置复杂一些

##授权
MysqL> grant all privileges on *.* to root@'%' identified by 'xxxxxx';             #解决客户端root用户远程连接服务器的问题
MysqL> grant all privileges on *.* to 'root'@'node1' identified by  'xxxxxx' with grant option;     #解决root权限访问所有库的问题,node01可以换为localhost 
MysqL> flush privileges;

四、安装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

##开机启动设置
systemctl enable PHP-fpm
systemctl daemon-reload

五、让Nginx支持PHP

修改 /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 (engine x) 是一个高性能的HTTP和反向代理服务,也是一...
本地项目配置 1 复制 luffy/settings/dev.py为prop.py 修改l...
nginx不仅可以隐藏版本信息,还支持自定义web服务器信息 先看...
一 、此次漏洞分析 1 nginx HTTP/2漏洞 [nginx-announce] ng...
###进入nginx 目录cd /usr/local/nginx###递归显示 2 级目录...
在cmd命令窗口输入下面命令进行查看 tasklist /fi "ima...