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;
    }
上一篇:linux命令安装 mysql,php,Apache以及站点配置,环境的搭建。


下一篇:Linux安装PHP扩展包冲突