Apache and PHP 5.5.27 are installed already in OS X 10.11 El Capitan, so just a little enabling is required.

Updated 12 Oct 2016: See the slightly updated guide for macOS 10.12 Sierra, which has been updated to Apache 2.4.23 and PHP 5.6.24.

The Grav Blog has an in-depth 3-part series on setting up Grav properly on OSX. This is just my quick-and-dirty approach.

Be careful, with great power (root) comes great responsibility! Use at your own peril.

From Terminal, edit the Apache configuration as root (password is the same as your login password).

sudo vi /private/etc/apache2/httpd.conf

Uncomment these lines (remove the #) and save.

LoadModule cache_module libexec/apache2/mod_cache.so
LoadModule expires_module libexec/apache2/mod_expires.so
LoadModule headers_module libexec/apache2/mod_headers.so
LoadModule rewrite_module libexec/apache2/mod_rewrite.so
LoadModule php5_module libexec/apache2/libphp5.so

By default, Apache runs as the user _www and serves pages from /Library/WebServer/Documents/. This can be changed to your user (replace [user] below with your username) and you own directory. In the same httpd.conf file:

User [user]
Group staff
DocumentRoot "/Users/[user]/Sites"

Next, create the default php.ini configuration and edit it as required, e.g. opcache.enable=1

cd /private/etc
cp php.ini.default php.ini

Create the Sites directory then start Apache: And finally, start or restart Apache, then open your browser to localhost/phpinfo.php to make sure all is hunky-dory:

cd /Users/[user]
mkdir Sites
echo "<?php phpinfo();" > Sites/phpinfo.php
sudo apachectl start

Back to the Apache httpd.conf, edit set AllowOverride All at a couple of locations:

<Directory "/Users/[user]/Sites">
 AllowOverride All
</Directory>

<Directory />
 AllowOverride All
</Directory>

And finally, restart Apache. The second line automatically starts Apache when the machine is rebooted (although, I didn't need this and I'm not sure why):

sudo apachectl -k restart
sudo launchctl load -w /System/Library/LaunchDaemons/org.apache.httpd.plist

To remove the startup, run the command again replacing load with unload.

Next time, file-copy installation of Grav without any command line interface (CLI) tools like Grav Package Manager (GPM). I almost said xcopy installation!

Updated 12 Oct 2016: Changed for macOS 10.12 Sierra which requires the AppType PHP line. See the updated guide.

Related Posts

Newer Post Older Post