Centos 7.3搭建LNMP环境

前端之家收集整理的这篇文章主要介绍了Centos 7.3搭建LNMP环境前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

1. 关闭防火墙和selinux

打开文件selinux

vim  /etc/sysconfig/selinux
  • 1

文件中SELINUX=enforcing改为disabled,然后执行”setenforce 0″不用重启地关闭selinux。

SELINUX=disabled
  • 关闭放火墙

    systemctl stop firewalld.service
    • 1

    2.安装软件

    2.1.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

        ​ sudo yum install -y  MysqL-server
        • ​ 更改MysqL用户权限:

          sudo chown -R root:root /var/lib/MysqL
          • ​ 重启服务:

            systemctl restart MysqL.service
            • 登录,并修改密码

              MysqL -u root
              MysqL > use MysqL;
              MysqL > update user set password=password(‘123456‘) where user=‘root‘;
              MysqL > flush privilgegs;
              MysqL > exit;
              • 1
              • 2
              • 3
              • 4
              • 5

              2.2Nginx安装

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

              ​ wget http://Nginx.org/packages/centos/7/noarch/RPMS/Nginx-release-centos-7-0.el7.ngx.noarch.rpm
              • 建立Nginx的yum仓库(默认yum是没有Nginx的)

                rpm -ivh Nginx-release-centos-7-0.el7.ngx.noarch.rpm
                • 下载并安装Nginx

                  ​ yum install -y Nginx
                  • Nginx启动

                    ​ systemctl start Nginx.service
                    • 1

                    2.3安装PHP

                    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
                    • 2

                    安装PHP7.0

                    yum install -y PHP70w
                    • 安装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
                        • 3. 修改配置文件

                          3.1修改Nginx配置文件

                          Nginx配置文件位置:(/etc/Nginx/conf.d/default.conf)

                          vim /etc/Nginx/conf.d/default.conf
                          • 修改 root目录,可自定义

                            root   /forest/NginxDir/html;
                            • ​ 配置PHP解析,修改 下面代码中黑色加粗部分:

                              location ~.PHP$ {
                               root   /forest/NginxDir/html;
                              ​ fastcgi_pass 127.0.0.1:9000;
                              ​ fastcgi_index index.PHP;
                              ​fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                              ​ include    fastcgi_params;
                              ​ }
                              • 5
                              • 6
                              • 7

                              3.2 修改PHP-fpm配置文件

                              PHP-fpm配置文件位置:(/etc/PHP-fpm.d/www.conf)
                              修改

                              user =Nginx ​ group=Nginx
                              • 2

                              4.放入测试文件

                              cd /forest/NginxDir/html
                              echo 'hello eric' >index.PHP
                              • 5.启动服务

                                5.1启动Nginx服务:

                                systemctl start Nginx.service
                                • ​ 查看启动状态:

                                  systemctl status Nginx
                                  • 看到以下字眼说明启动成功!
                                    ​Active: active (running) since 六 2016-11-19 13:40:04 CST; 50min ago

                                    5.2.启动PHP-FPM:

                                    systemctl start PHP-fpm.service 
                                    • ​ 查看启动状态:

                                      systemctl status PHP-fpm.service
                                      • 看到以下字眼说明启动成功!​Active: active (running) since 六 2016-11-19 14:14:33 CST; 18min ago

原文链接:https://www.f2er.com/centos/374592.html

猜你在找的CentOS相关文章