Mike's PBX Cookbook

Running Apache

In the good old days, Apache could be started and stopped by visiting the Sharing Preferences. It's still included in later versions of OSX, but now we need to open the Terminal application, and enter one of the following commands to control it:

Enter your admin password when prompted.
After starting Apache, check it's working by browsing to http://localhost

OS X Apache Localhost


To start Apache automatically after a restart, enter the folowing (unload to remove):

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

Users can not generally write to the "system level" document folder. We can either change permissions, or enable user sites as existed in previous OSX versions.

Enable User Sites:

1 Create a document root folder Sites in your home directory: mkdir ~/Sites
Note the Safari style Icon, which is a throwback to when the folder was standard.

OS X Apache Sites folder

2 Create a user config file: sudo nano /etc/apache2/users/username.conf

Paste in the following text, save and exit (ctrl-o, ctrl-x).

<Directory "/Users/*/Sites/">
  Options Indexes MultiViews FollowSymLinks
  AllowOverride All
  Require all granted

3 Edit the Apache configuration: sudo nano /etc/apache2/httpd.conf

Find, and uncomment the following lines (use ctrl-w to search):

LoadModule userdir_module libexec/apache2/mod_userdir.so
LoadModule alias_module libexec/apache2/mod_alias.so
LoadModule rewrite_module libexec/apache2/mod_rewrite.so
LoadModule php5_module libexec/apache2/libphp5.so
Include /private/etc/apache2/extra/httpd-userdir.conf

Save and exit (ctrl-o, ctrl-x)

4 Edit the user configuration: sudo nano /etc/apache2/extra/httpd-userdir.conf

Uncomment the following line:

Include /private/etc/apache2/users/*.conf

Save and exit (ctrl-o, ctrl-x)

5 Create a PHP test file in the new user level document root (~/Sites) with the following command:

printf "<?php phpinfo(); ?>" > ~/Sites/phpinfo.php

Restart Apache: sudo apachectl restart

6 Open http://localhost/~USERNAME/phpinfo.php (here, ~mike) in a browser, and behold!

OS X Apache PHP Info

Thanks to: Neil Gee, and Ole Michelsen

Home » Other » Mapache