Activating OS X’s Builtin Apache Web Server and PHP

14 Jan

As I mentioned in my prior post OS X Command-line Dev Tools—Install Shortcut, OS X comes with a variety of built-in tools suited for developers. Unfortunately, Apple has seen fit to hide one of the most important of them: the web server. Despite that, they are easily unlocked if you know how. This applies to Mountain Lion (10.8) and (though I haven’t tried it, yet) Mavericks (10.9). Though you can install separate installations, I don’t like to install anything extra, unless I must.

Apache Web Server

The article “Start an Apache Web Server in Mac OS X Mavericks & Mountain Lion“.  The key is knowing the command-line command (run from Terminal):

sudo apachectl start

This will start the built-in Apache web server. The system will remember the setting and restart the server across reboots.

  • The source directory for the machine’s root (http://localhost/) is in /Library/WebServer/Documents.
  • User-specific content, accessible via http://localhost/~user, is in ~/Site.
  • Logs are in /private/var/log/apache2/
  • PHP is also available, but needs to be activated.

See the article, linked above, for details on how to set things up.

Activating Built-in PHP Support

Now that you have the built-in Apache running, you might want to enable the built-in PHP support.

  1. Edit httpd.conf
  2. Search for “php” and uncomment that line,
    LoadModule php5_module libexec/apache2/
  3. Add to httpd.conf before dir_module’s definition of DirectoryIndex:
    <IfModule mod_php5.c>
         DirectoryIndex index.php index.html index.htm
  4. To configure PHP server:
    cp /etc/php.ini.default /etc/php.ini
  5. Restart Apache:
    sudo apachectl restart
  6. To update PHP on OS X, in-place from 5.3 ( This only updates the Apache version, adjustments have to be made reference the updated version of php from the command-line.
    PHP 5.3

    curl -s | bash -s 5.3

    PHP 5.4

    curl -s | bash -s 5.4

    PHP 5.5

    curl -s | bash -s 5.5

See Also:

Enhanced by Zemanta

Tags: , , , , , , ,

%d bloggers like this: