萧邦之殇

If not me who, If not now when
aliyun+LNMP

阿里云Centos7上搭建LNMP服务器环境

阿里云Centos7上搭建LNMP服务器环境,为个人博客和Laravel商城开发做准备。

安装

1、安装 Nginx :

yum install nginx18 -y
systemctl start nginx.service #启动nginx
systemctl stop nginx.service #停止nginx
systemctl restart nginx.service #重启nginx
systemctl enable nginx.service #设置nginx开机启动

2、安装MariaDB(CentOS 7.0中,已经使用MariaDB替代了MySQL数据库)

安装

yum install mariadb mariadb-server -y #安装
systemctl start mariadb.service #启动MariaDB
systemctl stop mariadb.service #停止MariaDB
systemctl restart mariadb.service #重启MariaDB
systemctl enable mariadb.service #设置开机启动
cp /usr/share/mysql/my-huge.cnf /etc/my.cnf #拷贝配置文件(注意:如果/etc目录下面默认有一个my.cnf,直接覆盖即可)

设置Root密码

mysql_secure_installation
#回车,根据提示输入Y
#输入2次密码,回车
#根据提示一路输入Y
#最后出现:Thanks for using MySQL!
#MariaDB密码设置完成,重新启动 MariaDB:
systemctl restart mariadb.service #重启MariaDB

3、安装 PHP :

建议将下面插件一次性安装,如mbstring、openssl插件,避免单独安装出现的坑~~!

yum install php71w-fpm php71w-mysql php71w-mysqli php71w php71w-opcache php71w-gd php71w-intl php71w-mbstring php71w-exif php71w-mcrypt php71w-openssl -y

php服务相关操作

systemctl start php-fpm.service #启动php-fpm
systemctl stop php-fpm.service #停止php-fpm
systemctl restart php-fpm.service #重启php-fpm
systemctl enable php-fpm.service #设置开机启动

配置

1、配置php-fpm:

vi /etc/php-fpm.d/www.conf

#修改user和group
user = nginx
group = nginx

2、配置 Nginx:

    server {
        listen       80 default_server;
        # listen       [::]:80 default_server;
        server_name  www.geek720.com;
        # set $root_path        /var/www/laravel/market/public/;
        set $root_path  /var/www/websites/blog;
        root $root_path;
        # Load configuration files for the default server block.
        include /etc/nginx/default.d/*.conf;
        index   index.html index.htm index.php;

        location / {
            try_files $uri $uri/ /index.php?$query_string;
        }

        error_page 404 /404.html;
            location = /40x.html {
        }

        error_page 500 502 503 504 /50x.html;
            location = /50x.html {
        }
 location ~ \.php {
            fastcgi_pass 127.0.0.1:9000;
            fastcgi_index /index.php;

            include /etc/nginx/fastcgi_params;

            fastcgi_split_path_info     ^(.+\.php)(/.+)$;
            fastcgi_param PATH_INFO     $fastcgi_path_info;
            fastcgi_param PATH_TRANSLATED       $document_root$fastcgi_path_info;
            fastcgi_param SCRIPT_FILENAME       $document_root$fastcgi_script_name;
        }

        location ~* ^/(css|img|js|flv|swf|download)/(.+)$ {
            root $root_path;
        }

        location ~/\.ht {
            deny all;
        }
    }

3、重启nginx服务

service nginx restart

4、在配置目录/var/www/websites/blog下,创建测试文件index.php,如能正常访问,则安装正常。

Tags:

发表回复

Your email address will not be published. Required fields are marked *.

*
*

鄂ICP备2025138472号-1