Mac OS X 10.9 Mavericks ships with Apache version 2.2.24 and PHP version 5.4.17. One way to gain more control over which versions of software you run is to use the Homebrew package manager to install and configure them. Homebrew is “the missing package manager” for Mac OS X. To install Homebrew on your system, run the following command at the command line in Terminal:

Installing Apache 2.4

Before you install Apache 2.4 from Homebrew, you’ll want to install a couple of prerequisites it will need:

Next, to install Apache 2.4 run the following command:

To verify your Apache version, run:

You should see output such as the following:

Configuring Apache

To configure the version of Apache you’ve now installed with Homebrew, you can edit the config file:

If you’ll be installing PHP 5.4 you can go ahead and add the line to load the PHP module into Apache. In the httpd.conf file search for the other LoadModule lines and add a new one below them:

Next, to map the .php file extension to the PHP MIME type in Apache, search for the other AddType lines and add a new line below them:

To enable loading index.php as a directory index, replace DirectoryIndex index.html in httpd.conf with the following and restart Apache:

Next remove the comment (the # symbol)  from the beginning of the following lines to enable a few commonly used modules:

By default, Apache is configured to store your website directories in /usr/local/var/www/htdocs. To change this to another directory change the following lines:

When making changes to the httpd.conf file, in order for the changes to take effect you’ll need to restart Apache with the following command:

Starting Apache

Before starting Homebrew’s Apache, it may be necessary to stop Mac OS’s default Apache:

To autostart Apache on boot, copy the Apache plist file to the LaunchAgents directory:

To start Apache now:

on your system, use the command sudo visudo to edit the sudoers file, and add the following line, replacing yourusername with your username:

Then edit your /etc/rc.common file:

And add the following lines to the bottom of the file:

Configuring Apache Virtual Hosts

To create the virtual hosts directory, run:

Edit the httpd.conf file:

Search for the Virtual Hosts section and add the following line just below there:

Installing PHP

To install PHP, run:

Install PHP modules:

Configuring PHP

To edit the php.ini file:

To have launchd start php54 at login:

To load php54 now:

Installing MySQL

To install MySQL:

To have launchd start mysql55 at login:

To start mysql55 now:

Secure your MySQL install and set the root password:

Configuring MySQL

Edit your Bash profile:

Add the following line:

Execute the contents of .bash_profile:

To start MySQL: