############################################################

搭建 Ubuntu + Apache2 + MariaDB + PHP 8.1 的指南。


步驟 1:準備環境

  1. 檢查 Ubuntu 版本

    確保 Ubuntu 系統是最新版本,執行以下命令:

    lsb_release -a
    sudo apt update && sudo apt upgrade -y
    
    
  2. 安裝必要工具

    確保系統上有 wgetcurl 等常用工具:

    sudo apt install wget curl unzip -y
    
    

步驟 2:安裝 Apache2

  1. 安裝 Apache2:

    sudo apt install apache2 -y
    
    
  2. 啟用和檢查 Apache2:

    sudo systemctl start apache2
    sudo systemctl enable apache2
    sudo systemctl status apache2
    
    

    確保 Apache2 正常運行,並可通過瀏覽器訪問伺服器的 IP 地址(例如:http://伺服器IP)。-l29dvgl92bgl3a43z./)

  3. 調整防火牆規則,允許 HTTP 和 HTTPS 流量:

    sudo ufw allow 'Apache Full'
    
    

步驟 3:安裝 MariaDB

  1. 安裝 MariaDB:

    sudo apt install mariadb-server -y
    
    
  2. 啟動並設置 MariaDB:

    sudo systemctl start mariadb
    sudo systemctl enable mariadb
    
    
  3. 執行安全設置向導,強化 MariaDB 安全性:

    sudo mysql_secure_installation
    
    

    根據提示完成設置,建議:

  4. 驗證 MariaDB 是否正常運行:

    sudo systemctl status mariadb
    
    

步驟 4:安裝 PHP 8.1

  1. 添加 PHP 8.1 的 PPA(Personal Package Archive):

    sudo add-apt-repository ppa:ondrej/php
    sudo apt update