简体   繁体   English

如何使用 apache 修复此 localhost 连接错误?

[英]How do I fix this localhost connection error with apache?

First of all, my apologies for the vague title.首先,我为模糊的标题道歉。 If anyone has any ideas for how I could have made the title more descriptive after reading the post I appreciate it.如果有人对我在阅读帖子后如何使标题更具描述性有任何想法,我将不胜感激。 I'm pretty inexperienced with this whole thing so I appreciate any and all help.我对这整件事非常缺乏经验,所以我很感激任何和所有的帮助。

I am trying to use PhpMyAdmin with Apache to connect to MySQL on macOS Big Sur 11.6.7.我正在尝试使用 PhpMyAdmin 和 Apache 在 macOS Big Sur 11.6.7 上连接到 MySQL。 I successfully installed MySQL and MySQL Workbench to make sure that it was working.我成功安装了 MySQL 和 MySQL Workbench 以确保它正常工作。 I ran into the problem that when I got to typing localhost in the browser, I got the message "It works,," but I couldn't, for the life of me, figure out how to get php code to run on the webpage.我遇到了一个问题,当我在浏览器中输入 localhost 时,我收到了“它可以工作”的消息,但我终其一生都无法弄清楚如何让 php 代码在网页上运行. and instead it printed on the page, I tried a bunch of things, including uncommenting the line that allows Apache to use PHP.相反,它打印在页面上,我尝试了很多事情,包括取消注释允许 Apache 使用 PHP 的行。 making sure DirectoryIndex included index,php.确保 DirectoryIndex 包含索引,php。 etc: Right now I'm receiving the following error when I try anything:等:现在我在尝试任何事情时收到以下错误:

AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using maverick-02.local. Set the 'ServerName' directive globally to suppress this message

I've been getting this message everywhere and defining the ServerName variable in the httpd.conf file doesn't seem to change anything.我到处都收到这条消息,在 httpd.conf 文件中定义 ServerName 变量似乎没有任何改变。 Now when I refresh the localhost page, it says that it can't connect to the server "localhost".现在,当我刷新 localhost 页面时,它说它无法连接到服务器“localhost”。 However, if I refresh again, it goes back to the "It Works" message.但是,如果我再次刷新,它会返回到“It Works”消息。 When I refresh again, it can't connect.当我再次刷新时,它无法连接。 Back and forth and back and forth.来回来回。 And my test.php file which was just printing out the code now cannot connect at all.我的 test.php 文件刚刚打印出代码,现在根本无法连接。

Does anyone have any ideas;有没有人有任何想法? is there anything else that I can add that would be helpful to better understand my problem?还有什么我可以添加的内容有助于更好地理解我的问题吗?

Thank you all!谢谢你们!

Edit: I forgot to mention a couple things about what I tried.编辑:我忘了提及我尝试过的几件事。 I know that MacOS comes with Apache and PHP preinstalled, at least for now.我知道 MacOS 预装了 Apache 和 PHP,至少现在是这样。 I decided that I didn't know what was going on and so I decided to reinstall Apache with Brew.我决定我不知道发生了什么,所以我决定用 Brew 重新安装 Apache。 I don't know if that was a good idea or not because now I don't know what's going on, and the problems seemed to get worse after I tried that (ie, the index.html file always displayed beforehand, in addition to the test.php code, both of which have been at least a little bit messed up).我不知道这是否是一个好主意,因为现在我不知道发生了什么,并且在我尝试之后问题似乎变得更糟(即 index.html 文件总是预先显示,除了test.php 代码,两者都至少有点混乱)。 I'd also be willing to try deactivating Apache and starting totally anew, but I don't know if that makes sense.我也愿意尝试停用 Apache 并重新开始,但我不知道这是否有意义。

Edit 2: I managed to get rid of the error message that I mentioned above.编辑 2:我设法摆脱了上面提到的错误消息。 The problem, of course, was that I hadn't defined a global value for ServerName.当然,问题在于我没有为 ServerName 定义全局值。 I had done it in /etc/apache2/httpd,conf, but because I had mixed everything up by installing httpd on Brew, the httpd folder it recognized was in a different place.我在 /etc/apache2/httpd,conf 中完成了它,但是因为我通过在 Brew 上安装 httpd 把所有东西都搞混了,所以它识别的 httpd 文件夹位于不同的位置。 one that indeed did not have any globally defined ServerName variable, So I Brew uninstalled httpd, and the message went away.一个确实没有任何全局定义的 ServerName 变量,所以我 Brew 卸载了 httpd,消息消失了。 but nothing else happened.但没有其他事情发生。 Still stuck on the exact same issues as before.仍然停留在与以前完全相同的问题上。

Reinstalling any Apache2 instances should fix the problem.重新安装任何 Apache2 实例应该可以解决问题。 It is almost certain you have multiple instances on your OS, removing them all, and reinstalling should fix the issue.几乎可以肯定您的操作系统上有多个实例,将它们全部删除,然后重新安装应该可以解决问题。

Hopefully it helps!希望它有帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM