阿里云CentOS7.3手动搭建LNMP

**

1.关闭防火墙和selinux
---------------

**

关闭防火墙

[root@localhost ~]# systemctl stop firewalld.service

selinux

[root@localhost ~]# vim  /etc/sysconfig/selinux
找到 SELINUX=enforcing 把enforcing改为disabled 
[root@localhost ~]# setenforce 0
**

2.安装nginx
---------

**

wget下载安装nginx包

[root@localhost ~]# wget http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm

建立nginx的yum仓库

[root@localhost ~]#  rpm -ivh nginx-release-centos-7-0.el7.ngx.noarch.rpm

install & start nginx

[root@localhost ~]# yum install -y nginx
[root@localhost ~]# systemctl start nginx.service
**

3.安装 mysql
----------

**

下载repo资源

[root@localhost ~]# wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm

安装mysql-community-release-el7-5.noarch.rpm

[root@localhost ~]# rpm -ivh mysql-community-release-el7-5.noarch.rpm

安装mysql & 设置用户权限 & 重启

[root@localhost ~]# sudo yum install -y  mysql-server
[root@localhost ~]# sudo chown -R root:root /var/lib/mysql
[root@localhost ~]# systemctl restart mysql.service

登陆MySQL,修改密码(可以所有安装完成后自行设置):

[root@localhost ~]# mysql -u root
mysql > use mysql;
mysql > update user set password=password(‘123456‘) where user=‘root‘;
mysql > flush privilgegs;
mysql > exit;
**

3.PHP7安装
-------

**

rpm安装php相应的yum资源

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

install php7.0

[root@localhost ~]# yum install -y php70w

安装扩展

[root@localhost ~]# 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

[root@localhost ~]# ​yum install -y php70w-fpm

**

修改配置

**
nginx配置文件修改:可以直接在nginx.conf修改,怕修改坏的,自己在con.d里面新建一个.conf文件

user  nginx;

worker_processes auto;

error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;

#Specifies the value for maximum file descriptors that can be opened by this process.
worker_rlimit_nofile 51200;

events
    {
        use epoll;
        worker_connections 51200;
        multi_accept on;
    }

http
    {
        include       mime.types;
        default_type  application/octet-stream;

        server_names_hash_bucket_size 128;
        client_header_buffer_size 32k;
        large_client_header_buffers 4 32k;
        client_max_body_size 50m;

        sendfile   on;
        tcp_nopush on;

        keepalive_timeout 60;

        tcp_nodelay on;

        fastcgi_connect_timeout 300;
        fastcgi_send_timeout 300;
        fastcgi_read_timeout 300;
        fastcgi_buffer_size 64k;
        fastcgi_buffers 4 64k;
        fastcgi_busy_buffers_size 128k;
        fastcgi_temp_file_write_size 256k;

        gzip on;
        gzip_min_length  1k;
        gzip_buffers     4 16k;
        gzip_http_version 1.1;
        gzip_comp_level 2;
        gzip_types     text/plain application/javascript application/x-javascript text/javascript text/css application/xml application/xml+rss;
        gzip_vary on;
        gzip_proxied   expired no-cache no-store private auth;
        gzip_disable   "MSIE [1-6]\.";

        #limit_conn_zone $binary_remote_addr zone=perip:10m;
        ##If enable limit_conn_zone,add "limit_conn perip 10;" to server section.

        server_tokens off;
        access_log off;




    server
        {
            listen 80 default_server;
            server_name "域名也可以是ip";
            index index.html index.htm index.php;
            root  /forest/www(改成你自己的放置代码的目录:自定义);

            #error_page   404   /404.html;


        location ~ [^/]\.php(/|$)
        {
            try_files $uri =404;
           # fastcgi_pass  unix:/tmp/php-cgi.sock;
            fastcgi_pass  127.0.0.1:9000;
            fastcgi_index index.php;
            include fastcgi.conf;
        }


            location /nginx_status
            {
                stub_status on;
                access_log   off;
            }

            location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
            {
                expires      30d;
            }

            location ~ .*\.(js|css)?$
            {
                expires      12h;
            }

            location ~ /\.
            {
                deny all;
            }

            access_log  /home/access.log;
        }

    # 载入其他配置
    #include vhost/*.conf;

}

修改php-fpm配置文件

[root@localhost ~]# vim /etc/php-fpm.d/www.conf
找到 修改成这样
    user =nginx
​    group=nginx

在设定的root目录下防止一个测试文件

echo 'HELLO VAN!';

**

启动服务器

**

[root@localhost ~]# systemctl start nginx.service

查看服务器状态

[root@localhost ~]# systemctl status nginx 

阿里云CentOS7.3手动搭建LNMP_第1张图片

启动PHP-FPM

[root@localhost ~]# systemctl start php-fpm.service
[root@localhost ~]# systemctl status php-fpm.service 

阿里云CentOS7.3手动搭建LNMP_第2张图片

在浏览器输入ip或者绑定的域名就OK了!

诶呀妈呀 终于写好了

你可能感兴趣的:(centos7,lnmp)