MAMP "Apache couldn't be started because port is in use." AND "Can’t connect to local MySQL server through /tmp/mysql.sock

MAMP "Apache couldn't be started because port is in use." AND "Can’t connect to local MySQL server through /tmp/mysql.sock

  1. Blog
  2. 15 November 2026
  3. 3 min read

Stefan Bogdanescu

Founder & Senior Architect

Diagnosing MAMP Port and Socket Errors

When MAMP fails to start, it often presents a confusing mix of symptoms that can suggest two completely different underlying issues. You might see an error stating "Apache couldn't be started because port 8888 is in use," while simultaneously receiving a MySQL connection failure: SQLSTATE[HY000] [2002] Can't connect to local MySQL server through socket '/Applications/MAMP/tmp/mysql/mysql.sock'.

The key to resolving this lies in understanding the order of operations and how MAMP handles its internal state. In many cases, the "port in use" error is a red herring caused by the database service failing to start first. If MySQL crashes or exits unexpectedly during startup, it can leave processes hanging or fail to cleanly release resources, which might confuse the web server's initialization sequence.

Investigating Port Conflicts

To determine if a legitimate external process is blocking port 8888, you need to inspect the active listeners on your system. Using Terminal, run the following command to list all processes listening for incoming connections:

sudo lsof -i -P | grep -i "listen"

When MAMP is closed, this output should only show standard macOS services like launchd listening on ports 5900 (VNC), 631 (CUPS), and 22 (SSH). If you see entries for httpd listening on port 8888, it confirms that the Apache process is active.

However, a critical detail to note is the count of httpd processes. In a healthy environment with MAMP running normally, you will typically see exactly two httpd entries (one for IPv4 and one for IPv6) sharing the same port 8888. If your diagnostic output shows multiple distinct PIDs (e.g., 28772 through 28794) all claiming to listen on port 8888, this indicates a state inconsistency within the MAMP application itself rather than an external conflict.

The MySQL Socket Discrepancy

The second error regarding the socket file is often more indicative of the root cause. The path /Applications/MAMP/tmp/mysql/mysql.sock specifies where the web server expects to find the database listener. If this file is missing, corrupted, or if the mysqld process failed to initialize correctly upon startup, Apache cannot establish the connection required to serve your application.

Attempting to manually kill processes in Activity Monitor and restarting MAMP often yields no results because the application attempts to spawn its own instances of httpd and mysqld. If the previous instance did not shut down cleanly, or if the configuration is locked due to a permission error or directory mismatch, simply killing the process isn't enough. The system may still be trying to bind to resources that are technically free but logically inconsistent with MAMP's internal state.

The Document Root Variable

In one specific variation of this issue, where all standard troubleshooting—including reinstalling the application and switching between Apache and Nginx—failed, the culprit was identified as a custom document root configuration. When a developer sets the MAMP document root to a custom directory outside the default htdocs folder (such as /Users/userhomedirectory/Sites), it can sometimes interfere with how the built-in virtual host definitions are resolved or how the application manages its internal paths during startup sequences.

Resetting the document root back to the default location (/Applications/MAMP/htdocs) restored functionality in this specific instance. This suggests that custom directory mappings might be causing path resolution conflicts, particularly when combined with socket errors where the web server and database cannot agree on their relative locations. If you are using a custom document root for development, ensure that the permissions on that folder match the expectations of the httpd user and that no symlinks are breaking the chain between the application's virtual host configuration and your actual files.

Our network