阿里雲CentOS7下部署Nginx,MySQL,PHP7環境

聰聰發表於2018-06-13

1、準備

  1. 更新

sudo yum update

  1. 安裝 wget

sudo yum install wget

2、安裝Nginx

阿里雲預設使用了自己的映象源。
不是阿里雲需要下載對應當前系統版本的nginx包
建立nginx的yum倉庫(預設yum是沒有nginx的)
複製程式碼

wget http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm

sudo rpm -ivh nginx-release-centos-7-0.el7.ngx.noarch.rpm

開始安裝Nginx

sudo yum install -y nginx

Nginx啟動

sudo systemctl start nginx

3、安裝php

  1. rpm 安裝 Php7 相應的 yum源

sudo rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm

sudo rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm

  1. 安裝

sudo yum install -y php70w

  1. 安裝php擴充套件(部分)

sudo yum install -y php70w-mysql.x86_64 php70w-gd.x86_64 php70w-ldap.x86_64 php70w-mbstring.x86_64 php70w-mcrypt.x86_64

  1. 安裝PHP FPM

sudo yum install -y php70w-fpm

  1. 啟動PHP FPM

sudo systemctl start php-fpm

  1. 檢視啟動狀態:

systemctl status php-fpm

4、安裝MySQL

  1. 下載mysql的repo源

wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm

  1. 安裝mysql-community-release-el7-5.noarch.rpm包

sudo rpm -ivh mysql-community-release-el7-5.noarch.rpm

  1. 安裝MYSQL

sudo yum install -y mysql-server

  1. 更改MYSQL使用者許可權:

sudo chown -R root:root /var/lib/mysql

  1. 重啟服務:

sudo systemctl restart mysql

  1. 登入,並修改密碼:

mysql -u root

mysql > use mysql;

mysql > update user set password=password('password') where user='root';

mysql > flush privileges;

mysql > exit;

  1. 遠端連結

mysql -u root -p

mysql > use mysql;

mysql > grant all privileges on *.* to root@'%' identified by 'password' with grant option;

mysql >flush privileges

5、虛擬主機配置

拷貝一份預設配置。參考下面的server

cp nginx.conf /conf.d xxx.cong

server{
        listen 80;
        root /usr/share/nginx/html;
        index index.html index.php index.htm;

        # Make site accessible from http://localhost/
        server_name localhost;

        gzip on;
        gzip_min_length 1k;
        gzip_buffers 4 16k;
        #gzip_http_version 1.0;
        gzip_comp_level 5;
        gzip_types text/plain application/x-javascript text/css application/xml text/javascript application/x-httpd-php image/jpeg image/gif image/png;
        gzip_vary off;
        gzip_disable "MSIE [1-6]\.";


        charset UTF-8;

        location ~* .(jpg|jpeg|png|gif|css|js|swf|mp3|avi|flv|xml|zip|rar)$ {
                gzip on;
        }

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

        location ~ .php {
                fastcgi_pass 127.0.0.1:9000;
                fastcgi_index index.php;
                fastcgi_param SCRIPT_FILENAME  $document_root$fastcgi_script_name;
                fastcgi_split_path_info ^((?U).+.php)(/?.+)$;
                fastcgi_param PATH_INFO $fastcgi_path_info;
                fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
                include fastcgi_params;
        }
}
複製程式碼

重啟Ngix和php-fpm、配置完畢。

相關文章