Setting up a local web server on OS X Snow Leopard 10.6

Basic Web Server

MAMP is great. It’s an easy way to host your PHP/MySQL site locally for test­ing and devel­op­ment. But, if you want to take advan­tage of Snow Leopard’s built in web server capa­bil­i­ties, OS X makes it easy. Go into Sys­tem Pref­er­ences > Shar­ing, and check the “Web Shar­ing” box.

That’s it. You can now setup an HTML-only web­site locally. Where do you put the files? The default folder is /Library/WebServer/Documents/. While we’re at it, let’s setup PHP and MySQL to work locally, as well.

Test it. http://localhost. No need for a port as it will use apache’s default port 80.

PHP and MySQL will now need to be setup for a full func­tion­ing local host.

Set­ting up PHP

Open up Ter­mi­nal (Applications->Utilities->Terminal) and type:

sudo nano /etc/apache2/httpd.conf

Go to this line

#LoadModule php5_module        libexec/apache2/

and uncom­ment the line by remov­ing the hash character

LoadModule php5_module        libexec/apache2/

After sav­ing the file (Control+O) and exit­ing (Control+X). Restart Apache.

sudo apachectl restart

Con­fig­ur­ing PHP

cd /etc
sudo cp php.ini.default php.ini
sudo chmod 666 php.ini
sudo nano php.ini

Find this line and remove the semi-colon

;date.timezone = 

and add your own time­zone. A list of time­zones can be found here (

date.timezone = America/Halifax

You’re halfway there. PHP 5 is now run­ning on your local server.

Set­ting up MySQL

Down­load the MySQL pack­age for Mac OS X.5 (32 or 64 bits depend­ing on your machine)
Install every­thing in the pack­age in this order:

  • mysql
  • the startup item
  • the pref­er­ence pane.

Now, open /etc/php.ini, find these three lines

mysql.default_socket = /var/mysql/mysql.sock
mysqli.default_socket = /var/mysql/mysql.sock

and replace /var/mysql/ with /tmp/

mysql.default_socket = /tmp/mysql.sock
mysqli.default_socket = /tmp/mysql.sock

After installed, you can start MySQL in the sys­tem pref­er­ences. To access your data­base from the Terminal

/usr/local/mysql/bin/mysql -u root

Change your Home Directory

Want your local server’s files to be located some­where other than the default /Library/WebServer/Documents/? Open /etc/apache2/httpd.conf, and change the next two lines to reflect your new home directory.

DocumentRoot "/Library/WebServer/Documents"
<Directory "/Library/WebServer/Documents">

Dru­pal Problems?

If you’re get­ting errors dur­ing Dru­pal instal­la­tion try link­ing the MySQL sock file like below

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

Drupal’s Clean Urls

Hav­ing prob­lems enabling Clean Urls? Find all instances of the fol­low­ing line in /etc/apache2/httpd.conf

AllowOverride None

and change None to All

AllowOverride All

Comments are closed.

Web Design Ideas and Resources