php MAMP “Apache 无法启动,因为端口正在使用中。” 和“无法通过 /tmp/mysql.sock 连接到本地 MySQL 服务器
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/27387922/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
MAMP "Apache couldn't be started because port is in use." AND "Can’t connect to local MySQL server through /tmp/mysql.sock
提问by wheresmyspaceship
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.
重新启动 MAMP 后,我注意到 MySQL 服务器复选框并没有像往常一样变成绿色。我再次单击“启动服务器”并收到一条消息,指出“无法启动 Apache,因为端口 8888 正在被其他一些软件使用。” 奇怪,因为我没有对系统或应用程序进行任何更改,也没有安装任何更新。我打开 Chrome 并输入我在本地开发的网站的 url,它显示没有问题。但是,当我尝试使用虚拟用户帐户登录该站点时,我收到“SQLSTATE[HY000] [2002] 无法通过套接字'/Applications/MAMP/tmp/mysql/mysql.sock'连接到本地 MySQL 服务器” (2)”消息。
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
关于第一个问题(另一个程序正在使用 Apache 端口),我打开终端并>> sudo lsof -i -P | grep -i "listen"
查看会显示哪些端口。当 MAMP 关闭时,控制台输出是
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) + :
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)
MAMP 运行时的输出是(上面列出的所有内容)+:
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)
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.
因此,端口 8888 仅在启动 MAMP 时使用,这也告诉我 Web 服务器实际上已连接。所以我不明白为什么我会收到 Apache 端口错误。
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.
无论如何,接下来我打开活动监视器并杀死正在运行的每个 httpd 和 mysqld 进程并重新启动 MAMP 但是,问题仍然存在。mysqld 进程在我第一次杀死它后就再也没有出现过。
Then, I searched SO. I came across a postregarding 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.
然后,我搜索了SO。我遇到了一篇关于 MAMP PRO的帖子,并决定尝试建议的解决方案,但无济于事。这同样适用于这个职位的建议,删除并重新安装整个应用程序。
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.
现在我无法判断是 mysql 错误导致了 apache 错误还是 apache 错误导致了 mysql 错误。因此,我搜索并尝试了几种有关 mysql 错误的解决方案,包括来自这篇文章和这篇文章的建议,但没有一个对我有用。我的意思是,我真的尝试了这些页面上的每一个建议,从发布的答案到评论。
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.
我还尝试重新启动计算机,更改 apache、nginx 和 mysql 端口配置设置,从 apache 切换到 nginx,从终端加载 MAMP 的 MySql,使用套接字配置创建 my.cnf 文件。这些都没有奏效。
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?
有人对这个有经验么?是 Apache 端口错误还是 MySQL 套接字错误?或者完全不同的东西?考虑到系统或应用程序中没有安装更新或更改任何内容,这可能是什么原因造成的?
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
.
* **编辑 2014 年 12 月 10 日***
所以我整晚都在玩这个。我重新安装了应用程序几次。安装了一些更新,甚至将我的笔记本电脑的 MAMP 设置复制到我的桌面上。但是,我仍然遇到相同的错误。然后我将 MAMP 的文档根目录改回默认值,Mac HD -> Applications -> MAMP -> htdocs
并且成功了!我之前已经设置为/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.
我将此作为编辑而不是答案发布,因为问题仍然存在。将文档根目录更改回Users/myhomedirectory/Sites
给我与以前相同的错误消息,因此我的解决方案更像是一种解决方法。希望这为某人点亮了灯泡,因为我仍然无法弄清楚可能是什么原因和/或解决方案。
回答by Monkey Monk
I don't know if it will help someone... but this worked for me :
我不知道它是否会帮助某人......但这对我有用:
sudo apachectl stop
:-)
sudo apachectl stop
:-)
回答by Amit Mishra
Go to the MAMP configuration and change the port address 8888
to any otheraddress
转到 MAMP 配置并将端口地址更改8888
为任何其他地址
MAMP->Preferences->Ports->Apache Port
I think it will work fine
我认为它会工作得很好
回答by user2130449
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.
升级到 Yosemite 和 MAMP 版本 3.0.7.3 后,我遇到了同样的问题。尝试了很多建议并解决了问题,但没有一个对我有用。
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.
当它击中我!在 MAMP 中点击“将 Web 和 MySQL 端口设置为 80 和 3306”按钮时,MAMP 会为 Apache 和 Nginx 设置端口 80。导致错误,因为两者都设置为使用相同的端口。我只是将 Nginx 设置为另一个随机端口,点击“确定”按钮,没有出现错误。
I restarted Apache and MySQL. And voila!
我重新启动了 Apache 和 MySQL。瞧!
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.
幸运的是,我刚刚阅读了一篇有趣的文章,解释了如何在 Apache 前设置 Nginx 以独立提供静态和动态服务以优化性能。这激发了这个想法。
I hope it helps!
我希望它有帮助!
回答by Mahbubur Rahman Mishal
Try going to activity monitor and searching for Mysqld and Httpd and end any processes for them. Then restart Mamp. This Worked for me
尝试转到活动监视器并搜索 Mysqld 和 Httpd 并为它们结束任何进程。然后重新启动Mamp。这对我有用
回答by faucher-bscg
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.
像 Nathan Rutman 一样,这对我来说是一个权限问题。我遇到了上面显示的相同错误 -
Apache couldn't be started because port 8888 is in use by some other software.
...而且 MySQL 服务器没有启动。
I had no luck changing ports or moving the directory to htaccess.
我没有运气更改端口或将目录移动到 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...
我去Applications
,选择MAMP
,然后调出 Finder 的Get Info
对话。我Read & Write
为当前用户和管理员添加了权限,单击齿轮,然后单击Apply to enclosed items...
I did the same for the MAMP Pro, just to make sure my bases were covered.
我为 MAMP Pro 做了同样的事情,只是为了确保我的基地被覆盖。
Started up MAMP, changed the ports to default, and boom! Everything working, including MySQL Server - no Terminal commands required.
启动 MAMP,将端口更改为默认值,然后繁荣!一切正常,包括 MySQL 服务器 - 不需要终端命令。
This continued to work successfully when I changed my directory back to a /Users/myuser/Sites/
folder, as well.
当我将目录更改回/Users/myuser/Sites/
文件夹时,这也继续成功。
回答by faucher-bscg
If no MySQL instance is running, it is probably permission issue.
Right click on the icon -> run as administrator
.
如果没有 MySQL 实例正在运行,则可能是权限问题。右键单击该图标-> run as administrator
。
回答by Daniel
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.
我的意思不是微不足道,但是当这发生在我身上时,我开始尝试这里的一些建议(权限等),但是当我刚刚重新启动计算机时,它就可以工作了。所以只是提醒在尝试其他之前尝试重新启动。
回答by user1798533
Changing the Nginx port helped me.
更改 Nginx 端口对我有帮助。
回答by Nathan Rutman
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.
实际上,这只是一个直接的权限问题。我再次遇到了同样的问题,只是做了一个chown -R nathan:staff <dir>
并在 MAMP 中重新启动了 Apache。它工作得很好。
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).
奇怪的是,我想我在我的机器上解决了这个问题。在查看了默认 htdocs 目录和我想使用的目录的目录后,我注意到默认目录归nrutman:admin
我所有,而我想使用的目录归nrutman:staff
(同一用户,不同组)所有。
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.
通过 Finder 的“信息”面板 (Cmd-I),我向Administrators
文件夹添加了对该组的读/写权限并删除了人员组权限。我重新启动了 MAMP,一切正常!然后,通过chown
我将所有者更改回nrutman:staff
. Finder 的信息面板现在看起来和以前一样,但现在 MAMP 将使用该目录而不会抱怨端口。
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.
绝对看起来像一个 MAMP 错误。不太确定发生了什么,但我希望能帮助那些正在努力解决问题的人。