---
# System prepended metadata

title: HW09

---

# HW09
### 安裝 Nginx
1.使用 yum 安裝 Nginx 伺服器：sudo yum install nginx
2.啟動 Nginx 服務：sudo systemctl start nginx
3.檢查 Nginx 是否正常啟動：sudo systemctl status nginx
4.永久啟用 Nginx 服務，讓重新開機後可自動啟動：sudo systemctl enable nginx

### 設定 Nginx 與 PHP 7
1.輸入指令:vi /etc/nginx/nginx.conf (For CentOS or RHEL)
2.將port改成8080
3.在Server{ }裡面加入location ~* \.php$ {
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_index index.php;
        fastcgi_split_path_info ^(.+\.php)(.*)$;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root 
        $fastcgi_script_name;
        } (目的:設定要將 .php 檔案直接交由 FPM 來處理)
        
### 更改web port為8080(所需輸入指令)
1.systemctl restart nginx
2.netstat -tlpn| grep nginx
3.ss -tlpn| grep nginx
4.yum install policycoreutils
5.semanage port -a -t http_port_t -p tcp 8080
6.semanage port -m -t http_port_t -p tcp 8080
7.systemctl restart nginx.service
8.netstat -tlpn| grep nginx
9.s -tlpn| grep nginx

### 下載與啟動PHP-FPM
1.yum install php-fpm
2.啟動:sudo service php-fpm restart


### 建立php測試檔
1.檔名info.php
2.內容:
       <?php
       phpinfo();
       ?>

### 重新啟動Nginx
1.sudo service nginx restart

### 輸入網址
1.10.2.200.210:8080/info.php
2.結果畫面:![](https://i.imgur.com/PYhejlb.jpg)
![](https://i.imgur.com/Apo4Mkg.jpg)




