Apache localhost 403 error using Yosemite

I just installed Mac OS X Yosemite. I configured Apache and chmodded "users / user / Sites" to 755. When I got to localhost, I got 403 Forbidden "You don't have permission to access / on this server" . The same thing happens with any other sites that I add to my hosts file.

I tried to configure user directories with this post . The guys from this MacRumors thread know that there is a problem with Apache, but they did not offer many suggestions.

My directory permissions are as follows

 drwxr-xr-x 29 root wheel 1054 Aug 11 07:30 / drwxr-xr-x 6 root admin 204 Aug 11 07:29 /Users/ drwxr-xr-x+ 26 zachshallbetter staff 884 Aug 11 11:57 /Users/zachshallbetter/ 0: group:everyone deny delete drwxr-xr-x 5 zachshallbetter staff 170 Aug 11 10:16 /Users/zachshallbetter/Sites 

Can anyone suggest any suggestions or help? Here are links to my hosts and httpd.conf and error logs for reference.

+46
Aug 11 '14 at 19:05
source share
7 answers

You DO NOT want to open your entire hard drive to the web server process. In fact, lines 215-217 of httpd.conf say:

 # Deny access to the entirety of your server filesystem. You must # explicitly permit access to web content directories in other # <Directory> blocks below. 

Apache 2.4 (OSX 10.10 Yosemite) has a different structure from Apache 2.2 (OSX 10.9) for the Directory Directive in the mod_authz_core module .

EDIT: If you are configuring Apache from START, follow this instruction to configure apache and php on OSX 10.10 Yosemite.

Assuming you have already included mod_userdir.so , your problem is in your custom .conf file ( /etc/apache2/users/username.conf ), edit (or add) the following.

Apache 2.2:

 <Directory "/Users/jnovack/Sites/"> Options Indexes MultiViews AllowOverride All # OSX 10.9 / Apache 2.2 Order from deny, allow </Directory> 

Apache 2.4

 <Directory "/Users/jnovack/Sites/"> Options Indexes MultiViews AllowOverride All # OSX 10.10 / Apache 2.4 Require all granted </Directory> 
+82
Oct 17 '14 at 15:01
source share

Edit the file: / private / etc / apache 2 / httpd.conf

on line 250 (in Yosemite):

 Options FollowSymLinks Multiviews 

at

 Options FollowSymLinks Multiviews Indexes 

then in terminal run:

 sudo apachectl restart 
+44
Oct 17 '14 at 11:41
source share

This may be a very late answer, but I followed most of the solutions, none of them helped me for various reasons. So I reset my device as the new Yosemite OS to get this local host running on Mac Yosemite (using Symlinks),

I took the steps for sure:

 sudo nano /etc/apache2/httpd.conf 

Uncomment the following lines:

 #LoadModule php5_module libexec/apache2/libphp5.so to LoadModule php5_module libexec/apache2/libphp5.so #LoadModule userdir_module libexec/apache2/mod_userdir.so to LoadModule userdir_module libexec/apache2/mod_userdir.so #Include /private/etc/apache2/extra/httpd-userdir.conf to Include /private/etc/apache2/extra/httpd-userdir.conf 

Save and exit (Ctrl + X press Enter and press Y and type again)

 sudo nano /etc/apache2/extra/httpd-userdir.conf 

and uncomment the following line on line 16:

 #Include /private/etc/apache2/users/*.conf to Include /private/etc/apache2/users/*.conf 

Save and exit (Ctrl + X press Enter and press Y and enter again).

Now go to the Apache Users folder to verify that your configuration file exists or not

 cd /etc/apache2/users/ 

if you do not have a configuration file in this folder, create it

 sudo nano /etc/apache2/users/<**YOUR USERNAME**>.conf 

Replace <YOUR USERNAME> name of your device (enter whoami in the terminal and enter this name).

after creating the .conf file, copy below line to this file

 <Directory "/Users/<YOUR USERNAME>/Sites/"> AddLanguage en .en LanguagePriority en fr de ForceLanguagePriority Fallback Options Indexes MultiViews AllowOverride None Order allow,deny Allow from localhost Require all granted </Directory> 

save and exit

Now restart apache

 sudo apachectl restart 

Now go to your browser and type localhost, it will work as expected,

As a note: if it does not work even after restarting the computer

create index.html as exactly index.html.en which you should find here:

 open /Library/Webserver/Documents/ 

right click on index.html.en and duplicate it in index.html, leaving the original as it is

try again in the browser and if you are successful you can delete the duplicate file

To be clear, leave the original index.html.en file where it is, untouched and unharmed throughout this step.

Not sure why I had to take this mysterious detour - maybe something local to my car, but if you have any problems after following the above guide, see if this helps.

SymLinks :

If you have success, you should see in the browser

 It works! 

Now create a symbolic link for any of your projects.

 ln -s <Path_to_your_Project(index_file)> <Path_to_webroot> 

For example, if you have a project folder in the Documents folder, then specify the website in the index file

 ln -s /Users/<YOUR USERNAME>/Documents/project/ /Library/Webserver/documents/projectlink 

you may need permission to create a symbolic link (use the command above with sudo)

Configure apache to track symbolic links (thanks tomvon, I don't have enough points to vote for you)

 sudo nano /private/etc/apache2/httpd.conf 

on line 250 (in Yosemite):

 Options FollowSymLinks Multiviews 

at

 Options FollowSymLinks Multiviews Indexes 

then in terminal run:

 sudo apachectl restart 

Now go to localhost/projectlink to see if your index file for your project is displayed in the browser.

Happy coding.

+29
Jan 31 '15 at
source share

The advice in this article helped me.

In particular, the Yosemite Only section:

First, there is a directive that helps protect your computer by denying access to the entire file system by default. Ill will show you how to remove this directive, since I find it easier on a machine designed for development. A section of code runs from line 220 to 223. You can comment (put a "# in front of each line") or simply delete this section.

And the section ...

 <Directory /> AllowOverride none Require all denied </Directory> 

Note:

As other details have shown, the method described above may be unsafe.

+8
Sep 27 '14 at 2:02
source share

There are two possibilities why your localhost denied, firstly, it can be because your apache parameter is incorrect, and secondly, maybe because you installed vhost , and you also forgot about the localhost set

  • sudo nano /etc/apache2/extra/httpd-vhosts.conf
  • Add this code

`

 <VirtualHost *:80> ServerName localhost DocumentRoot "/Users/username/Sites" <Directory "Users/username/Sites"> Options Indexes FollowSymLinks AllowOverride All Order allow,deny Allow from all </Directory> </VirtualHost> 
  • Save it and restart apache

`

 sudo apachectl restart 

it should be work :)

+2
Oct 06 '15 at 16:48
source share

Suggestions may focus on your own custom conf in apache, but by default this configuration may not load at all.

Change the userdir module configuration:

sudo vi / etc / apache2 / extra / httpd-userdir.conf

Uncomment the inclusion of user directory configuration files:

Include /private/etc/apache2/users/*.conf

Make sure you have the user directory configuration in accordance with our own username:

sudo vi / etc / apache2 / users / .conf

Make sure you have a good setup for your home directory:

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

Restart apache (web server)

sudo apachectl restart

Check your site!

0
Nov 24 '17 at 20:17
source share

Just create the Sites folder in the user folder. Go to

cd ~
mkdir 'Sites'

-3
Aug 03 '15 at 19:21
source share



All Articles