Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change localhost directory for Yosemite Apache 2.4

I have clean installed Mac OSX Yosemite but I cant configure the Apache 2.4 like I have always done on older OSX versions.

Here is what I want to do : set the "localhost" directory to "/Users/username/Public/". But, everything I tried won't work, I always get a "Forbiden, can't access to /" or I get the default "It works!" page...

How to simply reroot my localhost ?

Thx

EDIT (thanks to Krister Andersson for the answer)

For Mac OSX 10.10 Yosemite

I also post the changes I had to do to keep things running.

In "/etc/apache2/users/", I created a file named by my username like this "myUsername.conf".

You can get your username by typing "id" in terminal. You should find your username at start in "uid=501(myUsername)".

In this new "myUsername.conf" file, just copy past this:

<Directory "/Users/myUsername/Sites/">     AllowOverride All     Options Indexes MultiViews     Options +FollowSymLinks     Require all granted </Directory> 

Dont forgive to change the myUsername value.

Then, in the "/etc/apache2/httpd.conf" file, uncomment all these two lines:

167 #LoadModule userdir_module libexec/apache2/mod_userdir.so 169 #LoadModule php5_module libexec/apache2/libphp5.so 

Line 236, change the directory of "DocumentRoot" to whatever you want. Line 250, set "Options" to "Options "Options Indexes FollowSymLinks Multiviews". Line 258, set "AllowOverride None" to "AllowOverride All". Line 263, set "Require all denied" to "Require all granted"

In Terminal, restart apache by typing "sudo apachectl restart".

It work's for me on Mac OS X 10.10 Yosemite clean install.

like image 994
Jordan Avatar asked Oct 21 '14 12:10

Jordan


People also ask

How do I add Apache to the root directory?

Make sure you have at least o+r permissions on the directory. As root, run chmod ugo+r /home/pc/www/public/ and restart Apache, and see if that solves your problem. Run an ls -al /home/pc/www/public and then add the out put to your question. Also add the user and group apache is running under. Solution from OP.

Does the Apache user(usually Apache) have permissions to that directory?

Does the Apache user (usually apache or nobody) have permissions to that directory? Make sure you have at least o+r permissions on the directory. As root, run chmod ugo+r /home/pc/www/public/ and restart Apache, and see if that solves your problem. Run an ls -al /home/pc/www/public and then add the out put to your question.

What is Apache Apache2 Mount location?

Apache2 web server installed on the machine A new mount location or the new folder location for moving the Site information or files. As we already have knowledge that, the default location of the Apache web server is /var/www/html, or if you have a different setup with multiple sites with multiple document roots for different sites.

What is the default location of the Apache web server?

As we already have knowledge that, the default location of the Apache web server is /var/www/html, or if you have a different setup with multiple sites with multiple document roots for different sites.


2 Answers

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 [email protected]    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 
like image 85
Cyclonecode Avatar answered Sep 29 '22 03:09

Cyclonecode


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

like image 38
Dima Murdock Avatar answered Sep 29 '22 04:09

Dima Murdock