美文网首页
Centos7搭建LNMP环境

Centos7搭建LNMP环境

作者: Aria_CJ | 来源:发表于2018-03-08 18:00 被阅读0次

You have to know...


什么是LNMP?

LNMP全称是:Linux+Nginx+Mysql+PHP

为什么要使用LNMP?

目前主流的Web服务器有三种:Apache、Nginx、IIS。IIS是运行在Windos环境下的,而Apache和Nginx都是运行在Linux环境下的Web服务器;Nginx相比Apache有使用更少的系统资源,支持更多的并发连接数,性能稳定,使用简单等诸多优点,轻巧而高效,体现出更高的效率。

下面进入安装步骤:

1、关闭SELinux和防火墙

打开SELinux文件并修改SELINUX参数

vim /etc/sysconfig/selinux

SELINUX=disabled

执行如下命令 临时关闭(不用重启机器)

setenforce 0

关闭防火墙

systemctl stop firewalld.service

禁止防火墙开机启动

systemctl disable firewalld.service

2、安装Mysql

下载Mysql的repo源

wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm

安装mysql-community-release-el7-5.noarch.rpm包

rpm -ivh mysql-community-release-el7-5.noarch.rpm

执行安装Mysql

yum install -y mysql-server

更改Mysql用户权限

chown -R root:root /var/lib/mysql

重启服务

systemctl restart mysql.service

查看Mysql是否开启

systemctl status mysql.service

登陆Mysql并修改密码

mysql -u root

mysql > use mysql;

mysql > update user set password=password(‘123456‘) where user=‘root‘;

mysql >  GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'root' WITH GRANT OPTION;

mysql > flush privileges;

mysql > exit;

设置Mysql开机启动

systemctl enable mysqld.service

3、安装Nginx

下载对应当前系统版本的Nginx包

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

创建Nginx的yum仓库

rpm -ivh nginx-release-centos-7-0.el7.ngx.noarch.rpm

下载并安装Nginx

yum install -y nginx

开启Nginx

systemctl start nginx.service

查看Nginx是否运行成功

systemctl status nginx.service

设置Nginx开机启动

systemctl enable nginx.service

4、安装PHP7

rpm 安装 PHP7 相应的 yum源

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

执行安装PHP

yum install -y php70w

使用PHP -V命令查看是否安装成功(如果出现版本号则代表安装成功)

php -v

安装PHP扩展

yum install -y php70w-mysql.x86_64 php70w-gd.x86_64 php70w-ldap.x86_64 php70w-mbstring.x86_64 php70w-mcrypt.x86_64

安装PHP-FPM

yum install -y php70w-fpm

使用PHP-FPM -V命令查看是否安装成功(如果出现版本号则代表安装成功)

php-fpm -v

开启PHP-FPM

systemctl start php-fpm.service

设置PHP-FPM开机启动

systemctl enable php-fpm.service

安装Redis扩展

yum install -y php70w-pecl-redis

安装OPcache扩展

yum install -y php70w-opcache

5、修改Nginx配置文件

打开配置文件

vim /etc/nginx/conf.d/default.conf

修改如下(去掉# 参考root目录和fastcgi_param参数)

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服务

systemctl restart nginx.service

再次查看Nginx是否运行成功

systemctl status nginx.service

6、最后安装FTP上传PHP文件测试效果

安装FTP

yum install -y vsftpd

开启FTP

systemctl start vsftpd.service

设置FTP开机启动

systemctl enable vsftpd.service

新建用户

adduser test

为用户设置密码

passwd test

给Nginx网站根目录设置权限

chmod -R 777 /usr/share/nginx/html

使用刚刚新建的用户上传一个PHP文件,如果访问成功则证明LNMP环境已部署成功。

有可能出现的问题

Centos7上默认是安装了Vi编辑器,但Vim编辑器是未安装或者是未完全安装的;但Vim功能是要比Vi要强大的,那么如果我们要安装Vim编辑器应该怎么做呢?

第一步:检查是否已安装过Vim

rpm -qa|grep vim

第二步:是否出现完整的包名 如:

vim-minimal-7.4.160-2.el7.x86_64

第三步:运行安装

yum -y install vim*

同理Wget也一样

rpm -qa|grep wget

安装

yum -y install wget

注:Centos在最小化安装下 如果不完成这两步是无法完成LNMP环境的搭建的。

相关文章

网友评论

      本文标题:Centos7搭建LNMP环境

      本文链接:https://www.haomeiwen.com/subject/wmvyfftx.html