美文网首页
Centos7下搭建LNMP环境

Centos7下搭建LNMP环境

作者: 墨丘利lh | 来源:发表于2018-11-26 23:01 被阅读0次

    关闭防火墙和selinux

    打开文件selinux

    vim  /etc/sysconfig/selinux将文件中SELINUX=enforcing改为disabled,然后执行”setenforce0″不用重启地关闭selinux。

    SELINUX=disabled关闭放火墙

    systemctl stop firewalld.service

    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 usersetpassword=password(‘123456‘)whereuser=‘root‘;

    mysql > exit;

    下载对应当前系统版本的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

    rpm 安装 Php7 相应的 yum源

    rpm -Uvh https://mirror.webtatic.com/yum/el7/epel-release.rpmrpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm安装php7.0yum 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

    yum install -y php70w-fpm3. 修改配置文件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;

    ​ }3.2修改php-fpm配置文件

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

    ​ 修改

    user =nginx

    ​ group=nginx4.放入测试文件

    cd /forest/nginxDir/html

    echo 'hello eric'>index.php5.启动服务5.1启动nginx服务:

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

    systemctl status nginx 

    启动PHP-FPM:

    systemctl start php-fpm.service

    查看启动状态:

    systemctl status php-fpm.service

    设置开机自启动服务

    systemctl enable php-fpm.service

    systemctl enable nginx.service

    相关文章

      网友评论

          本文标题:Centos7下搭建LNMP环境

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