This post will teach you how to set up a local development environment to manipulate and create your web applications using the WordPress code base.

A few years ago the status quo for getting a development environment for PHP applications was to use MAMP – Mac, Apache, MySQL & PHP. This worked fine until I started doing Ruby development and specifically use Ruby on Rails for my daily development. There are many reasons why I do not like MAMP, yet is this post is not about any. This post is about an alternative set up a development environment for WordPress, or other PHP applications, on a new MAC with OSX Lion – without MAMP.

Part 1 – Apache and PHP

1) Get Apache activated on your system.

Activating Apache on a MAC Lion is a easy as opening System Preferences > Sharing. Then click “Web Sharing” in the list of options. Now direct your browser http://localhost/ .

You should see a page that looks like this:

it-works-apache

2) Load the PHP module in httpd.conf

Open the Terminal application and cd to the hard drive root

 $ cd /private/etc/apache2/

Open httpd.conf

 $ sudo vim httpd.conf

Type your password and vim will open the file. Move to line line number 111. Note: this was line 114 on Snow Leopard, but what you are looking for is a commented out line reading:

 111 # LoadModule php5_module libexec/apache2/libphp5.so

Uncomment the line, remove the “#”

 111 LoadModule php5_module libexec/apache2/libphp5.so

Write/Save the file and exit.

3) Create/Configure PHP

Back in Terminal. Copy the existing default PHP ini file to a working copy.

 $ sudo cp /private/etc/php.ini.default /private/etc/php.ini

Enter your password and this should be done. You can confirm this has happened by listing on the contents of the /private/etc directory. You should see both php.ini and php.ini.default.

$ cd /private/etc
$ ls -lha

the output may be long but you should see:

-r--r--r--   1 root  wheel    68K Oct 16 21:29 php.ini
-r--r--r--   1 root  wheel    68K Jul  8 01:37 php.ini.default

You can configure your PHP configuration to your preference.

4) Confirm PHP is running

Previously on OSX Snow Leopard there was a directory named sites. On Lion you must create this directory. This can be done where you activated Apache earlier. Go to System Preferences > Sharing and click the “Open Personal Website Folder” button. This will open Finder.

These can be deleted or you can copy the index.html to a index.php file then trash all but the index.php. In Terminal type:

$ cd ~/Sites
$ touch index.php
$ rm -rf images index.html
$ vim index.php

In index.php write this:

<?php phpinfo() ?>

Write/save the file and navigate your browser to http://localhost/~yourusername/index.php. If you are lucky you will see a long page with all the information about your version of PHP, but if you have my result you may need to restart Apache. To restart Apache run this in Terminal

 $ sudo apachectl restart

Refresh the browser and you should see:

 

Part 2 – WordPress and MySQL

1) Setup MySQL

Sadly OSX Lion still doesn’t come with a running, or non-running for that matter, instance of MySQL. This means we have to go get it. This is an entire blog post in it self, but here is the link to MySQL download page.

http://dev.mysql.com/downloads/mysql/

Grab the latest version of DMG (64 bit), 5.5.16 at the time. Once downloaded double click the file. After installation there is an additional file that will load a start/stop application for the daemon in you System Preferences application. Verify your MySQL daemon is running by opening the mysql console in Terminal.

 
$ mysql -u root
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.5.15 MySQL Community Server (GPL)

Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>

You see this if everything is working correctly.

2) Download and setup WordPress project

Navigate your browser to http://wordpress.org download the latest version on the home page to your “Sites” directory. Once the zip file is downloaded navigate to the Sites directory and double click the zip. At this point, I leave the zip file in the directory and rename the folder named WordPress to whatever project I am working on.

 

Now navigate to http://localhost/~yourusername/Taxi-Magic/ and you should see the setup page for WordPress configuration. It is easier to skip this tutorial when setting up for two reasons. 1) Your Mac folder permissions probably won’t let it work. 2) You should understand what is happening behind the scenes.

3) Connect MySQL and WordPress (final step)

WordPress doesn’t allow us to create a database from the code base at this time, so we need to access the MySQL console, or another tool – like Sequel Pro, to create a database.

 
$ mysql -u root
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.5.15 MySQL Community Server (GPL)

Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> create database taxi_magic_wp;
Query OK, 1 row affected (0.00 sec)

mysql> 
mysql> exit;
bye

The last step is to configure our WordPress wp-config.php file. WordPress includes a sample of the file uniquely named wp-configure-sample.php. Easiest way to do this is to copy the sample file, rename to wp-configure.php, and edit a few import functions near the top. This file is found in the root of the WordPress directory you renamed in the last step.

 

 

 17 // ** MySQL settings - You can get this info from your web host ** //
 18 /** The name of the database for WordPress */
 19 define('DB_NAME', 'taxi_magic_wp');
 20 
 21 /** MySQL database username */
 22 define('DB_USER', 'root');
 23 
 24 /** MySQL database password */
 25 define('DB_PASSWORD', '');
 26 
 27 /** MySQL hostname */
 28 define('DB_HOST', '127.0.0.1');
 29 
 30 /** Database Charset to use in creating database tables. */
 31 define('DB_CHARSET', 'utf8');
 32 
 33 /** The Database Collate type. Don't change this if in doubt. */
 34 define('DB_COLLATE', '');

The important lines here are 19, 22, 25, and 28. Most importantly is that WordPress instructions indicate your host should be ‘localhost’ in most cases. Actually, ‘127.0.0.1’ and ‘localhost’ are the same thing, but on the Mac running a testing envorinment this way requires the number, not the string.

Now you have a full fledged local development version of WordPress, MySQL, PHP, and Apache.

7 thoughts on “Local WordPress Development Environment without MAMP on OSX Lion

  1. Bill B says:

    I had a few wordpress sites that I was managing [barely] back before I upgraded my OS to Lion. I knew there would be some things that would be a pain, but never thought how much tweaking would be involved in just getting a local wordpress development environment going.

    Thank you so much for your tutorial, at first nothing was working but then I realized most of the problem was me. Sat back fully read the instructions and followed it to a “T”, everything worked just as you described.

    Now I can develop my site without having to go online until it is ready.

    Thanx again for ll your help.

  2. Colin says:

    Thanks for posting.
    I think this was actually faster than installing MAMP :-)

  3. BJ says:

    Hello,

    I’ve have been thinking about looking for something else than MAMP but why should i not use MAMP.
    The only reason i don’t like MAMP it’s because it runs so manny CPU processes. Do you know if all those processes are gone if i don’t use MAMP ?

    Thanks,

  4. Kyle Shevlin says:

    Any chance you might be able to add updates for Mavericks to this? I would love to be able to setup WordPress locally without MAMP (same reason, Rails developer for my job), but I some of the steps you’ve listed don’t seem to exist e.x. System Preferences > Sharing doesn’t have the same options.

  5. Brett says:

    I can do that, but probably not for a while. I don’t do much custom WP development anymore and the Daily Ruby Tips are taking up most my writing time.

  6. daniel says:

    Thanks so much. Had spent the whole day trying to get this to work. Turns out the issue was just needing to use ‘127.0.0.1’ instead of ‘localhost’. Couldn’t find that info ANYWHERE else.

Leave a Reply

Your email address will not be published. Required fields are marked *