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 OSXDaily.com 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
- User-specific content, accessible via http://localhost/~user, is in
- Logs are in
- 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.
- Search for “php” and uncomment that line,
LoadModule php5_module libexec/apache2/libphp5.so
- Add to httpd.conf before dir_module’s definition of DirectoryIndex:
<IfModule mod_php5.c> DirectoryIndex index.php index.html index.htm </IfModule>
- To configure PHP server:
cp /etc/php.ini.default /etc/php.ini
- Restart Apache:
sudo apachectl restart
- To update PHP on OS X, in-place from 5.3 (http://php-osx.liip.ch/). This only updates the Apache version, adjustments have to be made reference the updated version of php from the command-line.
curl -s http://php-osx.liip.ch/install.sh | bash -s 5.3
curl -s http://php-osx.liip.ch/install.sh | bash -s 5.4
curl -s http://php-osx.liip.ch/install.sh | bash -s 5.5