Ubuntu CT安裝
- 先更新Proxmox。
- 下載最新範本(ubuntu-24.10_standard-1_amd64.tar.zst)
- 建立ubuntu CT,設定好登入密碼(root用)、網路。
- 啟動ubuntu CT,以主控台方式用root登入。
- 建立新使用者
adduser 帳戶名稱 - 輸入完後,設定密碼
- 接著設定帳號的個人資料,可跳過,按“y“結束。
- 利用usermod來進行使用者模式的更動,能夠順利使用sudo -i
$ usermod -aG sudo 帳戶名稱 - 使用sudo -i,取得root權限測試。
- 若要刪除帳戶,使用userdel
$ userdel 要刪除的帳號(只刪除帳戶) - 更新ubuntu裡,apt的套件資訊及列表
$ apt update - 更新已安裝的套件
$ apt upgrade - 確認網卡IP位址
$ ip a - 安裝SSH
$ apt install openssh-server - 設定SSH
$ vim /etc/ssh/sshd_config - 修改設定中三個參數,更改成下方內容。
Port 22 -> SSH使用的Port,建議不要改
PasswordAuthentication yes
PermitRootLogin yes -> 是否開放 root 登入 - 登出,試試用其他帳號進行遠端連線
$ userdel -r 要刪除的帳號(連同檔案一同刪除)
- 安裝apache
$ sudo apt install apache2 apache2-utils - 安裝apache ssl
$ sudo a2enmod ssl - 重啟apache 2 服務
$ sudo systemctl restart apache2
此時已啟用port 443,可下指令 netstat -tlnp 檢查。 - 調整 SSL 網站設定檔
$ sudo a2ensite default-ssl.conf
$ sudo systemctl restart apache2 - 此時的SSL憑證(預設測試用)不是合法的,須自行申請合法憑證。
- apache2相關設定檔
一般設定檔
/etc/apache2/apache2.conf
SSL設定檔
/etc/apache2/sites-available/default-ssl.conf
MariaDB 安裝設定
- 先到官網下載頁面選擇您要安裝的作業系統、版本以及要安裝的 MariaDB 版本。因本次是安裝在 Ubuntu 24.10,所以選擇 Ubuntu 24.10 "oracular" > 11.8 > OSSPlanet + Ubuntu-TW - Ubuntu 台灣在地推廣組,然後按照畫面出現的指令安裝 apt 儲存庫。
- 安裝金鑰
$ sudo apt-get install apt-transport-https curl
$ sudo mkdir -p /etc/apt/keyrings
$ sudo curl -o /etc/apt/keyrings/mariadb-keyring.pgp 'https://mariadb.org/mariadb_release_signing_key.pgp' - 加入儲存庫:使用 vim 編輯 /etc/apt/sources.list.d/mariadb.sources,
sudo vim /etc/apt/sources.list.d/mariadb.sources
並填寫以下內容。
# MariaDB 11.8 repository list - created 2025-04-07 02:22 UTC
# https://mariadb.org/download/
X-Repolib-Name: MariaDB
Types: deb
# deb.mariadb.org is a dynamic mirror if your preferred mirror goes offline. See https://mariadb.org/mirrorbits/ for details.
# URIs: https://deb.mariadb.org/11.rc/ubuntu
URIs: https://ftp.ubuntu-tw.org/mirror/mariadb/repo/11.8/ubuntu
Suites: oracular
Components: main main/debug
Signed-By: /etc/apt/keyrings/mariadb-keyring.pgp - 安裝MariaDB
$ sudo apt-get update
$ sudo apt-get install mariadb-server - 啟動MariaDB
$ sudo systemctl status mariadb - 初始化MariaDB
$ sudo mysql_secure_installation - 初始化 MariaDB 會需要回答幾個問題,如下:
(1)Enter current password for root (enter for none)
輸入 root 密碼,預設 MariaDB 沒有密碼,可直接按 enter。
(2)Switch to unix_socket authentication [Y/n]
切換到 unix_socket 身份驗證,這是在 10.4.3 版新增的身份驗證方式,沒有強制使用,輸入 n。
(3)Change the root password? [Y/n]
修改資料庫 root 帳號密碼,輸入 y。
(4)New password
輸入要設定的 root 帳號密碼。
(5)Re-enter new password
再輸入一次輸入要設定的 root 帳號密碼。
(6)Remove anonymous users? [Y/n]
移除匿名帳號,輸入 y。
(7)Disallow root login remotely? [Y/n]
不允許遠端使用 root 帳號登入,考量安全性應該要輸入 y。
(8)Remove test database and access to it? [Y/n]
移除測試資料庫與帳號,輸入 y。
(9)Reload privilege tables now? [Y/n]
重新載入權限設定,輸入 y。 - 允許外部連線
(1)編輯 MariaDB 設定檔
編輯 /etc/mysql/mariadb.conf.d/50-server.cnf,找到 bind-address = 127.0.0.1 這一行,在這行前加入 # 註解掉。 修改後,重啟 MariaDB 服務 (sudo systemctl restart mariadb)。
(2)新增資料庫權限
假設外部電腦 IP 為 192.168.0.1,並且設定帳號為 root,密碼為 123456,可以管理全部資料庫,請參考以下指令進行設定。
GRANT ALL PRIVILEGES ON *.* TO 'root'@'192.168.0.1' IDENTIFIED BY '123456' WITH GRANT OPTION;
FLUSH PRIVILEGES;
(3)開啟 3306 Port
sudo ufw allow 3306 - 常用指令
$ sudo systemctl enable mariadb # 開機自動啟動服務
$ sudo systemctl start mariadb # 啟動服務
$ sudo systemctl stop mariadb # 停止服務
$ sudo systemctl restart mariadb # 重新啟動服務
$ sudo systemctl status mariadb # 查看服務狀態 - 詳細的帳號權限設定,可以參考以下文章:
MySQL / MariaDB 資料庫使用者帳號管理 SQL 語法教學與範例
- 安裝編譯工具
$ sudo apt install gcc make openssl curl libssl-dev libxml2-dev libzip-dev libcurl4-openssl-dev libpng-dev libjpeg-dev libwebp-dev libonig-dev libsqlite3-dev libsodium-dev libargon2-dev - 下載php安裝
$ sudo wget https://www.php.net/distributions/php-8.4.5.tar.gz
$ sudo tar -zxvf php-8.4.5.tar.gz - 進行編譯
$ sudo ./configure --prefix=[安裝php的路徑] --with-config-file-path=[安裝php的路徑] --with-config-file-scan-dir=/usr/local/php8.4/etc/php.d --enable-fpm --enable-fileinfo --enable-safe-mode --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --with-curlwrappers --enable-mbregex --enable-mbstring --enable-ftp --with-gd --enable-gd-native-ttf --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --with-pear --with-gettext --enable-calendar --with-openssl --with-mcrypt --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd - 開始安裝php
$ sudo make && make install - 查詢是否安裝成功
$ sudo [安裝php的路徑]/bin/php --version
$ sudo [安裝php的路徑]/bin/php -m - 複製php.ini到PHP目錄中,並正確配置php-fpm
$ sudo cp php.ini-development [安裝php的路徑]/lib/php.ini
$ sudo cp [安裝php的路徑]/etc/php-fpm.d/www.conf.default [安裝php的路徑]/etc/php-fpm.d/www.conf
$ sudo cp [安裝php的路徑]/etc/php-fpm.conf.default [安裝php的路徑]/etc/php-fpm.conf - 執行php
$ sudo php8.4-fpm - 若是出現下列錯誤訊息:
ERROR: [pool www] cannot get gid for group 'nobody'
ERROR: FPM initialization failed
增加一個用戶群組並重新執行
$ sudo groupadd nobody
$ sudo php8.4-fpm