Change localhost directory for Yosemite Apache 2.4

余生颓废 提交于 2019-12-02 16:45:36

I've just installed Yosemite and I managed to change the DocumentRoot without any problems. First I modified the following lines in /private/etc/apache2/httpd.conf:

DocumentRoot "/Library/WebServer/Documents"
<Directory "/Library/WebServer/Documents">
Options FollowSymLinks Multiviews

AllowOverride None
</Directory>

to:

DocumentRoot "<CUSTOM_PATH>"
<Directory "<CUSTOM_PATH>">
Options Indexes FollowSymLinks Multiviews

AllowOverride All
</Directory>

The above will set a custom DocumentRoot, enable directory listing and allow configurations to be overridden by .htaccess files.

Then I restarted apache by executing sudo apachectl restart.

Another approach would be to set up a virtual host. First make sure so that the following line is uncommented in your /private/etc/apache2/httpd.conf file:

# Virtual hosts
#Include /private/etc/apache2/extra/httpd-vhosts.conf

Then you can add the following in the httpd-vhosts.conf file:

<VirtualHost *:80>
   ServerAdmin webmaster@example.local
   DocumentRoot "/Library/WebServer/Documents"
   ServerName example.local
   ErrorLog "/private/var/log/apache2/example.local-error_log"
   CustomLog "/private/var/log/apache2/example.local-access_log" common

   <Directory "/Library/WebServer/Documents">
     Options Indexes FollowSymLinks Multiviews
     AllowOverride All
     Order allow,deny
     Allow from all
   </Directory>
</VirtualHost>

The above will setup a document root for a new virtual host named example.local and enable directory listing and allow configurations to be overridden by .htaccess files. Of course your also will need to restart apache for the changes to take effect:

sudo apachectl restart

On El Capitan you should restart apache with "-k" flag: sudo apachectl -k restart

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!