《轻松学linux》第七课、在CentOS7上搭建LNMP环境


  • administrators

    LNMP所需软件包安装

    启动epel的源

    yum install epel-release
    

    关闭SELinux

    SELinux是严格访问模式,初学linux建议把此功能关闭。编辑/etc/selinux/config

    #改此行值为disabled
    SELINUX=disabled
    

    修改完成后重启服务器,如果不想重启,也可以用命令

    setenforce 0
    

    安装nginx、mysql、php、fast-cgi

    yum install nginx mariadb-server mariadb php php-fpm php-mysql
    

    启动nginx 、mysql、php-fpm

    systemctl start nginx
    systemctl start mariadb
    systemctl start php-fpm
    

    启动上面服务后,我们把他们都设置为开机启动:

    systemctl enable nginx
    systemctl enable mariadb
    systemctl enable php-fpm
    

    配置测试站点

    这里我们以test.com为例添加一个新的虚拟站点。

    在nginx上添加新的站

    我们编辑vim /etc/nginx/conf.d/test.com.conf ,添加以下内容:

    server {
        listen      80;
        server_name www.test.com;
        charset     utf-8;
        index index.php;
        location ~ .php$ {
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }
        root /var/www/www.test.com/;
    }
    

    创建测试文件

    站点配置好了,我们创建站点的根目录和测试文件:

    mkdir /var/www/www.test.com
    touch /var/www/www.test.com/index.php
    

    我们修改此文件vim /var/www/www.test.com/index.php添加以下内容:

    <?php
    phpinfo();
    ?>
    

    然后修改下目录权限,让此目录属主为nginx

    chown -R nginx:nginx /var/www/www.test.com
    

    让nginx重新加载配置

    #用重启命令
    systemctl restart nginx
    #用文件重载命令
    systemctl reload nginx
    

    视频


登录后回复

Looks like your connection to 首页 was lost, please wait while we try to reconnect.