“Wait a moment, you’re using Homebrew?”, you say Dear Reader? “If you are using Homebrew, shouldn’t we use the copy of the Apache that comes with Homebrew?”, you say?
It’s a viable alternative. Just like with PHP and other things, using a package manager like Homebrew to install the web server in user space means that you can keep up a lot more rapidly with upstream changes in Apache. Down side is you have to undo some things in the system and remember to confirm and redo these things when you update macOS.
Let’s go about it… we need to turn off the version of Apache included in the operating system:
sudo apachectl stop
sudo launchctl unload -w /System/Library/LaunchDaemons/org.apache.httpd.plist 2>/dev/null
This turns off the server and unloads the system install of Apache from the list of services loaded at system startup.
Now we get things up and running with Homebrew:
brew install httpd
brew services start httpd
One more configuration adjustment: to keep things somewhat clean, Homebrew’s Apache installer defaults to run on port 8080 rather than port 80. This avoids conflicts issues between the system install of Apache and the Homebrew version. But we want the Homebrew version to server pages on the default port.
How to fix this, edit /opt/homebrew/etc/httpd/httpd.conf
to switch the listen port to port 80. Use your favorite edit to find the Listen
line in the file and make certain it looks like this:
Listen 8080
Now restart the server using brew services restart httpd
.
An opinion
There is a common thread among the different blogs telling you how to do this that recommends you reset the server root to the Sites
folder in your home folder. This is not something I recommend you to do as I believe you need to have a separation between production and development code. Feel free to reconfigure Apache in this manner as you wish but I’ll leave figuring how to do this to be an exercise for the reader.
Do go back and apply the changes I introduced in Part 1 of this series to get your home folder configured. All you need to do is adjust the files names to use the configuration files in your Homebrew install.