Why doesn't homebrew apache start at startup? - macos

I’m trying to figure out why my apache doesn’t start at startup… (I would like for it to).
My OS: OSX Mojave
Impressions I’m under: that I’m running homebrew’s apache
Upon a fresh boot…
If I hit http://localhost in a browser I get
Unable to connect
Firefox can’t establish a connection to the server at localhost.
Fire up terminal…
$brew services list
returns
httpd started bigpimpin /Users/bigpimpin/Library/LaunchAgents/homebrew.mxcl.httpd.plist
php started bigpimpin /Users/bigpimpin/Library/LaunchAgents/homebrew.mxcl.php.plist
(That first line makes me think httpd is running and I should be able to hit localhost).
$which -a apachectl
returns
/usr/local/bin/apachectl
/usr/sbin/apachectl
then
$apachectl configtest
returns
Syntax OK
then
$sudo apachectl -V
returns (among other things)
-D SERVER_CONFIG_FILE="/usr/local/etc/httpd/httpd.conf"
(Isn’t this brew’s httpd.conf?)
There's a brew command (which I forget) that I already ran that is supposed to run httpd at startup.
Once I run
$sudo apachectl start
everything is jake. So it’s a low-priority question, but one I would like to solve and understand.

I had the same issue with Homebrew NGINX.
Running the brew services command with sudo solved the problem for me.
It appears that the Homebrew web-server packages require sudo to start | stop | restart.
Try running:
sudo brew services start apache2

Related

Error starting homebrew apache service from command line (mac) [duplicate]

I'm still having some problems on using httpd (aka Apache2) after the update of my MacOs on BigSur.
I tried to make a clean reinstall of apache2 using the brew httpd services (like said in a lot of tutorials) but it still not working. I make a summary of the steps taked and I'll add some debug command.
To reinstall I done:
sudo apachectl stop
sudo launchctl unload -w /System/Library/LaunchDaemons/org.apache.httpd.plist 2>/dev/null
brew install httpd
After that I reboot and launched the command:
brew services start httpd
==> Successfully started `httpd` (label: homebrew.mxcl.httpd)
But if I run the following command:
brew services list
Name Status User Plist
dnsmasq started root /Library/LaunchDaemons/homebrew.mxcl.dnsmasq.plist
fuseki stopped
httpd error matteo.ceradini /Users/matteo.ceradini/Library/LaunchAgents/homebrew.mxcl.httpd.plist
mongodb-community started matteo.ceradini /Users/matteo.ceradini/Library/LaunchAgents/homebrew.mxcl.mongodb-community.plist
unbound stopped
As you can see the httpd is in an error status (in fact going to localhost:8080 I get an error) and I can't understand why.
Any suggestion how to fix this?
Thank you.
Something seems to not working, but still I can't find why.
I stopped all the services (either sudo brew and brew without sudo), and next running the commands:
sudo lsof -i :80
sudo lsof -i :8080
sudo lsof -i tcp:80
sudo lsof -i tcp:8080
the results is always nothing. But if I run:
sudo brew services start httpd
==> Successfully started `httpd` (label: homebrew.mxcl.httpd)
The httpd will not start (even if in the terminal command it says yes):
sudo brew services list
httpd error root /Library/LaunchDaemons/homebrew.mxcl.httpd.plist
And if I check the apachetl error I get always that the port 80 is occupied, even if there isn't processes on that port:
apachectl -e error
(48)Address already in use: AH00072: make_sock: could not bind to address 0.0.0.0:80
no listening sockets available, shutting down
AH00015: Unable to open logs
I urgently need to find a solution for this bug. It seems that in some httpd is corrupted, even if I uninstall and reinstall again
UPDATE:
I really don't know how I did it, but now it's working. I stopped all the brew httpd services and I restard apache using the command:
sudo apachectl -k start
and that worked for me
I just had exactly the same issue on Monterey. As digging in, it seems that the problem was a symbol not found ( _apr_bucket_alloc_aligned_floor ), expected in: /usr/lib/libaprutil-1.0.dylib.
Reinstalling apr-util fixed my case:
brew reinstall apr-util
FIRST ANSWER:
Sounds like the service started OK then later (or immediately) died, and reports an error. Using the command 'apachectl -e error' should provide details, but you'd wanna check the logs ('vi /usr/local/var/log/httpd/error_log', then shift-G [to goto end]).
SECOND (EXPLAINATION) ANSWER:
"
If you use (sudo) brew services ... to start httpd you have to use the proper (sudo) brew services list command to check the status:
If you start it as root then list it with root privs:
sudo brew services start httpd > sudo brew services list
or with user privs:
brew services start httpd > brew services list.
"
Judging by the result from sudo apachectl -e error, it cannot use port 8080 because another app is using it.
The first warning - can be ignored - or set the FQDN in httpd.conf. Usually this is in the '/usr/local/etc/httpd' folder. Edit with sudo vi /usr/local/etc/httpd/httpd.conf. (I like vi - use whatever you feel comfortable with - sudo open -e /usr/local/etc/httpd/httpd.conf is common).
The default config has the line #ServerName www.example.com:8080, remove that '#' and replace 'www.example.com:8080' with 'MBP-Matteo.local' - or whatever.
Type sudo lsof -i tcp:8080 to list all apps using port 8080, mostly only apps that LISTEN are important.
Next error: You must stop that other app which is using port 8080 (and prevent starting on boot) - or - set Apache to use a different port. (Note: If you choose a port lower than 1024, 'sudo' must be used to start the service.) Usually port 80 is devoted to Apache. The port to be used can be set by editing the config file, as above, then find the line 'Listen 8080', and replace 8080 with the desired port.
After the changes, try to start again with [sudo] 'brew services start httpd'. Then check with [sudo] 'brew services list'. Hopefully all works fine.
FIRST ANSWER: Sounds like the service started OK then later (or immediately) died, and reports an error. Using the command 'apachectl -e error' should provide details, but you'd wanna check the logs ('vi /usr/local/var/log/httpd/error_log', then shift-G [to goto end]).
The first command gives this result:
sudo apachectl -e error
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using MBP-Matteo.local. Set the 'ServerName' directive globally to suppress this message
(48)Address already in use: AH00072: make_sock: could not bind to address 0.0.0.0:8080
no listening sockets available, shutting down
AH00015: Unable to open logs
And the file '/usr/local/var/log/httpd/error_log' is empty
SECOND (EXPLAINATION) ANSWER: " If you use (sudo) brew services ... to start httpd you have to use the proper (sudo) brew services list command to check the status:
The results doesn't change if I executed brew commands with both sudo or without (given that previously I was using without sudo)
Any suggestions?
my solution, stop httpd service, then check httpd.conf and check DocumentRoot "/opt/homebrew/var/www"
<Directory "/opt/homebrew/var/www"> when returning to the original state this route, restart the httpd service and it worked without problems.
A simple brew reinstall httpd fixed it for me. All .conf files remained intact after reinstall for anyone wondering.

Clean reinstall and fix of httpd service error on macos

I'm still having some problems on using httpd (aka Apache2) after the update of my MacOs on BigSur.
I tried to make a clean reinstall of apache2 using the brew httpd services (like said in a lot of tutorials) but it still not working. I make a summary of the steps taked and I'll add some debug command.
To reinstall I done:
sudo apachectl stop
sudo launchctl unload -w /System/Library/LaunchDaemons/org.apache.httpd.plist 2>/dev/null
brew install httpd
After that I reboot and launched the command:
brew services start httpd
==> Successfully started `httpd` (label: homebrew.mxcl.httpd)
But if I run the following command:
brew services list
Name Status User Plist
dnsmasq started root /Library/LaunchDaemons/homebrew.mxcl.dnsmasq.plist
fuseki stopped
httpd error matteo.ceradini /Users/matteo.ceradini/Library/LaunchAgents/homebrew.mxcl.httpd.plist
mongodb-community started matteo.ceradini /Users/matteo.ceradini/Library/LaunchAgents/homebrew.mxcl.mongodb-community.plist
unbound stopped
As you can see the httpd is in an error status (in fact going to localhost:8080 I get an error) and I can't understand why.
Any suggestion how to fix this?
Thank you.
Something seems to not working, but still I can't find why.
I stopped all the services (either sudo brew and brew without sudo), and next running the commands:
sudo lsof -i :80
sudo lsof -i :8080
sudo lsof -i tcp:80
sudo lsof -i tcp:8080
the results is always nothing. But if I run:
sudo brew services start httpd
==> Successfully started `httpd` (label: homebrew.mxcl.httpd)
The httpd will not start (even if in the terminal command it says yes):
sudo brew services list
httpd error root /Library/LaunchDaemons/homebrew.mxcl.httpd.plist
And if I check the apachetl error I get always that the port 80 is occupied, even if there isn't processes on that port:
apachectl -e error
(48)Address already in use: AH00072: make_sock: could not bind to address 0.0.0.0:80
no listening sockets available, shutting down
AH00015: Unable to open logs
I urgently need to find a solution for this bug. It seems that in some httpd is corrupted, even if I uninstall and reinstall again
UPDATE:
I really don't know how I did it, but now it's working. I stopped all the brew httpd services and I restard apache using the command:
sudo apachectl -k start
and that worked for me
I just had exactly the same issue on Monterey. As digging in, it seems that the problem was a symbol not found ( _apr_bucket_alloc_aligned_floor ), expected in: /usr/lib/libaprutil-1.0.dylib.
Reinstalling apr-util fixed my case:
brew reinstall apr-util
FIRST ANSWER:
Sounds like the service started OK then later (or immediately) died, and reports an error. Using the command 'apachectl -e error' should provide details, but you'd wanna check the logs ('vi /usr/local/var/log/httpd/error_log', then shift-G [to goto end]).
SECOND (EXPLAINATION) ANSWER:
"
If you use (sudo) brew services ... to start httpd you have to use the proper (sudo) brew services list command to check the status:
If you start it as root then list it with root privs:
sudo brew services start httpd > sudo brew services list
or with user privs:
brew services start httpd > brew services list.
"
Judging by the result from sudo apachectl -e error, it cannot use port 8080 because another app is using it.
The first warning - can be ignored - or set the FQDN in httpd.conf. Usually this is in the '/usr/local/etc/httpd' folder. Edit with sudo vi /usr/local/etc/httpd/httpd.conf. (I like vi - use whatever you feel comfortable with - sudo open -e /usr/local/etc/httpd/httpd.conf is common).
The default config has the line #ServerName www.example.com:8080, remove that '#' and replace 'www.example.com:8080' with 'MBP-Matteo.local' - or whatever.
Type sudo lsof -i tcp:8080 to list all apps using port 8080, mostly only apps that LISTEN are important.
Next error: You must stop that other app which is using port 8080 (and prevent starting on boot) - or - set Apache to use a different port. (Note: If you choose a port lower than 1024, 'sudo' must be used to start the service.) Usually port 80 is devoted to Apache. The port to be used can be set by editing the config file, as above, then find the line 'Listen 8080', and replace 8080 with the desired port.
After the changes, try to start again with [sudo] 'brew services start httpd'. Then check with [sudo] 'brew services list'. Hopefully all works fine.
FIRST ANSWER: Sounds like the service started OK then later (or immediately) died, and reports an error. Using the command 'apachectl -e error' should provide details, but you'd wanna check the logs ('vi /usr/local/var/log/httpd/error_log', then shift-G [to goto end]).
The first command gives this result:
sudo apachectl -e error
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using MBP-Matteo.local. Set the 'ServerName' directive globally to suppress this message
(48)Address already in use: AH00072: make_sock: could not bind to address 0.0.0.0:8080
no listening sockets available, shutting down
AH00015: Unable to open logs
And the file '/usr/local/var/log/httpd/error_log' is empty
SECOND (EXPLAINATION) ANSWER: " If you use (sudo) brew services ... to start httpd you have to use the proper (sudo) brew services list command to check the status:
The results doesn't change if I executed brew commands with both sudo or without (given that previously I was using without sudo)
Any suggestions?
my solution, stop httpd service, then check httpd.conf and check DocumentRoot "/opt/homebrew/var/www"
<Directory "/opt/homebrew/var/www"> when returning to the original state this route, restart the httpd service and it worked without problems.
A simple brew reinstall httpd fixed it for me. All .conf files remained intact after reinstall for anyone wondering.

Can't change document root for apache 2.4

I want to set up local web server using Apache and PHP on my Mac running Sierra. I followed this tutorial:
https://getgrav.org/blog/macos-sierra-apache-multiple-php-versions
And I am stuck at changing the document root from httpd.config, for whatever reason this change does not take effect at all. If I type http://localhost it still says "It works", it still uses the original html file.
Another weird thing is that apparently I can't stop apache at all. I tried running
$ sudo apachectl stop
but I still can’t access http://localhost
if I run
$ brew services list
httpd24 is stopped. What gives? What am I doing wrong?
There is an instance of apache pre-installed with macOS. So you have now two versions of apache installed. If you check:
which apachectl
you will probably obtain:
/usr/sbin/apachectl
which is the official macOS version of apachectl. Stop it with:
sudo apachectl stop
Disable the auto-loading of the pre-installed apache with (as explained in the tutorial you mentioned):
sudo launchctl unload -w /System/Library/LaunchDaemons/org.apache.httpd.plist 2>/dev/null
To run the homebrew version do:
brew services run httpd24
to stop it:
brew services stop httpd24
to register it to launch at login:
brew services start httpd24

Apache Homebrew does not start on MacOS: No Path for Address

I'm having an issue with Homebrew Apache after using TimeMachine to transfer my system to another computer.
When I terminal "sudo apachectl start" I get this notification in the system.log:
httpd[4212]: no path for address 0x10ed15000
When I terminal "brew services start httpd24" I get:
com.apple.xpc.launchd[1] (homebrew.mxcl.httpd24[4370]): Service exited
with abnormal code: 1
When I terminal "sudo apachectl configtest" I get:
Syntax OK
There are no apache logs because it doesn't start. Homebrew tells me Httpd24 is running, however, it doesn't show in the Activity Monitor.
I'm not quite sure where to go from here, suggestions would be greatly appreciated
Tried a million things, the only way I was able to get Apache back up and running was to:
Remove Homebrew
Install Homebrew

I have 2 versions of Apache running on my system

There is another version of apache running on my system.
When in run sudo apachectl stop I still get the "It Works" page
So I found the location of the other version that is still running and it looks to be an older version which probably came pre-installed and is located in /opt/local/apache2/.
I tested this file /opt/local/apache2/htdocs/index.html.sample by just changing the text and then checked the browser again.
Server: Apache/2.2.29 (Unix)
I want to remove that one and keep the latest version which is located in private/etc/apache2
Server version: Apache/2.4.9 (Unix)
How can I do this safely.
I managed to fix this
I ran ps aux | grep apache to see the apache processes
I then ran sudo apachectl stop
Then sudo killall -9 httpd to kill all apache processes
Then sudo apachectl restart
I went to the browser and typed localhost~/username/sitename
Bingo it works again, my system is using the correct version of apache again!

Resources