When I’m working on WordPress related development (ie themes and plugins), I like to run WordPress locally. This is great for trying things out before it goes live and also lets me squeeze in some development time in on the train!
My web server package of choice is XAMMP Lite, the Apache distribution that contains PHP and MySQL. Works great in general, but I had some problems with WordPress permalinks and XAMMP Lite. Here’s the solution.
Trivia: In the past, I was forced to use IIS as my web server, because Apache had a known bug that conflicted with my Internet connection. Basically, I could have Apache running locally OR an Internet connection, but not both! So IIS it was. However, I recently changed ISP and was freed from this constraint!
My XAMMPLite / WordPress Environments
It’s important to note that I keep the XAMMPLite and WordPress environments separate. Rather than copying each WordPress site into the XAMPP Lite structure, I keep it in a separate folder and set up a Virtual Directory pointing to it. This makes it easier to keep track of things.
For example, rather than putting the WordPress installation for the site I’m working on in c:\xampplite\htdocs
, I store it in c:\dev\sites\sitename
. I then set up a Virtual Directory so that XAMPP Lite’s Apache installation can find the folder and can serve it via http://localhost/sitename
.
Now, I’m no Apache expert, but setting up a Virtual Directory was pretty easy: I simply added the following lines to the Apache configuration file (C:\xampplite\apache\conf\httpd.conf
), substituting sitename with the appropriate name:
[sourcecode language=”xml”]
Alias /sitename "C:\dev\sites\sitename"
<Directory "C:\dev\sites\sitename">
Options Indexes MultiViews
AllowOverride None
Order allow,deny
Allow from all
</Directory>
[/sourcecode]
This gave me a virtual directory that worked, but I couldn’t get the WordPress permalinks to work properly.
The Permalink Problem
What was the problem with the permalinks? For me, all of my posts and pages returned a 404 error. Great!
There’s a workaround: put /index.php/
at the start of the permalink structure (ie /index.php/%postname%/
). However, while this works, it means that the local permalink structure will be different from that on the live site.
That’s no good for me. The menu links for my themes are often hardcoded, at least to the extent that they will break if the permalink structure changes. I don’t want to have to recode the theme to run it locally!
At least the root cause of the problem was obvious: XAMMP Lite was ignoring the .htaccess file created by WordPress. I just needed to get XAMMP Lite to respect the WordPress .htaccess file. I knew there had to be a way to do this.
The Solution
It turned out the problem was caused by the code I used to set up the Virtual Directory. As I said, I’m no Apache expert! I found the solution on rudy egenias jr’s site. Instead of the code above, I should have entered the following (in the C:\xampplite\apache\conf\httpd.conf
file):
[sourcecode language=”xml”]
Alias /sitename "C:\dev\sites\sitename"
<Directory "C:\dev\sites\sitename">
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Order allow,deny
Allow from all
</Directory>
[/sourcecode]
Note the differences: AllowOverride has changed from None to All. Options has changed from Indexes MultiViews to Indexes FollowSymLinks Includes ExecCGI.
Problem almost solved. There’s one more thing to check to make sure that the WordPress permalinks work: In the httpd.conf
file we have to make sure that the following line is uncommented (ie remove the ; before it):
[sourcecode language=”xml”]
LoadModule rewrite_module modules/mod_rewrite.so
[/sourcecode]
Once that’s done, WordPress Permalinks should work perfectly with XAMMP Lite. Mission accomplished.
So Stephen, during the transition from the virual directory to going live, all of the permalinks were bad? Did this have anything to do with what you said in your trivia comment about changing isps for running locally and internet? Forgive my stupidity, as I am a novice to web-development. I have learned a lot from your posts and thank you for sharing all of your great knowledge.
mine, I am using EasyPHP2.0 instead but it seems that they have stopped developing this system. I actually tried XAMMP and really find it very helpful with some of my PHP experiments.
Xaamplite really is great for setting up a local wordpress install – I found that it is great for customizing and building wordpress themes and trying out different things. I was lucky, I didn’t have any problems with the permalinks or anything else 🙂
Thanks for the information. I use Xaamplite for testing and developing wordpress locally as well. I’ve thought about setting up a virtual directory for the same reason. I’ll definitely keep this bookmarked.
LINK REMOVED: because of failure to use KeywordLuv syntax (name@keywords)
Really didn’t think you’d have a problem with the two, I do like Xaamplite, it’s very easy to use.
Thanks for this. I run WordPress locally to test various things and stay up-to-date on the current version of WordPress. I’ve always wanted to take the time and resolve this and you’ve done it. Excellent job!!
Instead of running WordPress locally, I use a little server that I call my “Sandbox” for prototyping and experimenting. The hardware is just an old P4 that has been retired, but it can run on most anything, even a P3 or Celeron. The software is SME from contribs.org. SME can do lots of things and is a self contained Linux distribution. Check it out.
yup, it is great tool, I always use it for building a website before published..
I just started using xammplite last week to practice creating wordpress themes. I noticed this limitation when I started with my first theme but didn’t have time to digg into how to solve it. Luckily I stumbled onto post. This will be a great help when I get around to working on multiple projects at one time.
I’ve been meaning to get a local copy of wordpress running, but haven’t been able to yet. I find working with servers is so annoying… just give me my CSS and HTML, leave the server work to the real nerds.
Yes I am also facing same type of problem thanks for this…I will surly test it
going to a 404 error really sucks especially when you didn’t know.
Hi,
Thanks for the solution of the 404 error.
I have tried XAMMP before but got discouraged by some headaches that pops up every now and then. I have not tried XAMMPLite but I assume the headaches I’d get would be the same, hopefully ‘lite-r’ if I try it. These days, I’m using MoWeS Portable. I can attest to its bug-free headache-free performance. I installed it in my flashdrive and I can take all my work wherever I like, in whichever computer.
Thanks for this. I made the virtual hosts with your solution in Mamp (Mac) and it works perfect. Now I can enjoy my pretty permalinks locally
Hi Kees,
Thanks for the feedback – glad that it works on MAMP as well…