LNMP环境搭建与配置(lnmp yum 安装全步骤)

1. 安装MySQL

之前做过MySQL安装,这里便不再做了,想知道MySQL安装步骤可点下面链接
mysql

2. 安装Nginx

[root@xianxin ~]# cd /etc/yum.repos.d/
[root@xianxin yum.repos.d]# vi nginx.repo (添加以下内容)

[nginx]
name=nginx      repo
baseurl=http://nginx.org/packages/centos/7/$basearch/
gpgcheck=0
enabled=1

执行yum安装
[root@xianxin ~]# yum installnginx -y
[root@xianxin ~]# systemctl start nginx
[root@xianxin ~]# systemctl enable nginx

3. 安装PHP

(1)使用第三方扩展epel源安装php7.2
[root@xianxin ~]# yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm -y
[root@xianxin ~]# yum install yum-utils -y
[root@xianxin ~]# yum-config-manager --enable remi-php72
[root@xianxin ~]# yum search php72

[root@xianxin ~]# rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
[root@xianxin ~]# rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm

不成功的话可以直接使用后两个步骤(我是使用全部的命令,我有两个同学是直接使用最后两条命令成功的,但我个人建议使用全部命令为好)
LNMP环境搭建与配置(lnmp yum 安装全步骤)_第1张图片
如果第二条命令出错的话多试几次就可以了
(2)清除版本
[root@xianxin ~]# yum -y remove php*
(3)安装php

[root@xianxin ~]# yum -y install php72w php72w-cli php72w-fpm php72w-common php72w-devel php72w-embedded php72w-gd php72w-mbstring php72w-mysqlnd php72w-opcache php72w-pdo php72w-xml php72w-redis

(4)启动php-fpm服务
[root@xianxin ~]# systemctl enable php-fpm.service
[root@xianxin ~]# systemctl start php-fpm.service
(5)启动php-fpm
[root@xianxin ~]# service php-fpm start

4. 配置nginx支持PHP

[root@xianxin ~]# vi /etc/nginx/conf.d/default.conf(更改添加 location / {}里面的内容)

server {
     
    listen       80;
    server_name  localhost;

    #access_log  /var/log/nginx/host.access.log  main;

    location / {
     
        root   /soft/code;
        index  index.php index.html index.htm;
        location ~ \.php$ {
     
            fastcgi_pass    127.0.0.1:9000;
            fastcgi_index   index.php;
            fastcgi_param  SCRIPT_FILENAME  /soft/code$fastcgi_script_name;
            include  fastcgi_params;
        }
    }

    #error_page  404              /404.html;

    # redirect server error pages to the static page /50x.html
    #
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
     
        root   /usr/share/nginx/html;
    }

    # proxy the PHP scripts to Apache listening on 127.0.0.1:80
    #
    #location ~ \.php$ {
     
    #    proxy_pass   http://127.0.0.1;
    #}

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    #location ~ \.php$ {
     
    #    root           html;
    #    fastcgi_pass   127.0.0.1:9000;
    #    fastcgi_index  index.php;
    #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
    #    include        fastcgi_params;
    #}

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    #location ~ /\.ht {
     
    #    deny  all;
    #}
}

重启nginx
[root@xianxin ~]# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
[root@xianxin ~]# nginx -s reload
新建目录
[root@xianxin ~]# mkdir -p /soft/code
[root@xianxin ~]# vi /soft/code/info.php

<?php
    phpinfo();
?>

浏览网页
http://192.168.60.78/info.php
LNMP环境搭建与配置(lnmp yum 安装全步骤)_第2张图片

你可能感兴趣的:(笔记,linux,centos,nginx,lnmp,mysql)