WordPress Development Environment on Windows

I recently decided that I wanted to start contributing a little bit of time each week to the WordPress project.  Since I’ve already written a couple of extensions and administrate quite a few WordPress sites I figure it’s time to start giving back to the project.

The Core Contributor handbook outlines quite a bit of things you need to know in order to get started but there are always things that are linked to that start to fall out of date as time marches forward.

One step that I recently wanted to take was getting set up to perform unit tests.  As a developer I’ll be the first to admit guilt in not creating these for projects but for big projects like WordPress with distributed development and thousands of tickets it’s imperative that we have unit tests.

In this guide I will cover how to setup a complete WordPress development environment on Windows.  I’ll be covering everything from server (localhost) to SVN to Composer to PHPUnit.  We’ve got our work cut out for us so let’s get started.

Personally I find the instruction on the “First Steps” page in the handbook a bit lacking in detail, plus the complete setup is spread across several pages depending on your setup.  This guide assumes that you want to install on Windows and don’t want to run a virtual machine.

Step 1 – The Environment

“The environment is everything that isn’t me.”
-Albert Einstein

My personal favorite flavor of local server for window sin XAMPP.  The wonderful people over at apachefriends.org have put together a solid and stable release that works well in modern Window systems.  You can use a different one if you choose but I find this one the most user friendly.

Once downloaded and installed launch the control panel and start up Apache and MySQL. The other three are not necessary for WordPress development; we will be using SVN to keep our installation up to date not FTP, php can send mail without Mercury and we won’t be working in Java so no Tomcat necessary.
Click the Admin button for MySQL and using phpMyAdmin create two new databases for our WordPress installation and test.  I called mine “wordpress-svn” and wordpress-tests, but you can call them what ever you want.

Step 2 – The Checkout

“Check it out now, the funk soul brother”

-Fatboy Slim

First up is the discussion about SVN vs. Git. I LOVE GIT. Be that as it is and the fact that WordPress now supports both… your life will be easier if you use SVN.  WordPress is well vested in SVN and deviating from that standard isn’t recommended.  If you insist on using Git remember in the future if get commit privileges to the development trunk  someday your commits to Git will not affect the version of WordPress that gets published.  So in short you’ll end up switching to SVN eventually anyway.

Using SVN on Windows means it’s time install TortoiseSVN (if you don’t already have it).  I highly recommend it and it’s is pretty much the standard when your using Windows (and don’t want to mess with command line).

Once you have it installed go to your C:/xampp/htdocs folder. Create a new folder called wordpress-svn. Right click the folder and select SVN Checkout. Punch in https://develop.svn.wordpress.org/trunk/ in the “URL of repository:” and click OK.  This will download the “bleeding edge” version of WordPress.

Remember that you should do update each day you plan on working on WordPress.  You can update your version to the “HEAD” by simply right clicking the folder and selecting SVN Update.

Step 3 – The Install

WordPress started in 2003 with a single bit of code to enhance the typography of everyday writing and with fewer users than you can count on your fingers and toes. Since then it has grown to be the largest self-hosted blogging tool in the world, used on millions of sites and seen by tens of millions of people every day.

-Wordpress.org

Now if your using standard setting you should be able to go to http://localhost/wordpress-svn/src/ and start the install process (Make sure you have Apache and MySQL running).

WordPress will step you through the install process.  Select your language, then provide your database information.  If you followed along with me and left everything else default your credentials will be:

  • Database Name: wordpress-svn
  • Username:      root
  • Password:      blank    (literally leave the field empty)
  • Database Host: localhost  (default)
  • Table Prefix:  wp_        (default)

Run the install then login… DONE.  (I love how easy this system is to install)

Step 4 – The Test

The test of a first-rate intelligence is the ability to hold two opposed ideas in mind at the same time and still retain the ability to function.

-F. Scott Fitzgerald

In the handbook under “automated testing” (which should really be labeled unit testing for clarity) they point to this article written by Alex Mills in 2012.  While it’s a great article to help you get started it turns out that PHPUnit has recently decided to stop supporting the installation method he used in the near future.

Since PHPUnit is no longer supporting PEAR for installation I recommend using Composer to handle PHPUnit as a dependency.  They indicate on their installation page the “easiest method” is to use a PHAR archive to do the installation, but since we are targeting Windows for our environment and not a Linux distro it’s not really the easiest.

Here is the method I used to get started:

  1. Go get Composer (if you don’t have it already)
    1. I used the installer and installed the Shell Menus
  2. Restart your computer. (or all explorer and CMD.exe instances)
  3. Create your composer.json file in your C:/xampp/htdocs/wordpress-svn folder
  4. Here is what I put in my composer file:
  5. {
        "name"        : "wordpress/wordpress",
        "description" : "WordPress is web software you can use to create a beautiful website or blog.",
        "keywords"    : ["blog", "cms"],
        "homepage"    : "http://wordpress.org/",
        "license"     : "GPL-2.0+",
        "authors"     : [
            {
                "name"    : "WordPress Community",
                "homepage": "http://wordpress.org/about/"
            }
        ],
        "support"     : {
            "issues": "http://core.trac.wordpress.org/",
            "forum" : "http://wordpress.org/support/",
            "wiki"  : "http://codex.wordpress.org/",
            "irc"   : "irc://irc.freenode.net/wordpress",
            "source": "http://core.trac.wordpress.org/browser"
        },
        "require"     : {
            "php": ">=5.2.4",
            "phpunit/phpunit": "4.1.*"
        }
    }
  6. Most of this isn’t necessary but it’s nice to have. the only line you really need is
    "phpunit/phpunit": "4.1.*"
  7. Now launch CMD.exe as an administrator
  8. Navigate to your wordpress directory cd \xampp\htdocs\wordpress-svn
  9. Then run the composer install command

If you get an error saying something like: ‘php’ is not recognized as an internal or external command… it means that you need to add php to your path.  To do that:

  • Click Start -> Hover over “My Computer” -> Right Click and select Properties
  • Select Advanced system settings from the left column
  • On the Advanced Tab click the Environment Variables… button
  • In the “System variables section scroll down and select the Path variable and click Edit
  • If you are using the default install add C:\xampp\php; to the end of the value string (No Spaces after the semi-colon!)
  • Click OK until your back out and restart CMD.exe then try to run composer install again.

Now the PHPUnit is installed and ready to go we need to connect to our test database.  First rename the wp-tests-config-sample.php file in your wordpress-svn directory to wp-tests-config.php.  Open it up and make changes to the following lines:

define( 'DB_NAME', 'wordpress-tests' );
define( 'DB_USER', 'root' );
define( 'DB_PASSWORD', '' );
define( 'DB_HOST', 'localhost' );
define( 'DB_CHARSET', 'utf8' );
define( 'DB_COLLATE', '' );

$table_prefix  = 'wptests_';   // Only numbers, letters, and underscores please!

define( 'WP_TESTS_DOMAIN', 'localhost' );
define( 'WP_TESTS_EMAIL', 'youremail@domain.edu' );

Once you’ve saved your changes go back to the CMD and type in phpunit (make sure your still in your wordpress-svn directory).  This will run the battery of unit tests already written.

That’s it you are now ready to start making WordPress more awesome.  At this point I would suggest referencing the handbook and checking out the various ways you can contribute.

Tell me what you REALLY think...

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

You may use these HTML tags and attributes:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>