wheresmyspaceship
wheresmyspaceship

Reputation: 1080

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.

Upvotes: 7

Views: 52716

Answers (12)

Hassan Elshazly Eida
Hassan Elshazly Eida

Reputation: 839

run

sudo kill $(sudo lsof -t -i:8000)

which 8000 is port number

Upvotes: -1

sascha
sascha

Reputation: 1

Goto MAMP configuration and change the port addresses (Apache+Nginx) 8888 to > 80 Apache and 80 Nginx Port. Yep, MySql is 3306....

Upvotes: 0

Murat Kezli
Murat Kezli

Reputation: 307

Change MAMP Nginx port 70 etc.
and

sudo lsof -nP -i4TCP:8888 | grep LISTEN

then kill PID

for example: If port:8888

sudo lsof -nP -i4TCP:8888 | grep LISTEN
---
httpd     15030 yourusername    4u  IPv6 0x5fdd0f41d81c1dd3      0t0  TCP *:8888 (LISTEN)
httpd     15031 yourusername    4u  IPv6 0x5fdd0f41d81c1dd3      0t0  TCP *:8888 (LISTEN)
httpd     15032 yourusername    4u  IPv6 0x5fdd0f41d81c1dd3      0t0  TCP *:8888 (LISTEN)
--
sudo kill -9 15030
sudo kill -9 15031
sudo kill -9 15032

Upvotes: 3

Mahbubur Rahman Mishal
Mahbubur Rahman Mishal

Reputation: 151

Try going to activity monitor and searching for Mysqld and Httpd and end any processes for them. Then restart Mamp. This Worked for me

Upvotes: 7

Monkey Monk
Monkey Monk

Reputation: 990

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

sudo apachectl stop :-)

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

Upvotes: 45

Daniel
Daniel

Reputation: 792

I don't mean this in a trivial way but when this happened to me I started trying some of the suggestions in here (permissions etc) but when I just did a restart of the computer it was working afterwards. So just a reminder to try a restart before trying the others.

Upvotes: 1

Amit Mishra
Amit Mishra

Reputation: 291

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

Upvotes: 4

user2144993
user2144993

Reputation:

If no MySQL instance is running, it is probably permission issue. Right click on the icon -> run as administrator.

Upvotes: 0

faucher-bscg
faucher-bscg

Reputation: 11

Like Nathan Rutman, this turned out to be a permissions issue for me. I was getting the same errors displayed above - Apache couldn't be started because port 8888 is in use by some other software. ... and MySQL Server wasn't starting up.

I had no luck changing ports or moving the directory to htaccess.

What worked:

I went to Applications, selected MAMP, and brought up Finder's Get Info dialogue. I added Read & Write permissions for the current user and administrators, clicked the gear, and clicked Apply to enclosed items...

I did the same for the MAMP Pro, just to make sure my bases were covered.

Started up MAMP, changed the ports to default, and boom! Everything working, including MySQL Server - no Terminal commands required.

This continued to work successfully when I changed my directory back to a /Users/myuser/Sites/ folder, as well.

Upvotes: 1

user1798533
user1798533

Reputation: 323

Changing the Nginx port helped me.

Upvotes: 1

user2130449
user2130449

Reputation: 101

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!

Upvotes: 4

Nathan Rutman
Nathan Rutman

Reputation: 2255

UPDATE:

Actually, this is just a straight-up permissions issue. I ran into the same problem again and simply did a chown -R nathan:staff <dir> and restarted Apache in MAMP. It worked fine.

ORIGINAL POST:

Oddly enough I think I fixed the problem on my machine. After looking at the directories for both the default htdocs directory and the directory that I wanted to use, I noticed that the default directory was owned by nrutman:admin while the directory that I wanted to use was owned by nrutman:staff (same user, different group).

Via Finder's "Info" panel (Cmd-I) I added a read/write permission for the Administrators group to the folder and removed the staff group permission. I restarted MAMP and everything worked! Then, via chown I changed the owner back to nrutman:staff. Finder's information panel now looked the same way that it did before, but now MAMP will use that directory without complaining about ports.

Definitely seems like a MAMP bug. Not really sure what is going on, but I hope that helps others who are struggling with the problem.

Upvotes: 0

Related Questions