Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

After restarting MAMP, I noticed the MySQL Server checkbox didn't turn green as it usually does. I clicked 'Start Servers' again and got a message stating, "Apache couldn't be started because port 8888 is in use by some other software." Weird since I haven't made any changes to the system or application, or installed any updates. I opened Chrome and entered the url of a site I'm developing locally and it showed up with no problem. But, when I tried to log into the site with a dummy user account I received a "SQLSTATE[HY000] [2002] Can't connect to local MySQL server through socket ' /Applications/MAMP/tmp/mysql/mysql.sock' (2)" message.

Regarding the first problem (Apache Port in use by another program), I opened up Terminal and >> sudo lsof -i -P | grep -i "listen" to see which ports would show up. When MAMP was closed, the console output was

launchd 1 root 23u IPv6 0x156733646a84db9h 0t0 TCP *:5900 (LISTEN) launchd 1 root 24u IPv4 0x156733646a84eba8 0t0 TCP *:5900 (LISTEN) launchd 1 root 28u IPv6 0x156733646a84d75u 0t0 TCP localhost:631 (LISTEN) launchd 1 root 29u IPv4 0x156733646a84e3bu 0t0 TCP localhost:631 (LISTEN) launchd 1 root 31u IPv6 0x156733646a84d31u 0t0 TCP *:22 (LISTEN) launchd 1 root 32u IPv4 0x156733646a857ba5 0t0 TCP *:22 (LISTEN) kdc 96 root 6u IPv6 0x156733646a84cedt 0t0 TCP *:88 (LISTEN) kdc 96 root 8u IPv4 0x156733646c2a9ba5 0t0 TCP *:88 (LISTEN) imagent 270 userhomedirectory 7u IPv4 0x156733646a1a13bb 0t0 TCP *:52216 (LISTEN) EEventMan 279 userhomedirectory 4u IPv4 0x156733646a8573bb 0t0 TCP *:2968 (LISTEN) The output when MAMP is running is (everything listed above) + :

httpd 28772 userhomedirectory 5u IPv6 0x156733646a84b55f 0t0 TCP *:8888 (LISTEN) httpd 28786 userhomedirectory 5u IPv6 0x156733646a84b55f 0t0 TCP *:8888 (LISTEN) httpd 28790 userhomedirectory 5u IPv6 0x156733646a84b55f 0t0 TCP *:8888 (LISTEN) httpd 28791 userhomedirectory 5u IPv6 0x156733646a84b55f 0t0 TCP *:8888 (LISTEN) httpd 28792 userhomedirectory 5u IPv6 0x156733646a84b55f 0t0 TCP *:8888 (LISTEN) httpd 28793 userhomedirectory 5u IPv6 0x156733646a84b55f 0t0 TCP *:8888 (LISTEN) httpd 28794 userhomedirectory 5u IPv6 0x169041156a84b55f 0t0 TCP *:8888 (LISTEN)

So, Port 8888 is only in use when MAMP is launched, which also tells me that the web server is, in fact, connected. So I don't understand why I'm getting an Apache port error.

Anyway, next I opened Activity Monitor and killed every httpd and mysqld process that was running and restarted MAMP but, the problem persisted. The mysqld process never reappeared after I killed it the first time.

Then, I searched SO. I came across a post regarding MAMP PRO and decided to try the suggested solutions but, to no avail. Same goes for this post's suggestion to delete and re-install the entire application.

By now I can't tell if the mysql error is causing the apache error or if the apache error is causing the mysql error. So, I searched and tried several solutions regarding the mysql error including suggestions from this post, and this post, but none of them worked for me. I mean, I literally tried every single suggestion on those pages, from the posted answers to the comments.

I've also tried restarting my computer, changing the apache, nginx and mysql port configuration settings, switching from apache to nginx, loading MAMP's MySql from Terminal, creating a my.cnf file with the socket configuration. None of which have worked.

Does anyone have any experience with this? Is it an Apache port error or a MySQL socket error? Or something totally different? And considering that there were no updates installed or changes to anything in the system or application, what could have caused this?

Thanks in advance.

* **Edit December 10, 2014 ***
So I played around with this all night. I re-installed the application a couple of times. Installed some updates and even copied my laptop's MAMP setup, which works, to my desktop. But, I still got the same errors. Then I changed MAMP's document root back to the default Mac HD -> Applications -> MAMP -> htdocs and it worked! I had previously set it to /Users/userhomedirectory/Sites.

I posted this as an edit instead of an answer because the problem still exists. Changing the document root back to Users/myhomedirectory/Sites gives me the same error messages as before so my solution is more of a workaround. Hopefully this sets off a lightbulb for someone because I still can't figure out what could be the cause and/or solution.

like image 692
wheresmyspaceship Avatar asked Dec 09 '14 20:12

wheresmyspaceship


3 Answers

I don't know if it will help someone... but this worked for me :

sudo apachectl stop :-)

from https://stackoverflow.com/a/24287496/1420009

like image 94
Monkey Monk Avatar answered Dec 06 '22 18:12

Monkey Monk


I ran into the very same problem after upgrading to yosemite and the MAMP Version 3.0.7.3. Tried a lot of suggestions and fix out there, but none of them worked for me.

When it hit me! When hitting the "Set Web &MySQL ports to 80 & 3306" button in MAMP, MAMP sets port 80 for Apache AND Nginx. Resulting an an error since both are set to use the same port. I simply set Nginx to another random port, hit the "OK" button and no error appeared.

I restarted Apache and MySQL. And voila!

All my localhost sites are working just as they were before the update.

Luckily, i just had read an interesting article explaining how to set up Nginx in front of Apache to serve static and dynamic independently to optimize performance. Which sparked the idea.

I hope it helps!

like image 45
user2130449 Avatar answered Dec 06 '22 19:12

user2130449


Go to the MAMP configuration and change the port address 8888 to any other address

MAMP->Preferences->Ports->Apache Port

I think it will work fine

like image 34
Amit Mishra Avatar answered Dec 06 '22 19:12

Amit Mishra