I just moved my dev environment from an older machine to a new MAC. I like to use MAMP for my general local environment (simpler projects) but for some reason, the recent version of MAMP wants me to use port 8888 for my localhost.
I changed it back to port 80 which is what I had on MAMP on my old machine, and I have some absolute dev links so I don’t want the hassle of putting localhost:8888 instead of just localhost at the beginning of my Uri:s
The result was that no resource could be accessed, everything was forbidden. Change the port back to 8888 and it works fine.
Why do I get this behavior?
Someone else seems to have had this same issue a month back (Can't connect to port 80 in MAMP on MAc) with no solution.
—————— update
lsof -I tcp:80
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
Google 973 mattias 28u IPv6 0x269b774a91275221 0t0 TCP localhost:54383->localhost:http (CLOSE_WAIT)
Google 973 mattias 36u IPv6 0x269b774a91275881 0t0 TCP localhost:54384->localhost:http (CLOSE_WAIT)
httpd 5444 mattias 4u IPv6 0x269b774a912738a1 0t0 TCP *:http (LISTEN)
httpd 5445 mattias 4u IPv6 0x269b774a912738a1 0t0 TCP *:http (LISTEN)
httpd 5446 mattias 4u IPv6 0x269b774a912738a1 0t0 TCP *:http (LISTEN)
httpd 5447 mattias 4u IPv6 0x269b774a912738a1 0t0 TCP *:http (LISTEN)
httpd 5448 mattias 4u IPv6 0x269b774a912738a1 0t0 TCP *:http (LISTEN)
httpd 5449 mattias 4u IPv6 0x269b774a912738a1 0t0 TCP *:http (LISTEN)
httpd 5461 mattias 4u IPv6 0x269b774a912738a1 0t0 TCP *:http (LISTEN)
httpd 5468 mattias 4u IPv6 0x269b774a912738a1 0t0 TCP *:http (LISTEN)
httpd 5476 mattias 4u IPv6 0x269b774a912738a1 0t0 TCP *:http (LISTEN)
httpd 5477 mattias 4u IPv6 0x269b774a912738a1 0t0 TCP *:http (LISTEN)
httpd 5478 mattias 4u IPv6 0x269b774a912738a1 0t0 TCP *:http (LISTEN)
Also, http://localhost/MAMP/ works fine
When I try to access any of my own folders in the webroot I get forbidden:
If I try a first-level folder (i e http://localhost/myapp/, located in webroot/myapp) I get only
Forbidden
You don’t have permission to access this resource.
But if I try a subfolder or a PHP file such as http://localhost/myapp/subfolder/
or
http://localhost/myapp/subfolder/index.php
then I instead get
Forbidden
You don’t have permission to access this resource. Server unable to read htaccess file, denying access to be safe
If I configure MAMP to use a different port it all works fine. But I don’t want to have to specify a port in my route in dev env since the app I’m working on has some hard-coded Uri:s.
Also, this is a weird behaviour that annoys me =) My other MAC isn’t doing this so I’d like to get to the bottom of it…
——- another update
I have moved my web root (htdocs I believe MAMP called it by default) into my user folder (user/Home/Documents/www) if it is somehow permission related, but I don’t understand why it then works fine under port 8888 but not under 80… it’s not like Apache gets access to my folder based on what port it’s running off of…
——- requested info
I occasionally start a node server just to check a guy’s work but not running at the moment. When it’s on it runs under port 3000-something.
.htaccess of my web/ folder:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^domain-name.com$ [NC,OR]
RewriteCond %{HTTP_HOST} ^www.domain-name.com$
RewriteCond %{REQUEST_URI} !folder/
RewriteRule (.*) /folder/$1 [L]
Mac version Big Sur 11.3.1
MAMP version 6.3
5
Answers
This is the issue. I have no idea why the behavior is different with a different port, but setting the wwwroot to MAMP/htdocs and moving my application there solved the probem.
I won't mark this as THE answer, in case someone can explain why MAMP gets permission to wwwroot when it's in my Home folder as long as it runs on port 8080 or something else, and NO permission while on port 80, that would be the best answer to this question...
This happens because there are other apps using port 80. One that comes to mind is skype. you could try lsof -i tcp:80 to see which processes are locking port 80.
There could be multiple reasons I can think of. I’d like to also propose a workaround for each.
Firstly, Mac (Darwin) is based off of Linux. This means the ports under 1024 range are privileged. Any application running in ring 3 (userland) cannot access the ports.
You need to run the applications with
sudo
privileges. This of-course comes with security risk and should be done only after due considerations. Usually you should not run Webservers (and dev environments like MAMP) withsudo
. See my last point for a solution, which is often used as a best practice in many production environments.Secondly, there is a high possibility that you’re tryin to run it as root, but still the port isn’t accessible. This could be due to the fact that the port is already taken up by another application.
To check this, you can issue
lsof -i tcp:80
which I can see you did anyway. Kill other applications that are blocking this port for you. Sometimes quitting application is not enough, you might have to usesudo kill -9 pid
. More information is in this man page.Thirdly, A Mac specific problem could be (which I think is the case with you because you arere seeing different errors when accessing webroot and subfolders)that either the gatekeeper is preventing MAMP from accessing the directories, or the
chmod
permissions aren’t proper (because I see a .htaccess complaint).System Preference -> Pivacy & Security -> General
isn’t blocking the application.Full Disk Access
orFiles and Folders
available underSystem Preference -> Pivacy & Security -> Privacy
chmod
755 permission on your project directories and 644 on the files.chmod -R 755 DIRECTORY
. Have a look at this SupeUser post for futher details.And in the last, if nothing else works, you run MAMP on some other port and then redirect all local traffic from port 80 that port using
iptables
. This is mostly how webservers are actually configured in the production environment too, if they are not hidden behind a load-balancer or a reverse-proxy. Please refer this AskUbunu post for the instructions.When setting up the Apache tab, check the "Indexes" box:
That will give you access to your
localhost:8888
.The answer by Jorge Aranda Fernandez worked for me when I was trying to get a demo version of MAMP Pro working. I have been running MAMP Free for years on port 8888 so I had been trying to get MAMP Pro to run on port 80 to keep them separate. As a linked image may or may not last these are the full instructions.
NOTE: the original author stated this is a fix for port 8888 (it is). However, the original question was about access to port 80 which this also fixes.
Within MAMP Pro
Expert View
icon for the view mode.Hosts
underSETTINGS
. Then selectlocalhost
underNames
.Apache
.Options for <Directory> directive:
ensure the first boxIndexes
has a tick.Revert
andSave
. ClickSave
. You will then be prompted to restart the server.https://localhost:80
in your browser and it should now connect.