https://developer.apple.com/xcode/
xcode-select --install
This command will instrall Homebrew:
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
And this one will add missing libraries required for Mojave:
brew install openldap libiconv
The version of Apache included in macOS isn't always reliably updated with OS updates, so using Brew ensures that you'll run an updated version (that remains updated).
Shutdown and disable the existing version of Apache:
First: sudo apachectl stop
Then: sudo launchctl unload -w /System/Library/LaunchDaemons/org.apache.httpd.plist 2>/dev/null
Install Brew's version of Apache
brew install httpd
(To update Apache any time in the future, you can always run brew upgrade httpd
.)
Tell Brew to run Apache at system startup:
sudo brew services start httpd
By default, this Apache configuration will listen for traffic on port 80. So you can visit http://localhost:8080 to see it in action. If you'd like to switch to the default port (80), do this:
sudo sed -i.bak 's/Listen 8080/Listen 80/g' /usr/local/etc/httpd/httpd.conf
Then restart Apache with:
sudo apachectl -k restart
Install PHP via Brew:
brew install php@7.2
Configure Apache to load and run PHP:
echo 'LoadModule php7_module /usr/local/opt/php@7.2/lib/httpd/modules/libphp7.so' | sudo tee -a /usr/local/etc/httpd/httpd.conf
And then condfigure it to parse PHP files correctly:
echo 'AddType application/x-httpd-php .php' | sudo tee -a /usr/local/etc/httpd/httpd.conf
Restart Apache
sudo apachectl restart
Files are served out of /usr/local/var/www
. You can open that in Finder by typing Command-Shift-G and then pasting in the path.