Skip to content

Instantly share code, notes, and snippets.

@newbold
Created October 13, 2018 19:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save newbold/4adade158d907b60887004e8fd824ca2 to your computer and use it in GitHub Desktop.
Save newbold/4adade158d907b60887004e8fd824ca2 to your computer and use it in GitHub Desktop.
Simple guide to Apache + PHP on macOS 10.14 Mojave

Apache + PHP on macOS 10.14 Mojave

Download and install Xcode

https://developer.apple.com/xcode/

Install Xcode command line tools

xcode-select --install

Install Homebrew

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

Install Apache

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

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

Final notes

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment