如何修改Apache服务器的文档根目录?我基本上希望localhost来自/users/spencer/projects目录,而不是/var/www.
我终于弄明白了。有些人建议我更改httpd.conf文件,但我最终在/etc/apache2/sites-available/default中找到了一个文件,并将根目录从/var/www更改为/home/myusername/projects_folder,这是有效的。
如何修改Apache服务器的文档根目录?我基本上希望localhost来自/users/spencer/projects目录,而不是/var/www.
我终于弄明白了。有些人建议我更改httpd.conf文件,但我最终在/etc/apache2/sites-available/default中找到了一个文件,并将根目录从/var/www更改为/home/myusername/projects_folder,这是有效的。
当前回答
如果你正在使用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)。
就是这样。
其他回答
您需要更改httpd.conf文件中的DocumentRoot设置。它可能会在/etc/apache2/conf/httpd.conf下面。
使用你最喜欢的编辑器(我推荐Vim),寻找DocumentRoot并将其更改为/users/spencer/projects。再往下看一点,是这样的设置:
<Directory "/var/www">
您还需要将引号中的内容更改到新目录中。这使Apache能够在用户发出调用该目录的请求时从该目录读取数据。
现在重新启动Apache服务(httpd -k restart),您应该可以正常运行了。
Apache 2站点配置文件现在通常保存在/etc/apache2/sites-available/ (Debian, Ubuntu等)。
对于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。但据我所知,这并不是让一个通用开发环境运行所必需的。
redhat 7.0操作系统:/etc/httpd/conf/httpd.conf
如果您无法找到http.conf并遵循Nick的方式。
使用sudo service apache2 Restart重启Apache。
在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。