Developing WordPress plugins is not very difficult, in theory. PHP is not a difficult programming language, WordPress is well-designed with appropriate hooks for use by plugins, and there is extensive documentation.
In practice, it can be a different story.
There’s two main strategies for developing WordPress (and other MySQL/PHP web applications):
- Using a remote host: the server is located somewhere-else-who-knows-and-who-cares-where. Everything you need was automagically installed.
- Using a local host: the web server (Apache), the database server (MySQL) and the preprocessor (PHP) is located on your personal computer (Windows or Linux).
In the following, I’m using WAMP (Windows-Apache-MySQL-PHP) for illustration, but LAMP (Linux-Apache-MySQL-PHP) is interchangeable. If it matters (and it really shouldn’t because we both have better things to do with our time than battle over operating systems), at the this exact instant of writing I have Ubuntu running in VMWare running on Windows Vista.
With that out of the way, let’s examine a few of the many reasons why developing from a local WAMP installation benefits anyone serious about WordPress theme and plugin development.
Benefits of local WAMP
Benefits of developing WordPress (and other web applications) using locally installed Windows- or Linux-Apache-MySQL-PHP include:
- Offline capability for working means being to develop wherever you want. Say at Bolinas, on the beach, where even cell reception isn’t very good.
- Local development saves you time and hassle dealing with source code control systems such as Subversion. Your local development can contain any number of script files, makefiles or project files that have no business being on the server, including all those pesky .svn directories. You upload to the server precisely what’s necessary for your web application. In contrast, develpoing on a remote server requires synchronizing with another remote repository for source code control, or you have to download the changed files (can you remember which files you changed on the server?) for archiving or backing up. rsync can help with some of these chores, but if you aren’t already an rsync expert, that’s another tool to master.
- When you make mistakes, your website doesn’t crash! Once you have an operating website, downtime will cost you money. Do your testing and development on your laptop where mistakes can be deleted and fresh starts don’t cost you visitors and money.
- Learning a few skills to run a simple web server on your laptop will help you outsource in the future… you won’t get ripped off by ignorant or predatory developers. You’ll have important skills for managing your actual website and web server in an emergency… when tech support isn’t available and your contractor is out drinking himself blind in Baja!
- Learn faster and smarter: integrated development environments (IDEs) such as Aptana Studio provide excellent leverage. When set up correctly, you will be able to much more easily debug your application code, possibly even single-stepping line-by-line. Single stepping is one of the most effective ways to both debug code and to learn how unfamiliar code works.
Now, a fair number of programmers I know sneer at “development environments,” claiming “All I need is notepad and ftp.” Well, that’s just great, but notepad and ftp constitute a development environment themselves, and a very poor environment. That development cycle goes something like this: Notepad → FTP → WordPress → Notepad → FTP → WordPress → Notepad → FTP → WordPress → Notepad → FTP → WordPress → Notepad → FTP → WordPress → Notepad → FTP → WordPress → Notepad → FTP → WordPress → etc. etc. etc.
I think you get the idea.
Without a local installation and a capable Integrated Development Environment (IDE), web development can be very, very tedious. Of course, you can use Notepad when your develop locally… and when only small changes or tweaks are necessary, it’s the right way to go.
A brief digression… What I found from professional software development is that some of the best and fastest coders I’ve ever met use IDEs ranging from Eclipse, to Visual Studio, or even having a highly customized Emacs. These programmers don’t tend to write blog posts, and they don’t tend to argue about development environments. They just crank out solid code, day after day.
My experience is that time invested in an appropriate IDE will pay you back tenfold… so let’s get started!
Cygwin is not your Daddy’s DOS
The best place to begin… is the beginning. And in the beginning was the command line.
It’s hard for to explain why Cygwin tools are so important for effective development, like explaining color to a blind man… except that anyone blind to command-line power has the choice of opening their eyes.
So, what is Cygwin? Cygwin is Unix for your Windows computer. It’s just about every user space tool (and a fair number of services) available on all modern unix and linux systems, available at your fingertips, for free. If you used just about any flavor of Unix within the last 15 years, your scripts will probably run with few or (more likely) no changes whatsoever.
The most difficult part of learning Cygwin is unlearning DOS. DOS was so bad, for so many years (decades), that most people completely shut out the command line. The atrocity of DOS is one of the reasons why the UNIX community sneered at Microsoft: without a powerful command line, maintaining a computer becomes very difficult. Maintaining more than one computer almost impossibly difficult. The cynical might suggest that Microsoft kept DOS crippled on purpose. But cynicism isn’t productive, so let’s not go there.
This isn’t an anti-Microsoft rant… just know that your primary interface with the Cygwin system is through a command line window running the “bash” program. bash is a shell, and if you don’t care for it, cygwin will allow you to run any of several other shells such as csh, tcsh, ksh, wish, zsh, etc. You can find more information on bash at Wikipedia, which is a good place to start for now. We’ll go into more depth later.
In the meantime, get started downloading cygwin using the the setup.exe program from http://cygwin.com/. Click through the default install, choosing “Unix file endings” for portability and “Install for everyone.”
We’ll touch base with cygwin a bit later when we cycle back around to source code control.
Apache on localhost:8080
Your next step is installing your very own, private web server running on your personal computer. This is really easy, go to the http://apache.org/ website, download httpd server. Here’s the link to the download page, get httpd 2.2. Here’s the actual file.
For the installation:
- Install for everyone
- Install into C:Program Files
- Use the “Typical” configuration
httpd.conf:
- Open the
conf/httpd.conffile. - Find “
Listen 80” and change it to “Listen 8080“ - Save, close, start Apache again. On MS Windows, use the handy toolbar icon as shown the figures above and below.
Your very own MySQL server
Now that you have your Apache web server installed, it’s time to get your database server up and running. Fortunately, this is just as easy as installing Apache. For MySQL, download the .msi Windows installer file, a few clicks and you’re done. After you have MySQL installed, start the mysql command line client program in a Cygwin window (you did install Cygwin, right…?): $ mysql -uroot -p Hit enter, then type in the password you set for user root when you installed MySQL.
Now we set up your MySQL server with a database for WordPress. Here’s the commands:
1 2 3 4 5 6 7 8 9 10 11 12 | mysql> CREATE DATABASE wptest; Query OK, 1 ROW affected (0.00 sec) mysql> CREATE USER 'wptest'@'localhost' IDENTIFIED BY 'mypassword'; Query OK, 0 ROWS affected (0.00 sec) mysql> USE wptest; DATABASE changed mysql> GRANT ALL PRIVILEGES ON *.* TO 'wptest'@'localhost' -> WITH GRANT OPTION; Query OK, 0 ROWS affected (0.00 sec) mysql> FLUSH privileges; Query OK, 0 ROWS affected (0.00 sec) |
If you get ERROR 1133 (42000): Can't find any matching row in the user table, make sure all the user and password information matches for each command. If you changed any of the user names or passwords I listed here (which is smart security), then tried to cut and paste the following command, you’re probably going to get ERROR 1133. Once you have these commands executed properly, your MySQL database is ready for WordPress.
PHP
PHP: more of the same! Download PHP from the web site, a few clicks and you’re done. Here’s how you want to set up the installation:
- Install into C:Program Files
- Choose Apache 2.2.x.Module
- Browse to your Apache configuration directory. On my machine this is C:Program Files (x86)Apache Software FoundationApache2.2conf
- Choose everything first, then unselect the CLI executable option.
Here’s how to test it:
- Create a file called “index.php”
- Open index.php in a text editor, and add the following:
-
1 2 3
< ?php phpinfo(); ?>
- Save index.php to your htdocs directory so Apache can find it.
- Now point your browser at http://localhost:8080/index.php
Here’s what the top of phpinfo looks like on my WAMP installation:
Testing WAMP on localhost
If you have been following along and have everything installed, your WAMP installation should be running and available on this URL: http://localhost:8080/.
Installing WordPress locally
Here’s a quick overview:
- Download from wordpress.org
- Create a subdirectory for your web server to serve WordPress files, say, wptest:
C:Program Files (x86)Apache Software FoundationApache2.2htdocs - Unzip WordPress into
wptest. - If you haven’t created the MySQL database and database user as shown above, do so now.
- Make sure to change the database name in
wp-configto the name you used above (wptest in my example). - You should now be able to point your web browser to http://localhost:8080/wptest/ and finish your installation.
If you’re a complete beginner with WordPress, more detailed instructions are available here: “Install WordPress on Your New Web Site in 5 minutes.”
WordPress plugin development with Aptana Studio
I’ve just started using Aptana Studio, and I like it. It’s really cool. Using a local WAMP, I check out a copy of the source code directly into the WordPress plugins directory. My source has an Aptana project file, which once loaded into Aptana is always available on startup. Plugin development is much, much easier: changes in the code can be evaluated very, very quickly, never a wait while uploading via FTP. Once I’m done coding, I can use the Aptana “Team” tools to commit my changes using the subversion “subclipse” module available as an Aptana plugin, or just use svn on the Cygwin command line as usual.
Writing test code is a snap, as easy as changing projects in the IDE. This is especially useful for debugging intricate CSS layouts, for which Aptana has a handy preview capability. No more 3rd party CSS tools necessary.
Once your plugin has been uploaded to it’s subversion repository, here’s a great way to set up your environment for using Aptana:
Check out just the plugin trunk into your locally installed WordPress. For example, here’s what I do with my WordPress hRecipe plugin:
cd wp-content/pluginssvn co http://svn.wp-plugins.org/hrecipe/trunk ./hrecipe- Proceed with plugin development using Aptana in the wp-content/plugins/hrecipe directory.
- Test development using your locally installed WordPress blog; the plugin under development is “installed” already.
- Commit changes to trunk as necessary.
For release, I have the entire plugin source tree checked out into a different location. Once my development is finished, I svn update the plugin code in that location, advance the release version, and tag it appropriately.
Feedback welcome!
This article was partly inspired by some friends who are (or will be) attempting a local WAMP installation for their own WordPress-based websites. I expect to get some pretty good feedback from them, but I would also like some feedback from you:
- Was this article useful?
- Was it too detailed?
- Not detailed enough?
- How could it be improved?
- What’s your interest in a localhost WAMP? How does it benefit you in ways not listed above?
Let me know, and if I missed the mark anywhere, corrections are definitely welcome.




{ 7 comments… read them below or add one }
I’m still having some trouble getting everything up and running.
All in all. it took me 2 or 3 rounds of installing and uninstalling to get everything working.
The first major problem I had was that Apache was not loading correctly and PHP was not loading at all. I found that in the httpd.conf file for Apache, the directory to find PHP in was being defined 3 times. It looked like this:
#BEGIN PHP INSTALLER EDITS – REMOVE ONLY ON UNINSTALL
ScriptAlias /php/ “C:/Program Files/PHP/”
Action application/x-httpd-php “C:/Program Files/PHP/php-cgi.exe”
PHPIniDir “C:/Program Files/PHP/”
LoadModule php5_module “C:/Program Files/PHP/php5apache2_2.dll”
PHPIniDir “C:/Program Files/PHP/”
LoadModule php5_module “C:/Program Files/PHP/php5apache2.dll”
PHPIniDir “C:/Program Files/PHP/”
LoadModule php5_module “C:/Program Files/PHP/php5apache.dll”
#END PHP INSTALLER EDITS – REMOVE ONLY ON UNINSTALL
I put a hash in front of the second and third instance of:
PHPIniDir “C:/Program Files/PHP/”
to comment them out. Apache and PHP loaded after that.
The second problem I ran into was that PHP was not loading the mysql library. Because of this, my local Wordpress installation was failing to initialize. I solved this by following the instructions here:
http://us2.php.net/manual/en/faq.installation.php#faq.installation.addtopath
I now have Wordpress installed in a directory …/htdocs/wordpress/test/. When I browse to …//localhost:8080/wordpress/test/, index.php does not load, and instead I see a listing of the contents of that directory. When I click on index.php in that list, nothing happens.
I am able to launch and run the Wordpress backend by browsing to …//localhost:8080/wordpress/test/wp-admin/index.php, but I have to click on the index.php file in the list in that directory to get it going.
So, the backend runs, but the front end does not. Further, when I browse to a directory, index.php is not automatically run. If I put a file in those directories called index.html, those will run.
Hi Sean,
I’ve done this so many times… I now usually get it right but I never remember exactly what I did. Let’s take a look…
This doesn’t surprise me. Everyone’s environment is just a little bit different, and these little differences are often invisible to the end user. For example, I just helped someone set this up a couple of days ago… and we thrashed for 45 minutes until we ended up rebooting his machine… whence everything Just Worked after that. On my last install, I didn’t have to reboot. Go figure.
The first major problem I had was that Apache was not loading correctly and PHP was not loading at all. I found that in the httpd.conf file for Apache, the directory to find PHP in was being defined 3 times. It looked like this:
This looks like you installed PHP several (3?) times, without removing the directives from httpd.conf after each removal.
Which may be why it loaded. Sometimes, you can do something like that, and for whatever reason, it decides to fire up anyway for some other reason.
We had the same problem. Two possible solutions come to mind:
Install MySQL before PHP, making sure you get the MySQL “Add to Windows” path option checked. This is what I did and everything worked out of the box.
Install PHP first, then reboot your pc after installing MySQL. This is what Travis did Friday night.
Try the following. On or about line 239, add “index.php” to the DirectoryIndex module:
If that works, I’ll add it into the article.
You’re very, very close.
I added index.php as you suggested to the httpd.conf file, and it worked like a charm!
I edited the file, rebooted so Apache would start with the edited configuration file, pointed my browser to my local wordpress installation, and presto!
I’ve got Wordpress running on one of my machines now.
Very nice.
I have some proble with wordpress.
Pl help me.
I have completed installation.But wordpress themes does not open my localserver.
i installed php mysql appache manual process.
thx in advance.
my doubt:
is there any setting need in my localserver?
There is no way I can help you debugging a localost installation specifically. You are going to need to work out which pieces are working, and which aren’t, then describe the issue in specific detail.
See Sean’s comments above for an example.
Successfully operating your own server *requires* understanding a fair bit of how it works, it’s very difficult to “fake it.”
Here’s how to start:
* Make sure MySQL is working. Use the command line or a GUI program, doesn’t matter which. There’s lots of resources on the web for this.
* Make sure Apache is working.
* Make sure PHP is working. Again, lot’s of resources on the web for this.
* Make sure you have WordPress installed correctly. If you haven’t ever installed WordPress before, you might want to try that on real host.
THERE IS NO SHORTCUT! You have to actually learn it.
I spent 5 hours yesterday working on debugging a path issue in a single function call. Today, I’ll be looking through the WordPress source to see it actually works in detail. You may need to spend the better part of week or two drilling into your setup.
Dear David, just wanted to say BIG THANK YOU for the article, which guided me through my first escape into open source web development from Visual Studo/Sybase/WCF/Client-Server mindset.
A few Windows Server 2008 issues aside (had to run installations from command prompt using “run as administrator” option), I was able to put this all together…simply amazing…
Elena, once you get the hang of this, you won’t ever want to go back. You’ll be using the same tools as some of the biggest websites in the world. And that’s pretty cool.
David M. Doolin, PhD´s last [type] ..Scribe SEO- An In-depth review and why your blog needs this tool
{ 3 trackbacks }