Change localhost directory for Yosemite Apache 2.4
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 MultiviewsAllowOverride None</Directory>
to:
DocumentRoot "<CUSTOM_PATH>"<Directory "<CUSTOM_PATH>">Options Indexes FollowSymLinks MultiviewsAllowOverride 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