Ubuntu LAMP多站點管理主要通過配置Apache虛擬主機實現,以下是具體步驟及方法:
安裝LAMP環境
sudo apt update && sudo apt upgrade -ysudo apt install apache2 mariadb-server php libapache2-mod-php php-mysqlsudo systemctl start apache2 && sudo systemctl enable apache2配置虛擬主機(基于域名)
cd /etc/apache2/sites-available/000-default.conf)為站點配置文件(如site1.conf):sudo cp 000-default.conf site1.conf<VirtualHost *:80>
ServerName example.com # 站點域名
ServerAlias www.example.com # 別名(可選)
DocumentRoot /var/www/site1 # 站點根目錄
<Directory /var/www/site1>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/site1-error.log
CustomLog ${APACHE_LOG_DIR}/site1-access.log combined
</VirtualHost>
site2.conf)。啟用站點并重啟Apache
sudo a2ensite site1.conf site2.confsudo systemctl reload apache2域名解析
/etc/hosts文件,添加域名映射(如127.0.0.1 example.com)。多站點管理技巧
sudo chmod -R 755 /var/www/site1)。/var/log/apache2/目錄下的日志文件監控站點訪問和錯誤。Let's Encrypt為站點配置HTTPS(需安裝certbot工具)。參考來源: