1. 安裝及啟動nginx 輸入yum install nginx命令進行nginx的安裝,當需要確認時輸入”y“確認。 yum install nginx

安裝完成后,輸入service nginx start啟動nginx服務。 service nginx start

輸入wget http://127.0.0.1測試nginx服務。 wget http://127.0.0.1

2. 安裝PHP及相應組件 輸入yum install php php-fpm命令進行PHP的安裝,當需要確認時輸入”y“確認。 yum install php php-fpm 
輸入service php-fpm start啟動php-fpm服務,並使用命令cat /etc/php-fpm.d/www.conf |grep -i 'listen ='查看php-fpm配置。 service php-fpm start
cat /etc/php-fpm.d/www.conf |grep -i 'listen ='

上圖可見php-fpm的默認配置的監聽端口為9000,現在需要修改配置將php解析的請求轉發到127.0.0.0:9000處理即可。 使用命令nginx -t查找nginx配置文件,並使用vi命令修改該配置文件: nginx -t vi /etc/nginx/nginx.conf 
在配置文件中找到以下片段,修改紅色部分。(按任意鍵(或者i鍵)行文本編輯,以“#”開頭的為注釋行。編輯完成后,按Esc鍵,在輸入:wq,保存並退出)
server { listen 80; root /usr/share/nginx/html; server_name localhost; #charset koi8-r;
#access_log /var/log/nginx/log/host.access.log main;
location / { index index.html index.htm; } #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; } # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
# location ~ .php$ { fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } } 修改后保存,輸入service nginx restart重啟nginx服務。 service nginx restart
在web目錄下創建index.php: vi /usr/share/nginx/html/index.php 用vi命令進行編輯,寫入以下信息: Hello World
在瀏覽器中,訪問服務器公網IP+php網頁名稱查看環境配置是否成功,如果頁面可以顯示“hello world”,說明配置成功

注意:剛買的阿里雲服務器要配置安全組,不然公網在瀏覽器中打不開

