Apache localhost 403 error with Yosemite
Asked Answered
S

7

47

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

I tried configuring user directories following help from this post. The guys on this MacRumors thread know there is an Apache issue, but didn't offer a lot of suggestions.

My directory permissions look like this

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 offer any suggestions or help? Here are links to my hosts and httpd.conf files and error logs for reference.

Shiner answered 11/8, 2014 at 19:5 Comment(2)
Unless you just have a few web scripts, you should look into configuring Apache Virtual Hosts on Mac OS X instead of enabling user directories.Yod
Two things: 1) The update resets the httpd.conf, so you'll need to re-include the vhost conf and re-enable the needed modules, as mahi outlines below. 2) Inside the "Directory" section of each vhost definition, add "Require all granted". This replaces the older "Order from deny, allow" directives. (It doesn't seem to hurt anything to leave them in place, just make sure to add the new one also.)Autoionization
Y
80

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

# Deny access to the entirety of your server's 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 Module mod_authz_core.

EDIT: If you are setting up Apache from the START, please follow this instruction set to setup apache and php on OSX 10.10 Yosemite.

Assuming you have mod_userdir.so enabled already, your problem is within your user .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>
Yea answered 17/10, 2014 at 15:1 Comment(6)
Thanks for adding this to the discussion. I edited my answer to suggest people continue reading through other answers for security details.Wadley
This didn't have any apparent effect for me. Can mod_userdir.so be disabled? (Mine originally was) Is the username.conf supposed to be for my Mac user or the Apache user?Blowzed
Yes, mod_userdir.so is disabled by default. Please follow the entire instruction set posted in my third paragraph to set it up from the start. This answer only addresses the changes between 2.2 and 2.4 within mod_userdir.so.Yea
Thank you. I added Require all granted to all my vhost from httpd.conf and works like charm.Croce
This seems not work for me. Just found a more comprehensive instruction on apple official website: discussions.apple.com/docs/DOC-3083Glamorize
Oh my god, I could kiss you. It's the Require all granted that was the doozy. God damn it this is why I hate upgrading MacsWeevily
G
45

Edit the file: /private/etc/apache2/httpd.conf

on line 250 (in Yosemite) change:

Options FollowSymLinks Multiviews

to:

Options FollowSymLinks Multiviews Indexes

then in the Terminal run:

sudo apachectl restart
Genethlialogy answered 17/10, 2014 at 11:41 Comment(1)
If your documents is empty, you need to add "Indexes" to show the list of files and folders.Meridethmeridian
F
29

This might be very late answer but i did followed most of Stack Overflow solutions, None of them helped me for various reasons. So i did reset my device as a fresh Yosemite OS to get this localhost working on Mac Yosemite (with Symlinks too),

Steps I did exactly :

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 enter again)

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

and uncomment the following line at 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 apache Users folder to check your configuration file exist or not

cd /etc/apache2/users/

if you do not have configuration file in this folder, create one by

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

Replace <YOUR USERNAME> with the name of your machine (type whoami in terminal and enter that name).

after creating .conf file , copy below lines into that 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 your apache

sudo apachectl restart

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

Just as a Note: if it does not work even after try restarting your computer

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

open /Library/Webserver/Documents/

right click on index.html.en and duplicate it to index.html leaving original as it is

try again in browser and if you have success, you can delete the duplicated file

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

Not sure why I had to take this mysterious detour - probably something local to my machine, but if you're having trouble after following the guide above, see if it helps.

SymLinks :

if you have success, in Browser you should see

It works!

Now create symlink to any your project.

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

For example if you have project folder in your Documents folder ,then point webroot to your index file by

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

you might need permission to create symlink (Use above command with Sudo)

Configure apache to follow symlinks ( Thanks to tomvon, i do not enough points to vote you)

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

on line 250 (in Yosemite) change:

Options FollowSymLinks Multiviews

to:

Options FollowSymLinks Multiviews Indexes

then in the Terminal run:

sudo apachectl restart

Now go to localhost/projectlink to see if your project index file shows here on browser.

Happy Coding..

Fernandes answered 31/1, 2015 at 22:10 Comment(3)
Works perfectly. Similar instructions in this article which also lists out differences in steps for older versions of OSX (prior to Yosemite) - techzog.com/tips/mac-osx/set-web-server-mac-osxSlunk
Thank you! it worked fine on Mac OS Sierra. In my case, I was missing the line: #Include /private/etc/apache2/extra/httpd-userdir.conf to Include /private/etc/apache2/extra/httpd-userdir.confWhiffen
Worked for me on Sierra too. Added Include /private/etc/apache2/users/*.conf to httpd-userdir.conf and all came good. Thanks/Aney
W
8

The advice in this article helped me.

Specifically the "Yosemite Only" section:

First, there is a directive that helps secure your machine by denying access to the entire file system by default. I’ll show you how to remove this directive, since I find that easier on a machine meant for development. The section of code runs from line 220 through 223. You can comment out (place ‘#’ in front of each line) or just remove this section.

And the section is ...

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

Note:

As others have followed up on this with more details, the method outlined above can be insecure.

Wadley answered 27/9, 2014 at 2:2 Comment(1)
The entire directory structure is locked down for a reason. See @jnovack's answer below for a better solution. Short version: The Allow/Deny syntax changed in Apache 2.4, so the old statements in previous con files are ignored.Pluvious
L
2

There are 2 possibility why your localhost is forbidden, first it may be because your apache setting is not correct and second, may be because you set vhost and you forget about set localhost too

  1. sudo nano /etc/apache2/extra/httpd-vhosts.conf
  2. 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>  
  1. Save it and restart your apache

`

sudo apachectl restart

it should be works :)

Larkin answered 6/10, 2015 at 16:48 Comment(0)
R
0

Suggestions might focus on your own user specific conf in apache but by default this configuration might not be loaded at all.

Edit the userdir module configuration:

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

Uncomment the include of the user directory configuration files:

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

Make sure you have a user directory configuration according our own username:

sudo vi /etc/apache2/users/.conf

Make sure you have good configuration for your home directory:

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

Restart apache (webserver)

sudo apachectl restart

Check your site!

Revenant answered 24/11, 2017 at 20:17 Comment(0)
G
-2

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

cd ~
mkdir 'Sites'

Garibay answered 3/8, 2015 at 19:21 Comment(1)
As you can see in the original post, the Sites directory already exists.Palaeography

© 2022 - 2024 — McMap. All rights reserved.