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


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


当前回答

在Apache 2.4.18 (Ubuntu)版本中。

2.打开“/etc/apache2/apache2.conf”文件 搜索<Directory /var/www/>并替换到您的目录。 打开文件/etc/apache2/sites-available/000-default.conf,搜索DocumentRoot /var/www/html,将其替换为DocumentRoot。

其他回答

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

如果您无法找到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)及其后续版本。在进行任何更改之前,请确保备份以下文件。

Open /etc/apache2/apache2.conf and search for <Directory /var/www/> directive and replace path with /home/<USERNAME>/public_html. You can use * instead of . Open /etc/apache2/sites-available/000-default.conf and change the DocumentRoot value property from /var/www/html to /home/<USERNAME>/public_html. Also <Directory /var/www/html> to <Directory /home/<USERNAME>/public_html. Open /etc/mods-available/php7.1.conf. Find and comment the following code php_admin_flag engine Off

不要打开php_admin_flag引擎OFF标志,原因在指令代码上面的注释中提到了。此外,PHP版本可以是5.0、7.0或任何您已经安装的版本。

在home/<USERNAME>中创建public_html目录。

执行sudo service apache2 Restart命令重新启动Apache服务。

在服务器上运行示例脚本进行测试。

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