在 Ubuntu 下使用 Apache2 修改网站根目录,通常按下面步骤操作即可。
Ubuntu 中 Apache2 的默认根目录是:
/var/www/html
sudo mkdir -p /home/wwwroot
sudo chown -R $USER:www-data /home/wwwroot
sudo chmod -R 755 /home/wwwroot
编辑默认站点配置文件:
sudo nano /etc/apache2/sites-available/000-default.conf
找到这一行:
DocumentRoot /var/www/html
改成你的新目录:
DocumentRoot /home/wwwroot
sudo nano /etc/apache2/apache2.conf
找到这一段(默认是 /var/www/):
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
改成你的新目录:
<Directory /home/wwwroot/>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
sudo apache2ctl configtest
sudo systemctl restart apache2
通常是:
如果是多站点,建议新建配置:
sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/mysite.conf
sudo a2ensite mysite.conf
sudo a2dissite 000-default.conf
sudo systemctl reload apache2
如果你是想 改成用户目录(~user) 或 用 Ubuntu + PHP,可以告诉我具体需求,我可以给你更精确的配置。