---
# System prepended metadata

title: Linux 系統管理 - HW06
tags: [Linux]

---

# Linux 系統管理 - HW06

##  A. 安裝 nginx
1. 下載 nginx
```
sudo apt install nginx
```
![](https://i.imgur.com/wUN5FNj.png)


2. 查看nginx的狀態
```
systemctl status nginx
```

![](https://i.imgur.com/iCkisrj.png)

3. 利用瀏覽器確認

![](https://i.imgur.com/rT0M4BI.png)

## B. 安裝php

1. 安裝PPA
```
sudo add-apt-repository ppa:ondrej/php
```
![](https://i.imgur.com/6UDPgwu.png)
![](https://i.imgur.com/vNP9xVI.png)

* 備註 : PPA 是 Personal Package Archive 的縮寫，軟體開發者將原始碼上傳至 Launchpad 後，透過其線上編譯服務，產生預先編譯好的套件，提供使用者使用。由於 PPA 是屬於非官方的套件庫，所以通常軟體版本比較新，但穩定性也較差。

2. 下載 php (php8.1)

![](https://i.imgur.com/sInDzSN.png)

3. 查看 php，恩，果然不行

![](https://i.imgur.com/Fhs88rp.png)

4. 下載 php-fpm

![](https://i.imgur.com/5ildal2.png)

5. 查看 php-fpm

![](https://i.imgur.com/ktTn36K.png)

## C. 安裝 MariaDB
1. 下載必要套件
```
sudo apt install wget software-properties-common dirmngr ca-certificates apt-transport-https
```
![](https://i.imgur.com/HtZGdY8.png)

2. 下載 MariaDB
```
sudo apt install mariadb-server mariadb-client
```
![](https://i.imgur.com/X1fA27x.png)

3. 查看是否正確安裝並確認是否啟動
```
mariadb --version
systemctl status mariadb
```
![](https://i.imgur.com/i7AsEYh.png)

4. 利用瀏覽器確認

![](https://i.imgur.com/CpsK1tz.png)

## D. 設定php與nginx之間的參數

1. 用nano打開
```
sudo nano /etc/nginx/sites-available/default
// 如果前項指令無法正常執行，請執行以下:
sudo nano /etc/nginx/sites-enabled/default
```
![](https://i.imgur.com/iOiEIKp.png)

2. 更改參數
```
server {
  # Example PHP Nginx FPM config file
  listen 80 default_server;
  listen [::]:80 default_server;
  root /var/www/html;

  # Add index.php to setup Nginx, PHP & PHP-FPM config
  index index.php index.html index.htm index.nginx-debian.html;

  server_name _;

  location / {
    try_files $uri $uri/ =404;
  }

  # pass PHP scripts on Nginx to FastCGI (PHP-FPM) server
  location ~ \.php$ {
    include snippets/fastcgi-php.conf;

    # Nginx php-fpm sock config:
    fastcgi_pass unix:/run/php/php8.1-fpm.sock;
    # Nginx php-cgi config :
    # Nginx PHP fastcgi_pass 127.0.0.1:9000;
  }

  # deny access to Apache .htaccess on Nginx with PHP, 
  # if Apache and Nginx document roots concur
  location ~ /\.ht {
    deny all;
  }
} # End of PHP FPM Nginx config example

```

3. 測試編輯是否有錯誤
```
sudo nginx -t

```
![](https://i.imgur.com/i8LAK18.png)

4. 建立 info.php

![](https://i.imgur.com/beLtbEY.png)

5. 重新啟動服務
```
sudo systemctl restart nginx

```
6. 用瀏覽器確認

![](https://i.imgur.com/TDmUo0H.png)


## reference
[How to Install and Set Up MariaDB on Ubuntu 22.04](https://www.makeuseof.com/install-set-up-mariadb-on-ubuntu/)

https://www.ibm.com/support/pages/disabling-http-port-80-security-network-ips-appliances

[網頁伺服器－CLI及phpinfo()](https://ithelp.ithome.com.tw/articles/10243646)

###### tags: `Linux`