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

一、準備

  1. 更新

sudo yum updatejavascript

  1. 安裝 wget

sudo yum install wgetphp

二、安裝Nginx

阿里雲默認使用了本身的鏡像源。
不是阿里雲鬚要下載對應當前系統版本的nginx包
創建nginx的yum倉庫(默認yum是沒有nginx的)
複製代碼

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

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

開始安裝Nginxjava

sudo yum install -y nginxmysql

Nginx啓動nginx

sudo systemctl start nginxweb

三、安裝php

  1. rpm 安裝 Php7 相應的 yum源

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

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

  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

四、安裝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

五、虛擬主機配置

拷貝一份默認配置。參考下面的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、配置完畢。

相關文章
相關標籤/搜索