Apple - How to fix 403 in Mac OS X built-in Apache?
I have an alias specified in OSX server pointing to a user directory. I spent a long while chmodding and messing with _www user, adding executable permissions recursively, uninstalling macports and all sorts of stuff trying to get this to work. No idea why it wasn't working.
Eventually, I just checked the "shared folder" checkbox in the Finder for that folder, and it worked, on the specified domain, with php active, the way I wanted it to. :/ ...so that was easy.
I generally fix this by setting the Apache user to myself in local environments and in machines where the only user who uses Apache is me. In /private/etc/apache2/httpd.conf
, set User
to your username from _www
, e.g.:
User _www
->
User joao
And then restart Apache:
$ sudo apachectl restart
Additional steps:
If you have active sessions, they are going to give permission errors since they are still owned by
_www
. Own them:$ sudo chown joao: /var/tmp/sess_*
Implications:
After this, Apache (and PHP et al.) will run as you and will gain read/write permission to all of the files you have read/write permission. But since this is just a local development environment, that shouldn't be a problem unless you have no rules to block Apache in your firewall and let questionable files like file explorers, shells, scripts that may contain vulnerabilities run under Apache; in which case anyone including your public wifi neighbor in a cafe can enter http://<your IP>
and do whatever those scripts let them to do.
In fact, you should prevent this regardless of the scripts you run or even if you don't set Apache user to yourself since you probably don't want random outsiders to be able to see the contents of your localhost
.
Prevention:
Make Apache listen only to localhost. Again, in
httpd.conf
:Listen 80
->
Listen 127.0.0.1:80
And restart Apache again:
$ sudo apachectl restart
Disable Apache in the application firewall (note that you may have already disabled it if you clicked
Deny
if/when it was asked during the first time you run Apache):- Open
System Preferences
»Security & Privacy
»Firewall
. - Click the lock icon to the lower left and enter your password if needed.
- Turn the firewall on if it's disabled.
- Click
Firewall Options
. - Click the
+
button. - Hit cmd ⌘ + ⇧ shift + G and enter
/usr/sbin/httpd
and clickAdd
(Ifhttpd
doesn't show up there, you can look for it in the terminal bywhich httpd
) - In the list click
httpd
and selectBlock incoming connections
. - Hit
OK
. Reload the firewall:
$ launchctl unload /System/Library/LaunchAgents/com.apple.alf.useragent.plist $ sudo launchctl unload /System/Library/LaunchDaemons/com.apple.alf.agent.plist $ launchctl load /System/Library/LaunchAgents/com.apple.alf.useragent.plist $ sudo launchctl load /System/Library/LaunchDaemons/com.apple.alf.agent.plist
- Open
Restrict PHP to the document root. In
php.ini
:open_basedir = /Users/joao/Sites/:/var/tmp/
(
/var/tmp/
is for sessions)
Use all three solutions to secure yourself in case one of them gets disabled for some reason.
- Note that as my active language in my machine is not English right know, wording might be a little different (Menu options and wording can be different regardless of the language in various OS X versions).
- Lines starting with $
need to be entered in command line (Terminal or iTerm etc), with the $
removed.
I update to macOSS Sierra, Version 10.12
I face the same issue, I did two things to fix it properly. Following is my approaches.
1) Please check "/private/etc/apache2/extra/httpd-userdir.conf" file. Change
#Include /private/etc/apache2/users/*.conf
to
Include /private/etc/apache2/users/*.conf
2)**And edit your "/etc/apache2/httpd.conf"
change
Options FollowSymLinks Multiviews
to
Options FollowSymLinks Multiviews Indexes
finally your doc root will be look like the following,
DocumentRoot "/Library/WebServer/Documents"
<Directory "/Library/WebServer/Documents">
Options FollowSymLinks Multiviews Indexes
MultiviewsMatch Any
AllowOverride All
Require all granted
3) Restart apache
sudo apachectl restart
Still you facing the problem, Kindly check How to Set up Apache in macOS Sierra 10.12