Apache gives Access denied on macOS Catalina - macos

I have Apache webserver (the one supplied by Apple) running on my Macbook and it ran flawlessly, until I upgraded to Catalina 10.15.
I used the same httpd.conf, but now it is displaying
You don't have permission to access this resource.Server unable to read htaccess file, denying access to be safe
I thought is was folder access by Catalina, but I don't know how to let Apache access the web root folder (which is inside my /Users/me/Documents folder)as Apache is not a normal /Application.
Port 80 is open when I check with lsof -nP -i4TCP:80 | grep LISTEN op nmap, so Apache does start.
I set a simple index.html in the root folder, but the problem persists.
And when I remove the .htaccess from the Apache root folder I get:
You don't have permission to access this resource.
Additionally, a 403 Forbidden error was encountered while trying to use an ErrorDocument to handle the request.
What can be the problem here ?

I have found the solution, myself.
It is a Catalina issue:
Go to System Preferences => Security & Privacy => Full Disk Access
Click on the "+" button to add an app and go to the root folder of the disk and press
Cmd + Shift + .(dot)
Go to /usr/sbin/ and select httpd.
That worked for me.

i had the same error, the problem in my case was that macOS Catalina comes with the php module disable by default, in the error log apear as:
tail /private/var/log/apache2/error_log
[Wed Feb 26 18:10:57.123036 2020] [autoindex:error] [pid 3145] [client
127.0.0.1:53734] AH01276: Cannot serve directory /Library/WebServer/Documents/subdir/: No matching DirectoryIndex
(index.html) found, and server-generated directory index forbidden by
Options directive
the apache server was loking for index.html instead of index.php so it was blocking the list directory, I uncommented the line #LoadModule php7_module libexec/apache2/libphp7.so in /etc/apache2/httpd.conf and restart the apache server
sudo apachectl restart
and it just work. hope it helps.

The above answer save my life!
I tried all the different Apache configs possible, nothing worked.
Just a small correction for step 2 - click on the "+" sign to add an app, navigate to the root folder then press Cmd + Shift + .(dot) which will show all hidden folders and allow you to see the folder in step 3 (/usr/sbin/)
I wish Apple would have at least shown some error in such a case...

Mac catalina apache forbidden issue
Step 1: sudo code /etc/apache2/httpd.conf
Step 2:search for line #LoadModule php7_module libexec/apache2/libphp7.so
and uncomment no need to delete it.
Step 3: sudo apachectl restart
Step 4: open Web browsers type localhost
Step5: Done

Related

Apache httpd got 403 forbidden on MacOS High Sierra

I tried to install Apache HTTPD via Homebrew with brew install apache2, it worked well with default configuration http://localhost:8080
However, once I added more virtual host, to another folder (actually just clone the www folder to new one), and then tried to access to that new virtual host, I got 403 Forbidden error.
I don't think there was any wrong configuration, because it worked well with Apache2 on Ubuntu, but don't know why it's broken on MacOS, even I changed permission to 777 for that new www folder
Thanks
I hit the same wall, so I'd like to share my experience and hope it can help.
First of all, look at the error message in the log file that you specified for your virtual host.
If you see something like:
[authz_core:error] [pid 57233] [client 127.0.0.1:55693] AH01630: client denied by server configuration: /opt/local/www/your_vhost/
which indicates the module authz_core cause the forbidden. In this case, add Require all granted in your VirtualHost block can solve the problem.
There are different modules can cause the same problem, so you'd better to see the message in the log first.
The Apache2 error log helped me solved the mystery. It turned out that 127.0.0.1 is pointed to a VH with folder location in where there is no index.html. I thought it was pointing to my Docroot as in the case of the localhost.

Cannot get site loaded with Apache on Mac

I'm running El Capitan and trying to get my website hosted locally for development with Apache (that came with the OS). I followed the instructions here exactly. I made an anthony.conf file and put the Directory text in there, I replaced the actual directory with /Users/anthony/dev/web/unfinished-asteroids/ and then placed my web files in there. I started apache and navigated for localhost/~anthony but I get the
Not Found: The requested URL /~anthony was not found on this server.
standard 404 error. When I navigate to localhost it works fine and I get the "It works" from the index.html that is located in /Library/WebServer/Documents, I even changed that index.html file and it works fine.
Any ideas why I'm not able to see my website using apache? All I did was download this github repository and place it in my unfinished-asteroids folder, the index.html is at the root.
So it looks like there are a couple of extra steps that you need to do. There isn't really anything too special about apache that comes with OSX, so your standard apache configurations will work. but to get Userdir (~username) working on El Capitan,this is what I had to do
Edit /etc/apache2/httpd.conf
on (or near) line 166, uncomment
loadModule userdir_module libexec/apache2/mod_userdir.so
then on line 493 uncomment
Include /private/etc/apache2/extra/httpd-userdir.conf
then edit file /etc/apache2/extra/httpd-userdir.conf
uncomment line 16
Include /private/etc/apache2/users/*.conf
then in /etc/apache2/users/anthony.conf
<Directory "/Users/anthony/Sites/">
Options Indexes MultiViews
Require all granted
</Directory>
then sudo apachectl restart
That should make http://localhost/~anthony point to your sites directory.
Logs are stored in /var/log/apache2
Now if all you want is web access to say your dev directory you can do something like this.. (don't make any of the changes listed above)
in /etc/apache2/other/ create a file called mydev.conf (name doesn't really matter, save it needs to end in .conf')
and put this in that file
Alias /dev /Users/anthony/dev/
<Directory "/Users/anthony/dev">
Options Indexes MultiViews
Require all granted
</Directory>
and reload apache (sudo apachectl restart)
then you will be able to access your dev folder at http://localhost/dev and should be able to access your page at http://localhost/dev/web/unfinished-asteroids/
you can adjust the paths at will above, just need to make sure that the user or group _www has access to it, and that paths in the alias and the directory match.

OSX El Capitan - Apache 403 Forbidden

I just upgraded from Yosemite to El Capitan but unfortunately forgot to copy my old httpd.conf and now i need to configure all of its settings again.
I already changed the documentroot to the previous one /users/admin/www, and also configured to release access to this folder:
<Directory "/users/admin/www">
Options Indexes MultiViews FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
Restarted Apache but even this way I get the 'Forbidden' error when trying to access 127.0.0.1.
What am I'm missing here?
Do the following:
Open Terminal
Run:
cd /etc/apache2/
sudo mv httpd.conf httpd.conf.OLD
sudo mv httpd.conf~previous httpd.conf
sudo apachectl restart
After spending 3 hours on the issue - this worked for me!
I just found out that the old .conf file is saved during the El Captain update, in this folder :
/private/etc/apache2/httpd.conf.pre-update
So i just copied the old definitions to the new one :)
You can navigate to /private/etc/apache2/ and then diff httpd.conf httpd.conf.pre-update to see the differences between your old conf file and the new one that's been added.
For me there was a lot of LoadModules lines commented out, and my apache user/group had been changed back to _www
I am not familiar with the changes in Apache 2.4 so this one really stumped me for about 30 minutes. I just upgraded from Mavericks to El Capitan (Apache 2.2 to 2.4) and I could not load my personal Sites directory (http://localhost/~{username}. I kept getting "Forbidden". After a good bit of research I found that I needed to modify /etc/apache2/users/{username}.conf to add "Require all granted". Since I never upgraded to Yosemite (which also uses Apache 2.4) I never stumbled across this one.
I hope this info helps somebody
Updating the directory access control worked for me:
In this example, all requests are allowed.
2.2 configuration:
Order allow,deny Allow from all
2.4 configuration:
Require all granted
Source: http://httpd.apache.org/docs/trunk/upgrading.html (under Access control)
Note: I keep my custom settings separately under /private/etc/apache2/other/.
This helped as well (after doing everything else as well):
http://coolestguidesontheplanet.com/forbidden-403-you-dont-have-permission-to-access-username-on-this-server/
Like #delphirules said, you can copy your old httpd.conf file like so:
sudo cp /etc/apache2/httpd.conf.pre-update /etc/apache2/httpd.conf
I’ve had issues with connecting to my localhost all day but finally found this: https://mallinson.ca/web-development-with-el-capitan/
Just run the copy command and then do a sudo apachectl restart
I’ve also disabled the SIP ( System Integrity Protection ) in recovery mode. I don’t know if it actually did anything though.. You can find those instructions here: https://forums.developer.apple.com/thread/3981
I had a similar issue receiving a 404 error back when trying to access pages in my local sites directory after enabling myself at the user level to serve sites after upgrading to El Capitan. The issue was that Apache reset the httpd.conf file to its default which disables the user folders to load files from. So http://localhost loaded fine but http://localhost/~username/index.html would NOT load. Here's the fix:
back up the "new" config file that was created:
sudo cp /etc/apache2/httpd.conf /etc/apache2/httpd.conf_capitan
restore the "old" config file that was renamed:
sudo cp /etc/apache2/httpd.conf~previous /etc/apache2/httpd.conf
In case you have symlinks to some of your projects in DocumentRoot directory, after upgrade to El Capitan you can get 403 for these projects, like I did.
You will need the following things to make them work again:
1) Your apache user (_www by default) should have execute access to directory that houses a directory to which you link to.
In my case in apache DocumentRoot I had:
MyProject -> /Users/Me/Documents/Aptana Studio 3 Workspace/MyProject
And for some reason access settings for
/Users/Me/Documents/Aptana Studio 3 Workspace/MyProject
were
-rw------- 1 Me staff My guess it was set during OS x upgrade.
So after sudo chmod 755 Aptana\ Studio\ 3\ Workspace error was resolved.
2) As upgrade also changes httpd.conf, make sure you have this for DocumentRoot directory, or restore from backup httpd.conf as suggested above:
Options Indexes FollowSymLinks
If you upgraded from Mavericks or earlier OS x and restored backup httpd.conf, you should, as jcfranko said, replace apache 2.2 setting for request allowance with:
Require all granted
Create a symlink in your /Users/{user name}/Sites folder
ln -s /Path/To/Target/Files /Users/{user name}/Sites/{name}

Apache, permission denied accessing the web app folder after upgrading OSX to 10.9.2

My Apache used to work fine, but I assume that problems came after upgrading OSX to 10.9.2, (anyway not certain about when the problem came) Apache was not working with the current configuration.
I tried apachectl configtest so I found out that the Apache's file structure on my machine was changed, from Library/WebServer/Documents/ to Library/WebServer/Apache Home so I edited the DocumentRoot of httpd.conf to point to the new folder.
But the problem I still cannot fix is about the permission. I got 403 Forbidden, You don't have permission to access / on this server.
Extra Information
I hosted all my web projects at /Users/myname/home_www this folder and it's sub folders belong to _www group, and has 775 access permission. I created a symlink at Library/WebServer/Apache Home (all these setup used to work fine)
I noticed some strange thing that the Library/WebServer/ and its sub folders belong to wheel group, I never paid attention to these folders before that what group they belong to.
OSX: 10.9.2
Apache: 2.2.26
As I said in my case all problems seem to come after upgrading to 10.9.2, these are steps I have done to solve my problems.
Edit DocumentRoot to DocumentRoot "/Library/WebServer/Apache Home"
Edit <Directory> to <Directory "/Library/WebServer/Apache Home">
This step may not be necessary but just in case, brew upgrade
Chenge owner and group of /usr/local/var/mysql/ to *mysql using sudo chown -R _mysql:_mysql /usr/local/var/mysql/, otherwise mysql.server start will fail

install wordpress locally on OS X without MAMP (permission error)

I'm trying to install wordpress locally on a mac with the built in stuff (apache/php) without installing MAMP. basically I'm following this tutorial:
https://gist.github.com/1500117
after editing the httpd.conf file, and restarting apache, I get this error in the browser:
Forbidden
You don't have permission to access / on this server.
Any ideas?
I'm using Snow Leopard
well it seams I found what caused the problem.
the Sites folder, where I put the wordpress folder had permissions 750, after changing it to 751, now it works.
is this a proper solution or I should keep digging?
While there are a lot of variables to check here, the two biggest are the server root (make sure the case of all the path elements is correct) and the user permissions/owner of the WordPress files themselves.
All that said, why not use MAMP for this kind of situation?
Try typing http://your-host-name/index.php
If that fixes it, then your DirectoryIndex directive (in httpd.conf) needs to be changed to DirectoryIndex index.html index.php
If that does not fix it, type tail -f /var/log/apache2/error_log at the console and look at the terminal screen while you hit http://your-host-name/index.php in your browser. It may tell you what the problem is. If not, paste the last few lines of the log file up here and I'll look at it for you.

Resources