# HW9 ## 登入root,方便後續處理 `su`並輸入密碼 ## 安裝 Nginx ### 使用 yum 安裝 Nginx `yum install nginx` ### 啟動 Nginx 服務 `systemctl start nginx` ### 檢查 nginx 是否正常啟動 `systemctl status nginx` ![](https://i.imgur.com/iorNS0a.png) ### 永久開啟 Nginx 服務,讓重新開機後可以自動啟用 `systemctl enable nginx` ## 安裝 MariaDB ### 使用 yum 安裝 MariaDB `yum install mariadb-server mariadb` ### 啟動 MariaDB 服務,並設定開機自動啟動 `systemctl start mariadb` `systemctl enable mariadb` ### 強化 MySQL/MariaDB 資料庫設定的安全性 `mysql_secure_installation` 接著出現以下指令: `Set root password? [Y/n] Y` `New password: Enter your password here` `Re-enter new password: repeat your password` `Remove anonymous users? [Y/n] Y` `Disallow root login remotely? [Y/n] Y` `Remove test database and access to it? [Y/n] Y` `Reload privilege tables now? [Y/n] Y` 完成之後會看到以下字樣 ` ... Success!` `Cleaning up...` `All done! If you've completed all of the above steps, your MariaDB Installation should now be secure.` ## 安裝 PHP7 輸入`yum install php php-mysql` `systemctl restart httpd.service`使Apache再次啟動使之能與PHP作用 ### 更新PHP版本 參考 Remi's RPM repository https://rpms.remirepo.net/wizard/ 選擇目前CentOS版本、想要安裝的PHP版本、以及想要的安裝方式 ![](https://i.imgur.com/ylvvoE6.png) ## 設定 Nginx ### 先允許防火牆讓 HTTP、HTTPS 封包通過 `firewall-cmd --permanent --zone=public --add-service=http` `firewall-cmd --permanent --zone=public --add-service=https` `firewall-cmd --reload` ### 刷新 Nginx 讓設定套用 `systemctl restart nginx` ### 修改預設主站台設定檔 `nano /etc/nginx/conf.d/default.conf` 修改成以下內容 ![](https://i.imgur.com/i2HUrfk.png) 完成後按 ctrl + X,Y,並且 Enter ### 修改 Nginx 的主設定檔 `nano /etc/nginx/nginx.conf` 除了需要修改上方的數據之外,也需要新增下面的設定 ![](https://i.imgur.com/CuGYZHq.jpg) ### 刷新 Nginx 讓設定套用 `systemctl restart nginx` ### 查看伺服器網頁,若正常應該出現以下畫面 ![](https://i.imgur.com/M90N2hS.png) ## 設定 PHP-FPM 修改 PHP-FPM 的主設定檔 `nano /etc/php-fpm.d/www.conf` 配合 Nginx 修改下列設定值 user = nginx group = nginx listen.owner = nobody listen.group = nobody ![](https://i.imgur.com/X285grJ.jpg) ### 啟動 PHP-FPM,並讓它在開機後自動啟動 `systemctl start php-fpm` `systemctl enable php-fpm` ### 測試 `nano /usr/share/nginx/html/info.php` 新增 `<?php phpinfo(); ?>` ![](https://i.imgur.com/1lTPJ3c.png) 完成後按 ctrl + X,Y,並且 Enter 直接打開瀏覽器,在網址列除了輸入 IP 之外,再加上 php 檔案名稱,例如: http://10.2.200.184:8080/info.php 看到這個畫面就代表成功了。 ![](https://i.imgur.com/anngT5j.png)