Why did I switch to using brew to manage Apache on my Macbook?
Macbook comes with Apache pre-installed, but whenever I upgrade my Macbook to a new OS version, the upgrade process seems to overwrite my configuration file.
DocumentRoot is /usr/local/var/www.
The default ports have been set in /usr/local/etc/httpd/httpd.conf to 8080 and in
/usr/local/etc/httpd/extra/httpd-ssl.conf to 8443 so that httpd can run without sudo.
To have launchd start httpd now and restart at login:
brew services start httpd
Or, if you don't want/need a background service you can just run:
apachectl start
/usr/local/etc/httpd/httpd.conf
http://localhost:8080/
brew services start httpd
How did I install Apache onto my MacBook?
Apache is already pre-installed on my MacBook. I tried using the below commands to install Apache before I realized that it was pre-installed.
- brew install homebrew/apache/httpd24
- mkdir -p ~/Library/LaunchAgents
- ln -sfv /usr/local/opt/httpd24/*.plist ~/Library/LaunchAgents
- launchctl load ~/Library/LaunchAgents/homebrew.mxcl.httpd24.plist
- Edit the /usr/local/etc/apache2/2.4/httpd.conf
How can we configure the pre-installed Apache to start automatically?
sudo launchctl load -w /System/Library/LaunchDaemons/org.apache.httpd.plist
How can we prevent the pre-installed Apache from starting automatically?
sudo launchctl unload -w /System/Library/LaunchDaemons/org.apache.httpd.plist
Where is the configuration file for the pre-installed Apache?
/etc/apache2/httpd.conf
/private/etc/apache2/other
Where are the log files generated by the pre-installed Apache?
/private/var/log/apache2
What is the default DocumentRoot used by the pre-installed Apache?
/Library/WebServer/Documents
How can we check the syntax of the configuration file?
/usr/sbin/httpd -S
apachectl configtest
How can we stop Apache?
apachectl stop
How can we start Apache?
apachectl start