After upgrade to macOS Sierra Apache can't do start/stop/restart - macos

After upgrade to macOS Sierra Apache can't do start/stop/restart.
Errors:
AH00557: httpd: apr_sockaddr_info_get() failed for MacBook-Pro-N.local
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1. Set the 'ServerName' directive globally to suppress this message
I tried reinstall apache24 using home-brew. But it didn't fix my problem.
Also I configured httpd.conf, uncommented ServerName localhost. But it didn't help anyway.
Please, help.

try adding
127.0.0.1 MacBook-Pro-N.local
to your /etc/hosts file

Another solution is to change ServerName to localhost.
So first you need to find the location of your httpd.conf Apache configuration file by:
apachectl -t -D DUMP_INCLUDES
then edit it and uncomment or change the line with ServerName (make sure it has the valid server name or it exists in your /etc/hosts file). E.g.
ServerName localhost

Related

Why would apache refuse connection to localhost 127.0.0.1 on OSX?

When trying to access sites on my localhost the connection is refused. Two days ago the set up was working without issues with multiple virtual hosts configured. I'm not aware of any changes that could have affected the set up. I spent all day yesterday trying to troubleshoot the issue but have been going around in circles.
OS: OSX 10.11.16
httpd -V returns this:
Server version: Apache/2.4.18 (Unix)
Server built: Feb 20 2016 20:03:19
Server's Module Magic Number: 20120211:52
Server loaded: APR 1.4.8, APR-UTIL 1.5.2
Compiled using: APR 1.4.8, APR-UTIL 1.5.2
Architecture: 64-bit
Server MPM: prefork
threaded: no
forked: yes (variable process count)
Server compiled with....
-D APR_HAS_SENDFILE
-D APR_HAS_MMAP
-D APR_HAVE_IPV6 (IPv4-mapped addresses enabled)
-D APR_USE_FLOCK_SERIALIZE
-D APR_USE_PTHREAD_SERIALIZE
-D SINGLE_LISTEN_UNSERIALIZED_ACCEPT
-D APR_HAS_OTHER_CHILD
-D AP_HAVE_RELIABLE_PIPED_LOGS
-D DYNAMIC_MODULE_LIMIT=256
-D HTTPD_ROOT="/usr"
-D SUEXEC_BIN="/usr/bin/suexec"
-D DEFAULT_PIDLOG="/private/var/run/httpd.pid"
-D DEFAULT_SCOREBOARD="logs/apache_runtime_status"
-D DEFAULT_ERRORLOG="logs/error_log"
-D AP_TYPES_CONFIG_FILE="/private/etc/apache2/mime.types"
-D SERVER_CONFIG_FILE="/private/etc/apache2/httpd.conf"
httpd.conf is configured to allow virtual hosts and nothing has changed in httpd-vhosts.conf file.
LoadModule vhost_alias_module libexec/apache2/mod_vhost_alias.so
...
# Virtual hosts
Include /private/etc/apache2/extra/httpd-vhosts.conf
apachectl configtest returns:
Syntax OK
I've tried running a port scan for 127.0.0.1 and http port 80 does not show. This and the connection being refused makes me think this is where the issue is but I don't know why. The OSX firewall is turned off. I've tried the solution posted here but it did not fix it.
My /etc/hosts file looks like this:
#
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting. Do not change this entry.
#
127.0.0.1 localhost
255.255.255.255 broadcasthost
::1 localhost
fe80::1%lo0 localhost
127.0.0.1 site.local
127.0.0.1 othersite.local
...
I can ping 127.0.0.1. I previously had homebrew installed to run different PHP versions but I've removed that to try and bring the system back to stock. I really don't know what to try next, any help would be really appreciated.
It happened to me while upgrading php. Below steps worked for me to bring me back on track.
Generally, mac creates a back-up before upgrading. Hence, we'll be using the pre-update version of httpd.conf
cd /etc/apache2/
sudo mv httpd.conf httpd.conf-afterupdate
sudo mv httpd.conf.pre-update httpd.conf
sudo apachectl configtest
sudo apachectl restart
You could check to ensure you have Listen: 80 in your /usr/local/etc/apache2/2.4/httpd.conf configuration file.
After several days of trying to debug this I resolved it by overwriting my httpd.conf file with an older one that was created when upgrading to osx elcapitan.
sudo cp httpd.conf~elcapitan httpd.conf
After doing this localhost was accessible again. I don't know what was wrong with my previous httpd.conf file. I'd been through it many times looking for issues and never found any. I even diffed the two files to try and see where the problem was and found no reason why it would fail in the way it was.
Once I had localhost responding again I went through the process of enabling the modules I require and reconfiguring my virtual hosts.
Again, I don't know what was wrong with the other httpd.conf file. Perhaps it was corrupted in some way. Regardless it was failing silently with apachectl configtest not reporting any problems.
So if others have a similar issue it may be worth reverting back to an older httpd.conf file. OSX usually creates a backup when upgrades are done.
In my case DocumentRoot in the httpd.conf file was wrong.
I figured it out after typing httpd in the terminal. Try the same maybe it can give you some hints to solve the problem.
➜ ~ httpd
AH00526: Syntax error on line 255 of /usr/local/etc/httpd/httpd.conf:
DocumentRoot '/Users/xx/Desktop/sites' is not a directory, or is not readable

DNSMasq Not Resolving Addresses on Mac Local Web Development Environment

I've setup my local web development environment according to -http://mallinson.ca/osx-web-development/. I have done this before, and I got on a new computer, and am trying to do it again. I'm running Apache 2.4.9 on Mac OS X Yosemite 10.10.2 and directing the DNS with dnsmasq.
When I try to go to home.dev, it received this error:
Error code: ERR_NAME_NOT_RESOLVED
When I run scutil --dns, it seems to resolve it correctly as:
resolver #3
domain : dev
nameserver[0] : 127.0.0.1
flags : Request A records, Request AAAA records
reach : Reachable,Local Address
However, when I:
ping -c 1 home.dev
I get
ping: cannot resolve home.dev: Unknown host
Here is my reference to it in vhosts:
<VirtualHost *:80>
VirtualDocumentRoot "/Volumes/Work/Home/www"
ServerName home.dev
UseCanonicalName Off
</Virtualhost>
I think it was a change from Maverick's to Yosemite. In Yosemite, I had to add "port 35353" to the /etc/resolver files as well as as the config file for DNSmasq. I know for a fact I didn't originally do that, and it originally worked, so there was a change somewhere in there that broke it. Possibly also from a newer version of DNSmasq.
To make this work, I had to add a 127.0.0.1 DNS entry in my Network Preferences.

VirtualHosts does not work on Mac OS 10.7

I want to create VirtualHosts on Mac OS 10.7 and therefore I edited the /etc/apache2/httpd.conf. I uncommented the line "Include /private/etc/apache2/extra/httpd-vhosts.conf" to include the virtual hosts. In the file /private/etc/apache2/extra/httpd-vhosts.conf I wrote the following:
NameVirtualHost *:80
<VirtualHost *:80>
DocumentRoot "/var/www"
ServerName localhost
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "/var/www/someFolder"
ServerName myApplication.dev
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "/var/www/someOhterFolder"
ServerName myApplication2.dev
</VirtualHost>
There were two example virtual hosts before which I deleted. In my /etc/hosts file I added the following:
127.0.0.1 myApplication.dev
127.0.0.1 myApplication2.dev
I restarted my Apache and typed myApplication.dev and myApplication2.dev in the browser but I get an error "server not found" and it makes www.myApplication.dev in the browser (the same for myApplication2.dev).
Did I forget something to configure? I activated PHP in httpd.conf, mysql is installed also, but that has nothing to do with virtual hosts, I think.
Thanks for your help!
apachectl has an option -S to check vhost.conf file syntax. You can find these lines in vhosts.conf file.
> # You may use the command line option '-S' to verify your virtual host
> # configuration.
So, when you run
sh-3.2# apachectl -S
if you get Syntax OK result it means that there is no problem in your vhosts.conf file.
httpd: VirtualHost configuration:
wildcard NameVirtualHosts and _default_ servers:
*:80 is a NameVirtualHost
default server zz.xxxx.com (/private/etc/apache2/extra/httpd-vhosts.conf:27)
port 80 namevhost zz.xxxx.com (/private/etc/apache2/extra/httpd-vhosts.conf:27)
port 80 namevhost yy.xxxx.com (/private/etc/apache2/extra/httpd-vhosts.conf:35)
Syntax OK
If conf file has any problem it will tell you error line(s) like
sh-3.2# apachectl -S
Syntax error on line 33 of /private/etc/apache2/extra/httpd-vhosts.conf:
CustomLog takes two or three arguments, a file name, a custom log format string or format name, and an optional "env=" clause (see docs)
make sure that your vhosts.conf file has true configuration.
I had the exact same problem using OS X Lion. I fixed it by adding "::1 myhost.dev" to /etc/hosts:
127.0.0.1 myhost.dev
::1 myhost.dev
Incidentally, the ::1 also fixes a bug that makes page loading very slow on virtual hosts served from the Mac.
Are you using an HTTP proxy? If so, make an exception for myApplication.dev and myApplication2.dev.
What I meant was that the problem "server mot found" means that your browser cannot find the ip adresses of the hosts "myapplication.dev". This may be because you're using an http proxy, possibly one configured by your hosting company. In any case, you don't even reach the server, so you never get to try the virtual host configuration at all.
To just try the virtual host configuration, you can use telnet in a Terminal window and talk HTTP directly to the server, like this:
yourmacbox:~ yourname$ telnet 127.0.0.1 80
You should see the following text:
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.
Then you type
GET / HTTP/1.0
Host: myApplication.dev
Now, hopefully you should see some response from your web server. This shows that once you can connect to it, the virtual hosts things works.
I had the same problem, and noticed that the ServerRoot "/usr" was set as shown and incorrectly after the 10.7 upgrade. The httpd.conf file was still under /etc/apache2, but this setting in it was pointing to the wrong place. Once I had fixed that by changing to ServerRoot "/etc/apache2", all my previous virtual host configuration got picked up properly.
I also had to re-enable virtual hosts by uncommenting line 477 as mentioned here http://brettterpstra.com/fixing-virtual-hosts-and-web-sharing-in-mountain-lion/ That didn't quite kick in until I had fixed the path issue above.

Can't get my Vhosts back running after Mac OS X Lion upgrade

After upgrading my MacBook Pro to Mac OS X Lion I am not able anymore to get my 'Zend Server' running like before. At first the 'Zend Server' gave me servile errors by starting it from the command line. I fix this by doing a complete new installation of Zend Server.
After this new installation Zend Server runs fine and no problems at all. So now I want to put back my zend projects. I made a backup of my vhost file and put it back, it seems to be Lion didn't touch my host file so I didn't touch either (just checked). I did the follow things;
Put one of my vhosts back in conf/extra/httpd-vhosts.conf (just one to check).
Uncomment the vhost include in conf/httpd.conf
Checked my host file
Restart zend server from command line
After this I still cant reach the project by browsing to http://foo.localhost:10088/
Vhosts
<VirtualHost *:10088>
ServerAdmin my#email.com
SetEnv APPLICATION_ENV "development"
DocumentRoot "/Users/nicky/Zend/workspaces/DefaultWorkspace7/foo/public"
ServerName foo.localhost
ErrorLog "/Users/nicky/Zend/workspaces/foo-log"
CustomLog "/Users/nicky/Zend/workspaces/foo-log" common
</VirtualHost>
Hosts
127.0.0.1 localhost
127.0.0.1 dummy-host.example.com
127.0.0.1 dummy-host2.example.com
127.0.0.1 foo.localhost
I am not sure if this can have effect on the problem, but by restarting zend from the
command line, i get the follow:
MacBook-Pro-van-Nicky-Klaasse:~ nickyklaasse$ sudo /usr/local/zend/bin/zendctl.sh
restarthttpd: Could not reliably determine the server's fully qualified domain name,
using MacBook-Pro-van-Nicky-Klaasse.local for ServerName
Regards,
Nicky
I've had similar problems as well with that. I've been searching around for an answer, found some solutions but none of them seemed to work.
The only thing that finally made it working (not even sure how it actually helped), is going into system preferences -> sharing and enabling web sharing. That is normally starting your apache2 server but I wasn't using the default one, I am running another apache2 process with a different httpd configuration. Anyway, after starting it and stopping it (from the system preferences window), it seemed like it was working.
One thing that could be useful is checking your error_log as well as the access_log in /var/log/apache2/. Check the access_log to see what is the address trying to be resolved. At first, whenever I was making a request on my website through the Virtual Host, in my access log I only had 127.0.0.1 which is incorrect. After it worked, I can see that the requests are www.example.com and not the localhost, showing that the virtual host is indeed working.
Not sure if that will help you, give it a try, paste the access_log and error_log latest lines to see where there could be a problem.

apache not running on windows 7

I have an issue on my windows 7, I want to work on php so i tried everything but can not get it done. It always gives
Unable to connect
Firefox can't establish a connection to the server at nazar-studio:8080.
These are the things i had tried:
Installed WAMP
Installed XAMPP
Installed Apache
Installed IIS
stoped the http service
blocked anti-virus
un-installed anti-virus
stoped skype
Also tried this link
and there are many other things i had done, but invain.
When i check the port using netstat -an it shows the ports listening, i tried many different ports, but nothing works.
Can any one help me, I am really struck and frustrated due to it.
Have you tried connecting to localhost rather than 'nazar-studio'?
Are you sure its running on port 8080?
Is there possibly another process running on port 8080?
Have you checked the error logs? (in #apache install dir#/logs/)
To get Apache running on Windows 7 I did the following.
Switch to Administrator:
Open a command prompt as Admin, type net user Administrator /active:yes and then log off. At the log on screen you will see two options, log in as Administrator.
Install Apache.
Edit conf file to how you want.
Make sure you have set Listen to 8080 (I have mine left as 80).
Don't forget to LoadModule for PHP. Set the ServerName to localhost:8080 (again I have mine as 80).
Set DocumentRoot to the htdocs folder where you installed Apache - mine is C:\Program Files\Apache\2.0.40\htdocs. By connecting to localhost:80 you should be able to see the Apache welcome screen.
Add type info for PHP (AddType application/x-httpd-php .php .phtml .php3).
Create a virtual host. I am guessing yours would look like
<VirtualHost *:8080>
ServerName nazar-studio.localhost
DocumentRoot "C:/Develop/nazar/htdocs"
ServerAdmin webmaster#localhost
DirectoryIndex index.php index.html index.htm
ErrorLog logs/error.nazar.log
CustomLog logs/access.nazar.log combined
</VirtualHost>
Now Edit your hosts file in C:\Windows\System32\drivers\etc and add the subnets you have added:
127.0.0.1 localhost
127.0.0.1 nazar-studio.localhost
127.0.0.1 test.localhost
Open the command prompt and now type net user Administrator /active:no to disable the admin. Log off and reconnect as you.
Start Apache and you should be able to connect.

Resources