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


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


当前回答

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

其他回答

如果您无法找到http.conf并遵循Nick的方式。

使用sudo service apache2 Restart重启Apache。

我正在使用LAMP和更改文档根文件夹,我已经编辑了默认文件,这是在 /etc/apache2/sites-available文件夹。

如果你想做同样的事情,只需编辑如下:

DocumentRoot /home/username/new_root_folder
    <Directory />
        Options FollowSymLinks
        AllowOverride None
    </Directory>
    <Directory /home/username/new_root_folder>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride None
        Order allow,deny
        allow from all
    </Directory>

在此之后,如果您在浏览器中键入“localhost”,它将加载/home/username/new_root_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

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

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

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

这里→

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

如果你正在使用Linux Mint(个人观点,从所有的发行版来看,这个版本让我很开心),请遵循以下内容:

进入/etc/apache2/sites-available文件夹,编辑文件000-default.conf。 搜索DocumentRoot,例如DocumentRoot /var/www/html。您更改到您各自的目录; 打开终端,输入:sudo service apache2 restart

在Linux Mint中,您可以访问文件/etc/apache2/apache.conf。用您各自的路径替换/var/www,然后重新启动服务器(步骤3)。

就是这样。