简体   繁体   中英

Localhost configuration mac sierra

Problem: Ever since I upgraded to Sierra I can't connect to 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! 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. 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. -I upgraded to php7. So I now have php5 and php7 installed. -I have set up a username.conf (And of course I swapped out username for my actual user name)

<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,

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,

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!" page was loading, very strange.

The DocumentRoot in httpd.conf is /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!" and when I type "localhost/~username" it should say "Welcome from your user directory". 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

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

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

/usr/bin/php

which mysql

/usr/local/mysql/bin/mysql

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

/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.

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/

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. 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!' 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.

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

Perform apachectl restart , again, with sudo privileges. If the problem still persists run apachectl configtest and paste contents in here somewhere.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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