---
# System prepended metadata

title: HW06

---

# HW06
一、更新apt 
---
```$ sudo apt update```
```$ sudo apt upgrade```

二、裝NGINX
---
```$ sudo apt install nginx```
```$ sudo ufw app list```
```$ sudo ufw allow 'Nginx HTTP'```
```$ sudo apt install mysql-server```
```$ sudo mysql```
```$ exit```

三、PHP
---
```$ sudo apt install php8.1-fpm php-mysql```
```$ sudo systemctl start php8.1-fpm```
```$ sudo systemctl enable php8.1-fpm```
```$ systemctl status php8.1-fpm```
```$ sudo rm /etc/nginx/sites-enabled/default```
```$ sudo nano /etc/nginx/conf.d/default.conf```

存入:
server {
  listen 80;
  listen [::]:80;
  server_name _;
  root /usr/share/nginx/html/;
  index index.php index.html index.htm index.nginx-debian.html;

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

  location ~ \.php$ {
    fastcgi_pass unix:/run/php/php8.1-fpm.sock;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include fastcgi_params;
    include snippets/fastcgi-php.conf;
  }

 #A long browser cache lifetime can speed up repeat visits to your page
  location ~* \.(jpg|jpeg|gif|png|webp|svg|woff|woff2|ttf|css|js|ico|xml)$ {
       access_log        off;
       log_not_found     off;
       expires           360d;
  }

  #disable access to hidden files
  location ~ /\.ht {
      access_log off;
      log_not_found off;
      deny all;
  }
}

四、測試
---
```$sudo nginx -t```
```$ sudo systemctl reload nginx```
```$ sudo nano /usr/share/nginx/html/info.php```

存入: <?php phpinfo(); ?> 

五、MariaDB
---
**1.安裝MariaDB**
    ```$ sudo apt install mariadb-server mariadb-client```
**2.檢查MariaDB是否Active**
    ```$ systemctl status mariadb```
**3.運行安裝後的安全腳本**
    ```$ sudo mysql_secure_installation```
    尚未設置root密碼按enter即可
    其餘問題可以都回答yes
    有特殊需求可以彈性調整
**4.登入MySQL即可查看MariaDB服務器版本**
    ```$ sudo mysql -p -u root```
    ![](https://i.imgur.com/kwrXFFI.png)
    
六、成果
---

![](https://i.imgur.com/2lrK1YV.png)
![](https://i.imgur.com/K7TEvf3.png)
![](https://i.imgur.com/izYBuGX.png)
