When you use MAMP for local development, sometimes the web server just refuses to start. The usual cause is another application already holding port 80. Skype is the classic culprit, but IIS on Windows, Docker Desktop, or a leftover XAMPP install cause the same thing.
The fix is to move the web server to a different port, usually 8080.
The steps
-
Quit MAMP completely. Not just closing the window, actually quit it, and check the system tray too.
-
Open the Apache config file in a text editor:
C:\MAMP\conf\apache\httpd.confOn macOS the path is
/Applications/MAMP/conf/apache/httpd.conf. -
Find the line
Listen 80 -
Change it to
Listen 8080and save. -
Start MAMP, go to the port settings in the interface, change the value to 8080 and save.
-
Open the site with the port in the address:
http://localhost:8080
Fix ServerName too
Just below Listen there is usually a ServerName line. If it still has the old port, Apache can generate redirects pointing at the wrong address:
ServerName localhost:8080
Finding out what is holding the port
Sometimes instead of changing the port you want to know exactly what has port 80 so you can shut it down.
On Windows, open Command Prompt as administrator:
netstat -ano | findstr :80
The last column is the process ID. Look up the process name:
tasklist | findstr <PID>
On macOS or Linux:
sudo lsof -i :80
If IIS on Windows turns out to be the culprit, you can stop it with:
net stop http
If MySQL conflicts too
MySQL in MAMP defaults to port 3306, which clashes if the machine already has MySQL or XAMPP installed. Change it in:
C:\MAMP\conf\mysql\my.ini
Find port=3306 and change it to 3307.
Remember that changing the MySQL port means updating the connection string in your code as well:
$conn = new mysqli( '127.0.0.1:3307', 'root', 'root', 'database_name' );
After changing the port
A few things are easy to forget once the site is not on port 80:
Application config. WordPress stores the site URL in the database, so it will try to redirect to http://localhost with no port and give you a blank page. Fix it in wp-config.php:
define( 'WP_HOME', 'http://localhost:8080' );
define( 'WP_SITEURL', 'http://localhost:8080' );
Callback URLs. If you are integrating a payment gateway or social login, the registered callback URLs need the new port too.
Consider just keeping 8080. If you hit port conflicts often, leave MAMP on 8080 permanently and get used to typing the port. It beats stopping and starting other applications every time you want to write code.