LAMP Setup on OSX

APACHE

Most configuration items can be found in: /etc/apache2/httpd.config

Starting and Stopping

On the Mac, to force Apache to run during computer start-up, issue the one-time command: sudo launchctl load -w /System/Library/LaunchDaemons/org.apache.httpd.plist

Alternatively, manually launch it with: sudo apachectl start

To undo that command (don't start Apache on boot): sudo launchctl unload -w /System/Library/LaunchDaemons/org.apache.httpd.plist

Alternatively, manually stop it with: sudo apachectl stop

Reboot the web server with: sudo apachectl restart

Directory Locations

The default folder, from which web pages can be found at http://localhost are specified with the line: DocumentRoot "/Library/WebServer/Documents" from the config file. It is possible to put a symbolic link in that directory if you don't want all files there, or want to setup virtual hosts.

User Locations

Users are also given their own private web space. It can be accessed similar to http://localhost/~Craig

The directory that maps to the user file is specified in /etc/apache2/users/Craig.conf (replace Craig with the actual case-sensite user name — you can get the names from the /Users directory). The contents of the Craig.conf file should be similar to:

<Directory "/Users/Craig/Sites/">
Options Indexes MultiViews FollowSymLinks
     AllowOverride All
     Order allow,deny
     Allow from all 
</Directory> 

Virtual Hosts

A virtual host allows you to use http://pixelpro.dev instead of http://localhost/pixelpro. The difference isn't strictly cosmetics on the command line. For PHP sites, you will be able to keep the directory levels closer to production without needing special code for when running in Dev vs. Prod.

It is a two-step process to create each virtual host. First, prevent the browser from getting resolving your domain name from the DNS servers by injecting an exception in the "hosts" file. Open /etc/hosts and add a line similar to this: 127.0.0.1 pixelpro.dev

The second step is to tell Apache where to find the directory for your virtual host. Open /etc/apache2/extra/httpd-vhosts.conf and add a section similar to this:

<VirtualHost *:80>     
	ServerName "pixelpro.dev"     
	ServerAdmin craig@pixelpro.biz     
	DocumentRoot "/Users/Craig/Sites/Pixel Pro"         
	<Directory "/Users/Craig/Sites/Pixel Pro">                 
		Allow From All                 
		AllowOverride All         
	</Directory> 
</VirtualHost> 

Lastly, you will need to do this one-time step to ensure Apache is loading your virtual host file. In the main Apache config file, uncomment out the line Include /private/etc/apache2/extra/httpd-vhosts.conf

Under OSX, /etc is a symbolic link to /private/etc, which explains the directory path above.

PHP

Most configuration items can be found in: /etc/php.ini

Installation

OSX comes with PHP, but if you need a different build (Mcrypt, I'm looking at you.) then you may have to compile a new version. To enable PHP on Apache, make sure the PHP Module is getting loaded. The line you need inside of the Apache configuration file (/etc/apache2/httpd.config) is:

LoadModule php5_module libexec/apache2/libphp5.so

I have another instance of PHP at LoadModule php5_module /usr/local/Cellar/php54/5.4.24/libexec/apache2/libphp5.so

You can get binary installs from http://php-osx.liip.ch

Configuration for Development

During development, it is a good idea to turn on error logging. I made these changes to /etc/php.ini

Line 462: error_reporting = E_ALL

Line 479: display_errors = On

I have also tweak file upload sizes; see the installation document for the DART project.

This page has good instructions for getting LAMP set-up under Mavericks. Plus, it has instructions for enabling Xdebug.

MySQL

I installed the “Mac OS X ver. 10.7 (x86 64bit) DMG Archive. All three components.

The System Preferences pane will start and stop the database server.

I created file “~/.bash_profile” to add a path to the MySQL bin folder (I'm not sure if this was strictly necessary...)

I did not set a “root” password.

When PHP/PDO attempts to connect to MySQL you will get error 2002 (some sort of socket error?). To fix that, you need to create a symbolic link in folder /var/mysql using the command:

sudo ln -s /tmp/mysql.sock /var/mysql/mysql.sock