简体   繁体   English

Localhost配置Mac Sierra

[英]Localhost configuration mac sierra

Problem: Ever since I upgraded to Sierra I can't connect to localhost. 问题:自从升级到Sierra以来,我无法连接到localhost。 I was using MAMP previously but it stopped working once I upgraded, when I couldn't get the mysql working again I decided to set up the default localhost with apache/php/mysql, but it's been almost a week now and I can't seem to get the configuration right! 我以前使用过MAMP,但是升级后它停止工作,当我无法再次使mysql工作时,我决定使用apache / php / mysql设置默认的localhost,但是已经快一个星期了,我不能似乎配置正确! At a complete loss with the whole thing, at this point and any help would be more than greatly appreciated. 在此之前,不惜一切代价,并且提供任何帮助将不胜感激。

What I've done so far.. 到目前为止我做了什么

-Removed all instances of MAMP including removing it from .bash_profile. -删除了MAMP的所有实例,包括从.bash_profile中删除了它。 My PATH now looks like this, 我的路径现在看起来像这样,

export PATH="/usr/local/mysql/bin:$PATH"

-I installed mysql and can turn it on and off via the systems preferences panel. -我安装了mysql,可以通过“系统偏好设置”面板将其打开和关闭。 -I upgraded to php7. -我升级到php7。 So I now have php5 and php7 installed. 所以我现在安装了php5和php7。 -I have set up a username.conf (And of course I swapped out username for my actual user name) -我已经设置了一个username.conf(当然,我将用户名换成了我的实际用户名)

<Directory "/Users/username/Sites/">
Options Indexes MultiViews
AllowOverride All
Order allow,deny
Allow from all
</Directory>

-I setup a vhost, -我设置了虚拟主机,

<VirtualHost *:80>
DocumentRoot "/Users/username/Sites"
ServerName localhost
</VirtualHost>

-I uncommented in httpd.conf, -我在httpd.conf中没有评论,

LoadModule userdir_module libexec/apache2/mod_userdir.so
LoadModule include_module libexec/apache2/mod_include.so
LoadModule rewrite_module libexec/apache2/mod_rewrite.so
LoadModule cgi_module libexec/apache2/mod_cgi.so
LoadModule php5_module libexec/apache2/libphp5.so
Include /private/etc/apache2/extra/httpd-userdir.conf
LoadModule vhost_alias_module libexec/apache2/mod_vhost_alias.so

-Uncommented in httpd-userdir.conf, -在httpd-userdir.conf中未注释,

Include /private/etc/apache2/users/*.conf

Before the vhost changes I could access "It Worked!" 在更改虚拟主机之前,我可以访问“它起作用了!”。 in the browser but now it says 在浏览器中,但现在它说

localhost refused to connect. 本地主机拒绝连接。

I also tried moving one of my projects to the Documents folder and just working on it from the default "localhost" without using the username.conf, but I couldn't get the project to open even though the "It Works!" 我还尝试了将我的项目之一移至Documents文件夹,并且仅使用默认的“ localhost”在不使用username.conf的情况下进行处理,但是即使“ It Works!”,我也无法打开项目。 page was loading, very strange. 页面正在加载,非常奇怪。

The DocumentRoot in httpd.conf is /Library/WebServer/Documents httpd.conf中的DocumentRoot是/ Library / WebServer / Documents

I don't want to change this to /Users/username/Sites (as I have previously) because I want to use the username.conf to access to directory, for example: when I type "localhost" in the browser it should say "It Works!" 我不想将其更改为/ Users / username / Sites(如我之前所述),因为我想使用username.conf来访问目录,例如:当我在浏览器中键入“ localhost”时,应该说“有用!” and when I type "localhost/~username" it should say "Welcome from your user directory". 当我键入“ localhost /〜username”时,应该显示“欢迎从您的用户目录”。 I know this must be so simple and there's probably just one small change I need to make, does anyone have any idea what I'm doing wrong? 我知道这一定很简单,可能只需要做一个小改动,有人知道我在做什么错吗?

What I get in the terminal: 我在终端中得到什么:

httpd -v httpd -v

Server version: Apache/2.4.23 (Unix)
Server built:   Aug  8 2016 16:31:34

apachectl -S apachectl -S

VirtualHost configuration:
*:80                   is a NameVirtualHost
         default server localhost (/private/etc/apache2/extra/httpd-vhosts.conf:24)
         port 80 namevhost localhost (/private/etc/apache2/extra/httpd-vhosts.conf:24)
         port 80 namevhost dummy-host.example.com (/private/etc/apache2/extra/httpd-vhosts.conf:29)
                 alias www.dummy-host.example.com
         port 80 namevhost dummy-host2.example.com (/private/etc/apache2/extra/httpd-vhosts.conf:38)
ServerRoot: "/usr"
Main DocumentRoot: "/Library/WebServer/Documents"
Main ErrorLog: "/private/var/log/apache2/error_log"
Mutex mpm-accept: using_defaults
Mutex proxy-balancer-shm: using_defaults
Mutex rewrite-map: using_defaults
Mutex proxy: using_defaults
Mutex default: dir="/private/var/run/" mechanism=default 
PidFile: "/private/var/run/httpd.pid"
Define: DUMP_VHOSTS
Define: DUMP_RUN_CFG
User: name="_www" id=70 not_used
Group: name="_www" id=70 not_used

which php 哪个PHP

/usr/bin/php

which mysql 哪个mysql

/usr/local/mysql/bin/mysql

php -v 的PHP -V

PHP 5.6.25 (cli) (built: Sep  6 2016 16:37:16) 
Copyright (c) 1997-2016 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies

echo $PATH 回声$ PATH

/usr/local/mysql/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin

..So as you can see the localhost isn't being picked up by apache. ..因此您可以看到apache并未占用localhost。

I have worked through numerous post solutions but nothing seems to get things working. 我已经完成了许多后期解决方案,但似乎没有任何事情可以解决。 I have also reset everything back to the default settings and worked through making the changes again to see if I missed anything, but no luck. 我还将所有内容重置为默认设置,并通过再次进行更改来查看是否错过了任何内容,但是没有运气。

I didn't want to change anything in the "hosts" file just in case I messed everything up, is that the step I'm missing? 我不想更改“主机”文件中的任何内容,以防万一我搞砸了一切,这是我所缺少的步骤吗?

(It seems I can only post two links here, but obviously I have worked through a lot more questions/tutorials than this!)These two seem like they should be able to solve the problem though. (似乎我只能在此处发布两个链接,但是显然我已经解决了很多问题/教程!)这两个似乎可以解决问题。 Apache localhost/~username/ not working https://coolestguidesontheplanet.com/get-apache-mysql-php-and-phpmyadmin-working-on-macos-sierra/ Apache localhost /〜用户名/不起作用 https://coolestguidesontheplanet.com/get-apache-mysql-php-and-phpmyadmin-working-on-macos-sierra/

Thanks again for your time and I hope someone out there can point me in the right direction. 再次感谢您的宝贵时间,我希望外面有人可以向我指出正确的方向。

If still relevant. 如果仍然相关。 If you are simply trying to setup localhost without simulation tools, such as to simulate other servers, etc., there is no need to even look into virtual hosts. 如果您只是尝试在不使用模拟工具(例如模拟其他服务器等)的情况下设置localhost,则甚至无需查看虚拟主机。 By default, localhost is listening to port 80, and it's practically ready for you to use, you only need to specify who can access it and, of course, don't forget to apachectl start the apache with sudo mode, which I thought weird, since to get localhost working you only need to start apache and it should say 'It works!' 默认情况下,localhost正在监听端口80,并且几乎可以使用它,您只需要指定可以访问它的人即可,当然,不要忘了apachectl start以sudo模式apachectl start apache,我认为这很奇怪,因为要使localhost工作,您只需启动apache,它应该显示“ It works!”。 right after you go into the browser. 在您进入浏览器后。

Where you specify user directory watch out for the version of apache you are using, so for Siera your username.conf should look like this. 在指定用户目录的位置,请注意所使用的apache的版本,因此对于Siera,您的username.conf应该如下所示。

<Directory "/Users/username/Sites/">
  Options Indexes MultiViews FollowSymLinks
  AllowOverride All
  Require all granted
</Directory>

Perform apachectl restart , again, with sudo privileges. 再次使用sudo特权执行apachectl restart If the problem still persists run apachectl configtest and paste contents in here somewhere. 如果问题仍然存在,请运行apachectl configtest并将内容粘贴到此处的某个位置。

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

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