9

I have followed this guide to set-up Apache on High Sierra: https://coolestguidesontheplanet.com/get-apache-mysql-php-and-phpmyadmin-working-on-macos-sierra/

I used it to set it up on Sierra.

But when I go to http://localhost/~scott/ I get "Forbidden. You don't have permission to access /~scott/ on this server."

A suggestion on this similar question: localhost / userdir on macOS High Sierra is to load vhosts. Which I've tried, but still get "Forbidden".

Has anything changed between Sierra and High Sierra which would be preventing Apache from working with user Sites folders?

5

15 Answers 15

8

This worked for me when I ran into the same problem.

Please check "/private/etc/apache2/extra/httpd-userdir.conf" file.

change

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

to

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

and restart apache.

From: https://stackoverflow.com/questions/39631351/apache-localhost-403-forbidden-with-macos-sierra

4
  • That line in /private/etc/apache2/extra/httpd-userdir.conf is already uncommented, from the instruction link I followed. Commented Sep 28, 2017 at 19:08
  • did you restart apache "sudo apachectl restart"
    – Robert
    Commented Sep 29, 2017 at 18:38
  • Yes. I have done with all changes to Apache's configuration files Commented Oct 2, 2017 at 21:03
  • Yeah, can confirm this doesn't work, even with restarting apache. Commented Aug 16, 2021 at 17:08
4

To allow access to the Sites directory, you have to add the following to /etc/apache2/httpd.conf:

<DirectoryMatch "/Users/.*/Sites">
  Require all granted
</DirectoryMatch>

The default Apache configuration is set to denied on /, so you have to explicitly allow access to everything.

2
  • 2
    Added and restarted apache. Didn't make any difference Commented Nov 7, 2017 at 20:07
  • I had the same problem. Was getting the "It works!" on locahost, but could not get the user directories to work. Fixing the DirectoryMatch rule like this solved it. Thanks!
    – Karra
    Commented Apr 22, 2019 at 0:05
4

Just to expand on to Diogo Lima's answer.

With the upgrade to High Sierra, Apple made copies of your previous apache settings and appended a ~previous to the *.conf files both in the /etc/apache2 and the /etc/apache2/extra folders. If you are using virtual hosts or ssl-virtual hosts then you will need to also move your previous versions for those .conf files as well.

mv /etc/apache2/extra/httpd-vhosts.conf~previous /etc/apache2/extra/httpd-vhosts.conf
mv /etc/apache2/extra/httpd-ssl.conf~previous /etc/apache2/extra/httpd-ssl.conf
5
  • 1
    This was a clean install of High Sierra, so I didn't have any previous configuration files Commented Nov 11, 2017 at 10:08
  • So, just to clarify, you had it working on Sierra, but didn't do an upgrade, but rather a complete clean install? I recall when I set up getting it working on Sierra that I created a symbolic link from my Sites folder to the /Library/WebServer/Documents folder and made sure I had granted myself permission (read and write). Since it sounds merely to be a permissions issue at this stage, have you made the symbolic link and changed permissions? Commented Nov 13, 2017 at 3:03
  • Yes, that's correct. I always do a clean install of new macOS versions. I'm aware I can do that, but I want to maintain both /Library/WebServer/Documents and Users/username/Sites as separate locations for web projects, as that's what I've been able to do on macOS for the last 10+ years. Commented Nov 14, 2017 at 8:15
  • So it looks like you would need to run two separate instances of Apache on the same machine but wouldn't that defeat the whole purpose of load balancing the websites that Apache now offers when run from a single instance? Apple's best practices recommendation is to no longer use the Users/username/Sites and stick with the Library/Webserver/Documents Commented Nov 15, 2017 at 9:12
  • The single Apache instance is cable of reading web projects from multiple directories. That's how I've had it set up for years. Commented Nov 16, 2017 at 9:18
3

After trying all the above methods, if you still get "forbidden" when accessing localhost, try adding virtualhost in your /etc/apache2/extra/httpd-vhosts.conf

Add:

<VirtualHost *:80>
ServerName localhost
DocumentRoot /Library/WebServer/Documents/
</VirtualHost>

then restart apache.

https://coolestguidesontheplanet.com/set-up-virtual-hosts-in-apache-on-macos-high-sierra-10-13/

works fine for me

1
  • Does not work after adding and restarting Apache. Commented Aug 16, 2021 at 17:11
1

I was on the same situation, apparently there are a few more lines to uncomment in httpd.conf, vhosts are not activated on High Sierra. - https://apple.stackexchange.com/a/299929/259065

1
  • I had already uncommented both of those lines. Makes no difference Commented Oct 11, 2017 at 21:00
1

Just updated this morning. Using Sites folder in /Users/username.

Backed up and replaced httpd.conf,httpd-userdir.conf and https-vhosts.conf w/ the ~previous variants.

Ran sudo apachectl configtest and got the PHP error (PHP updated to 7 in High Sierra). Edited http.conf to start PHP7 and now everything is working again.

1
  • +1 for including note sudo apachectl configtest
    – David C
    Commented Apr 2, 2018 at 15:47
1

Possible solution (after failing with all the above suggestions). The issue is with the permission of the home directory. It should be executable for group/others:

sudo chmod go+x /Users/username

where "username" is to be replaced with the actual username. After this, it works!

0

Phew!! I figured it out myself.

Do these steps

Step 1: Open your terminal and run this command below

sudo atom /etc/apache2/httpd.conf

And then Uncomment the Line by removing the "#" sign before it

LoadModule php7_module libexec/apache2/libphp7.so

Step 2: Run the following command mentioned below

cd /private/etc

sudo cp php.ini.default php.ini

Step 3: Then go to your /Library/WebServer/Documents directory and do a

sudo chown -R  root yourprojectname

Go back to your Safari browser and type in "http://localhost/yourprojectname"

You are all set to go.

I am using MacOS High Sierra 10.13, it got updated yesterday morning.

1
  • localhost running from /Library/WebServer/Documents is working fine. The problem is running localhost/~scott from /Users/Scott/Sites. Commented Oct 2, 2017 at 21:07
0

Spent the whole morning to figure it out, but finally it worked. Hope this can be useful for somebody.

I followed a guide, but with a slight change.

Now I can access localhost folders, but...

Before high-sierra it was like: http://localhost/~username/smomesite.local

Now is like: http://localhost/smomesite.local

No more ~username required.

1
  • I don't want to change the default apache web path to my user folder. In previous version of macOS I've been able to run files/sites from both the Users/myname/Sites directory and /Library/WebServer/Documents Commented Nov 7, 2017 at 20:10
0

I just had this same issue, and wanted to do exactly what you wanted (keep the root at /Library/WebServer/Documents, but also allow user Sites folders). I'm not sure if this will be helpful, but after banging at this for hours tonight, looking line by line thru all of the .conf files, and wondering what was wrong, I realized that httpd process wasn't able to read my own user directory. For some reason it was set as 750, and the _www user is unable to read it. Once I fixed that by running "chmod 755 ." on my user directory, the Sites folder showed right up.

I'm not sure how my own user directory got like that, as it appears that they default to 755 when I create a new user. And I had already double-checked many times that my Sites folder was set to 755.

1
  • Just tried that and restarted Apache. Still "Forbidden: You don't have permission to access /~username/ on this server" Commented Nov 11, 2017 at 10:11
0

I had the same problem. I uncommented the two lines below (as already suggested in another response)

#LoadModule vhost_alias_module libexec/apache2/mod_vhost_alias.so 
#Include /private/etc/apache2/extra/httpd-vhosts.conf

But still got the same error. The trick for me was uncommenting these additional lines in the httpd.conf file:

#LoadModule userdir_module libexec/apache2/mod_userdir.so 
#LoadModule include_module libexec/apache2/mod_include.so 
#LoadModule rewrite_module libexec/apache2/mod_rewrite.so

Hope that helps.

1
  • I've already uncommented those lines Commented Nov 14, 2017 at 8:16
0

It happens that the update moved all your previous configuration to the files .conf~previous. If you move /etc/apache2/extra/httpd-userdir.conf~previous to /etc/apache2/extra/httpd-userdir.conf, and /etc/apache2/extra/httpd.conf~previous to /etc/apache2/extra/httpd.conf, it should work like before.

mv /etc/apache2/extra/httpd-userdir.conf /etc/apache2/extra/httpd-userdir.conf~high-sierra
mv /etc/apache2/httpd.conf /etc/apache2/httpd.conf~high-sierra
mv /etc/apache2/extra/httpd-userdir.conf~previous /etc/apache2/extra/httpd-userdir.conf
mv /etc/apache2/httpd.conf~previous /etc/apache2/httpd.conf
apachectl restart
1
  • This was a clean install of High Sierra, so I didn't have any previous configuration files Commented Nov 7, 2017 at 20:08
0

I have had the same issue. The resolution was easy. See answer posted here: https://apple.stackexchange.com/a/306390/129503

I faced the same after I upgraded to High Sierra earlier today. I found that the following apache files were replaced with brand new versions. Fortunately for all of these files there existed a FILE~previous file in the same folder. I just copied the ~previous version back to the original ones, restarted apache and everything was fine.

In folder /etc/apache2 :

./httpd.conf
./extra/httpd-vhosts.conf
./extra/httpd-ssl.conf

Example:

cp /etc/apache2/httpd.conf~previous /etc/apache2/httpd.conf
0

Replace

./httpd.conf
./extra/httpd-vhosts.conf
./extra/httpd-ssl.conf

from older ~previous files.

The you might get php5 module error in httpd.conf, replace php5 with php7 and your sites should start working.

Replace

LoadModule php5_module libexec/apache2/libphp5.so

With

LoadModule php7_module libexec/apache2/libphp7.so
0

I just upgraded and had exactly the same issues. I don't use vhosts. Solution for me was ensuring:

In https.conf uncomment

LoadModule userdir_module libexec/apache2/mod_userdir.so

LoadModule authz_host_module libexec/apache2/mod_authz_host.so

LoadModule authz_user_module libexec/apache2/mod_authz_user.so

LoadModule authz_core_module libexec/apache2/mod_authz_core.so

and ensure the extra/httpd-user.conf has the line:

UserDir Sites

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .