如何修改Apache服务器的文档根目录?我基本上希望localhost来自/users/spencer/projects目录,而不是/var/www.


我终于弄明白了。有些人建议我更改httpd.conf文件,但我最终在/etc/apache2/sites-available/default中找到了一个文件,并将根目录从/var/www更改为/home/myusername/projects_folder,这是有效的。


当前回答

这是Ubuntu 14.04 (Trusty Tahr):

在/etc/apache2/apache2.conf文件中,它应该如下所示,不包含目录名:

<Directory /home/username>
    Options Indexes FollowSymLinks
    AllowOverride All
    Require all granted
</Directory>

在/etc/apache2/sites-available/000-default.conf文件中,你应该包括自定义目录名,即www:

DocumentRoot /home/username/www

如果不是如上所述,它会在加载服务器时给你一个错误:

禁止您没有访问此服务器的权限

其他回答

我必须编辑/etc/apache2/sites-available/default。线条和RDL提到的一样。

redhat 7.0操作系统:/etc/httpd/conf/httpd.conf

对于Linux Mint 17.3 Cinnamon 64位的Apache 2,以下工作:

In /etc/apache2/sites-available/ open the 000-default.conf file, and change the Document Root to the absolute path of your directory. sudo vim /etc/apache2/sites-available/000-default.conf In folder /etc/apache2/ open file httpd.conf, and add a <Directory> tag referencing your directory and containing the exact same settings as the tag for var/www. sudo vim /etc/apache2/apache2.conf On my machine it looked like this: <Directory /home/my_user_name/php/> Options Indexes FollowSymLinks AllowOverride All Require all granted </Directory>

注意:在第一步中,为了SSL的目的,您可能想要更改default-ssl.conf文件中的Document Root。但据我所知,这并不是让一个通用开发环境运行所必需的。

请注意,这只适用于Ubuntu 14.04 LTS (Trusty Tahr)和更新的版本。

在我的Ubuntu 14.04 LTS中,文档根目录被设置为/var/www/html。它在以下文件中配置:

/etc/apache2/sites-available/000-default.conf

所以只要做一个

sudo nano /etc/apache2/sites-available/000-default.conf

然后把下面这行改为你想要的:

DocumentRoot /var/www/html

也做一个

sudo nano /etc/apache2/apache2.conf

找到这个:

<Directory /var/www/html/>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>

并将/var/www/html更改为您的首选目录并保存。

保存更改后,只需重新启动Apache 2 web服务器,就可以完成了:)

sudo service apache2 restart

如果您更喜欢图形文本编辑器,可以用gksu gedit替换sudo nano。

如果你使用的是Ubuntu 16.04 (Xenial Xerus),请更新/etc/apache2/sites-available目录下的000-default.conf文件。

这里→

服务器webmaster@localhost DocumentRoot /var/www/html/YourFolder