前言
这两天使用Apache2作为网站服务器,开发应用的时候需要使用/home/mydir/html作为工作目录,因为使用/var/www的话需要root权限,很不方便。但是问题来了,网上很多教程都说需要修改http.conf,而deepin下的apache2没有httpd.conf。以下是我解决问题的过程。
参照网上教程,修改根目录
sudo nano /etc/apache2/sites-available/000-default.conf
将
DocumentRoot /var/www/
修改为想要的目录比如:
DocumentRoot /var/www/html/mainpage
重启apache2服务器
sudo service apache2 restart
完成后访问127.0.0.1会出现404 Forbiden错误,但是访问localhost能够出现apache2的欢迎页,于是我在欢迎页上找到了如下一段话
If your site is using a web document root located elsewhere (such as in /srv) you may need to whitelist your document root directory in /etc/apache2/apache2.conf.
也就是说如果使用非根目录的话,需要更改apache2.conf
于是修改权限
sudo nano /etc/apache2/apache2.conf
添加如下一段
<Directory /home/yourdir> Options Indexes FollowSymLinks AllowOverride None Require all granted </Directory>
然后重启
sudo service apache2 restart