美文网首页
centos 7 配置lnmp环境(php7.1版本) 操作集合

centos 7 配置lnmp环境(php7.1版本) 操作集合

作者: 庆庆_ce88 | 来源:发表于2019-05-10 19:50 被阅读0次

    安装nginx

        yum install nginx

    启动nginx:

        systemctl start nginx.service

    验证nginx是否开启

        ps -ef | grep nginx

    nginx开机自启

        systemctl enable nginx.service

    检查是否设置成功

        systemctl is-enabled nginx.service # 验证是否开启,有开启会显示enabled

    开启防火墙:

    systemctl start firewalld

    防火墙配置80端口开放:

     firewall-cmd --zone=public --add-port=80/tcp --permanent

    重启防火墙:

    systemctl  restart firewalld.service     (如果用vagrant需要重启虚拟机)

    安装mysql:

      1. wget  http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm (下载源)

      2. rpm -ivh mysql-community-release-el7-5.noarch.rpm                    (安装源)

    3.yum install mysql-server                                                                                           (安装)

      4. 重置密码:mysql -u rootmysql -u root

        几率报错 Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)

        原因:权限问题

         解决:sudo chown -R root:root /var/lib/mysql (两个root都可以改为拥有者,但是需要保持一致)

      5. 重启服务

          service mysqld restart

      6. 登陆mysql

         mysql -u root -p    按回车直接可以登陆,刚安装完mysql是没有密码的

    7. 修改mysql密码

            mysql > use mysql;

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

            mysql > exit;

      8. 重启

            service mysqld restart

      9. 登陆mysql

                   必要时加入以下命令行,为root添加远程连接的能力。链接密码为 “root”(不包括双引号)

           GRANT ALL PRIVILEGES ON *.* TO root@"%" IDENTIFIED BY "root";

      10. 开放3306端口

            firewall-cmd --zone=public --add-port=3306/tcp --permanent 

    10. 重启服务

    firewall-cmd --reload

    安装php(7.1版本)

      yum install epel-release            (下载源)

    rpm -ivh http://rpms.famillecollet.com/enterprise/remi-release-7.rpm

    yum install php71w php71w-fpm php71w-mbstring php71w-mysqlnd php71w-pecl-redis php71w-mcrypt php71w-opcache

        查看版本:php -v

    开启服务:

        systemctl startphp-fpm.service

    设置开机自动启动:

        systemctl enable php-fpm.service

    配置nginx支持php:

        1. cp /etc/nginx/nginx.conf  /etc/nginx/nginx.confbak # 备份原有配置文件

          vim /etc/nginx/nginx.conf # 编辑这个文件

          修改: user  nginx  nginx;  # 修改nginx运行账号为:nginx组的nginx用户

    添加绿色框中代码

    :wq保存退出

    2.cp /etc/nginx/nginx.default.conf  /etc/nginx/nginx.default.confbak # 备份原有配置文件

           vim /etc/nginx/conf.d/default.conf # 编辑

    45行左右 :

                 找到location / {增加index.php

    indexindex.phpindex.htmlindex.htm;65行左右:取消FastCGIserver部分location的注释

    特殊情况:

    配置成上面的方式,我的php文件并不能正常访问,要修改如下

    $document_root$fastcgi_script_name

    # 替换成绝对路径

    /usr/share/nginx/html$fastcgi_script_name

    配置php

    vim  /etc/php.ini

    设置中国时区:  date.timezone = PRC

    配置php-fpm

        cp /etc/php-fpm.d/www.conf  /etc/php-fpm.d/www.confbak # 备份原来的配置文件(随时备份)

        vim /etc/php-fpm.d/www.conf#

        修改内容如下

            user = nginx  # 由原来的apache换成nginx

            group = nginx # 由原来的apache换成nginx

    设置目录权限

        chown nginx.nginx /usr/share/nginx/html/ -R  # 设置目录所有者chmod 700 

    chmod 700  /usr/share/nginx/html/ -R# 设置目录权限

    重启服务

        systemctl restart nginx.service  # 重启nginx服务

        systemctl restart php-fpm.service # 重启php服务

    相关文章

      网友评论

          本文标题:centos 7 配置lnmp环境(php7.1版本) 操作集合

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