Issue
Background
I followed the instructions here to configure Apache, PHP, and MySQL on my Mac (running Sierra 10.12.4) and got everything working fine. I then used Migration Assistant to copy everything over to a new Mac (Mac #2) for another developer to use. On first login, I opened Chrome and visited localhost
. I did not make any changes to Mac #2 beforehand.
The Problem
On Mac #2, when I visit localhost
in Chrome, I get an ERR_CONNECTION_REFUSED
(This site can't be reached: localhost refused to connect). Some digging led me to this Q/A on Apple Stack Exchange, so I tried the following in Terminal:
ping 127.0.0.1
(success; i.e., "64 bytes from 127.0.0.1...")ping localhost
(success)ping myvirtualhost.dev
(success)
The Plot Thicks
I then tried to run apachectl configtest
, which threw the following error:
/usr/local/bin/apachectl: line 79: 1132 Illegal instruction: 4 $HTTPD -t
Ok, how about sudo apachectl -k restart
? Nope, same error:
/usr/local/bin/apachectl: line 79: 1170 Illegal instruction: 4 $HTTPD "$@"
Omitting the -k
flag throws the same error, but the last characters are a bit different:
/usr/local/bin/apachectl: line 79: 1184 Illegal instruction: 4 $HTTPD -k $ARGV
What I've Tried
I can't stop, start, restart, or really do anything with Apache. Google searching the error doesn't bring up much. I've tried restoring the httpd.conf
from the backup I had, then restarting my computer. I checked /etc/hosts
and it looks normal. I'm not sure what else to do.
Apache's config is messed up somehow but I'm not sure where. What should I do?
Other Potentially Useful Info
Running httpd -v
in Terminal yields:
Server version: Apache/2.4.25 (Unix)
Typing php -v
in Terminal yielded:
Illegal instruction: 4
So I reinstalled and now php -v
yields:
PHP 5.6.30 (cli) (built: Apr 7 2017 13:12:17)
Typing which php
yields:
/usr/local/bin/php
Solution
In my case, it had to do with the php binary loaded in the 'other' conf file:
Try running:
sudo mv /private/etc/apache2/other/+php-osx.conf /private/etc/apache2/other/+php-osx.conf-bak
And then restart apache
If you don't have this conf file, it is most likely the php binary that is being loaded on your system that is causing the issue because the error is very similar to what I saw.
Answered By - CLL Answer Checked By - Mildred Charles (WPSolving Admin)