RSS
 

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 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):

[bash light=”true”]
sudo apachectl start
[/bash]

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,

    [code light=”true”]
    LoadModule php5_module libexec/apache2/libphp5.so
    [/code]

  3. Add to httpd.conf before dir_module’s definition of DirectoryIndex:

    [code light=”true”]
    <IfModule mod_php5.c>
        DirectoryIndex index.php index.html index.htm
    </IfModule>
    [/code]

  4. To configure PHP server:

    [bash light=”true”]
    cp /etc/php.ini.default /etc/php.ini
    [/bash]

  5. Restart Apache:

    [bash light=”true”]
    sudo apachectl restart
    [/bash]

  6. 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.
    PHP 5.3

    [bash light=”true”]
    curl -s http://php-osx.liip.ch/install.sh | bash -s 5.3
    [/bash]

    PHP 5.4

    [bash light=”true”]
    curl -s http://php-osx.liip.ch/install.sh | bash -s 5.4
    [/bash]

    PHP 5.5

    [bash light=”true”]
    curl -s http://php-osx.liip.ch/install.sh | bash -s 5.5
    [/bash]

See Also:

http://osxdaily.com/2012/09/10/enable-php-apache-mac-os-x/

Enhanced by Zemanta
 

Tags: , , , , , , ,

 
%d bloggers like this: