Ubuntu CT安裝


  1. 先更新Proxmox。
  2. 下載最新範本(ubuntu-24.10_standard-1_amd64.tar.zst)
  3. 建立ubuntu CT,設定好登入密碼(root用)、網路。
  4. 啟動ubuntu CT,以主控台方式用root登入。
  5. 建立新使用者
    adduser 帳戶名稱
  6. 輸入完後,設定密碼
  7. 接著設定帳號的個人資料,可跳過,按“y“結束。
  8. 利用usermod來進行使用者模式的更動,能夠順利使用sudo -i
    usermod -aG sudo 帳戶名稱
  9. 使用sudo -i,取得root權限測試。
  10. 若要刪除帳戶,使用userdel
    $ userdel 要刪除的帳號(只刪除帳戶)
  11. $ userdel -r 要刪除的帳號(連同檔案一同刪除)
  12. 更新ubuntu裡,apt的套件資訊及列表
    apt update
  13. 更新已安裝的套件
    apt upgrade
  14. 確認網卡IP位址
    ip a
  15. 安裝SSH
    apt install openssh-server
  16. 設定SSH
    vim /etc/ssh/sshd_config
  17. 修改設定中三個參數,更改成下方內容。
    Port 22 -> SSH使用的Port,建議不要改
    PasswordAuthentication yes
    PermitRootLogin yes -> 是否開放 root 登入
  18. 登出,試試用其他帳號進行遠端連線
Apache安裝設定
  1. 安裝apache
    sudo apt install apache2 apache2-utils
  2. 安裝apache ssl
    sudo a2enmod ssl
  3. 重啟apache 2 服務
    sudo systemctl restart apache2
    此時已啟用port 443,可下指令 netstat -tlnp 檢查。
  4. 調整 SSL 網站設定檔
    sudo a2ensite default-ssl.conf
    sudo systemctl restart apache2
  5. 此時的SSL憑證(預設測試用)不是合法的,須自行申請合法憑證。
  6. apache2相關設定檔
    一般設定檔
    /etc/apache2/apache2.conf
    SSL設定檔
    /etc/apache2/sites-available/default-ssl.conf
MariaDB 安裝設定
  1. 先到官網下載頁面選擇您要安裝的作業系統、版本以及要安裝的 MariaDB 版本。因本次是安裝在 Ubuntu 24.10,所以選擇 Ubuntu 24.10 "oracular" > 11.8 > OSSPlanet + Ubuntu-TW - Ubuntu 台灣在地推廣組,然後按照畫面出現的指令安裝 apt 儲存庫。
  2. 安裝金鑰
    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'
  3. 加入儲存庫:使用 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
  4. 安裝MariaDB
    sudo apt-get update
    sudo apt-get install mariadb-server
  5. 啟動MariaDB
    sudo systemctl status mariadb
  6. 初始化MariaDB
    $ sudo mysql_secure_installation  
  7. 初始化 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。
  8. 允許外部連線
    (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
  9. 常用指令
    $ sudo systemctl enable mariadb         # 開機自動啟動服務
    $ sudo systemctl start mariadb            # 啟動服務
    $ sudo systemctl stop mariadb            # 停止服務
    $ sudo systemctl restart mariadb         # 重新啟動服務
    $ sudo systemctl status mariadb          # 查看服務狀態
  10. 詳細的帳號權限設定,可以參考以下文章:
    MySQL / MariaDB 資料庫使用者帳號管理 SQL 語法教學與範例
PHP安裝設定

  1. 安裝編譯工具
    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
  2. 下載php安裝
    $ sudo wget https://www.php.net/distributions/php-8.4.5.tar.gz
    $ sudo tar -zxvf php-8.4.5.tar.gz
  3. 進行編譯
    $ 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
  4. 開始安裝php
    $ sudo make && make install
  5. 查詢是否安裝成功
    $ sudo [安裝php的路徑]/bin/php --version
    $ sudo [安裝php的路徑]/bin/php -m
  6. 複製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
  7. 執行php
    $ sudo php8.4-fpm
  8. 若是出現下列錯誤訊息:
    ERROR: [pool www] cannot get gid for group 'nobody'
    ERROR: FPM initialization failed

    增加一個用戶群組並重新執行
    $ sudo groupadd nobody
    $ sudo php8.4-fpm

這個網誌中的熱門文章

公務雲出現「系統發生錯誤」或「系統單登中」或「空白畫面」

Raspberry - 安裝fcitx中文輸入引擎(含嘸蝦米、新酷音輸入法)

強制關機自動關閉程式