WordPress & Apache Virtual Hosts
April 27th, 2008 chris

Yesterday I spent about 4 hours trying to figure out why virtual hosts weren’t working for me, so I thought I’d spend a few minutes writing it down in case it helps anyone else.
I had originally set up a WordPress 2.5 installation in /var/www/blog of my Apache 2 document tree. This worked fine, but I later decided to use a specific domain for the blog (cristoblanco.com), and point it at the same server. Apache has a feature called Name-based Virtual Hosts that allows you to host multiple domains on the same server with the same IP number
In Apache 2, you put your new domain config file in the /etc/apache2/sites-available directory, and then enable it by running a2ensite. After following all the instructions, it still wasn’t working for me. When I typed cristoblanco.com into the browser, it went to the top level of my original domain instead. I did the usual google searches, and tried some of the things they suggested. It’s funny what you’ll try when you feel like you’ve exhausted all possibilities. Still no luck.
I woke up this morning and thought, well let’s debug this. I put an index.html test file into the blog directory, and tried cristoblanco.com again. It worked! So, it all started to make sense. Either php wasn’t working (WordPress uses an index.php file), or it was something else. Well it turned out to be something else. WordPress needs to be configured for the domain, otherwise it just redirects back to the top level of the domain. So I used their admin tool to change the domain name, and now everything works. Seems so simple when you look back at it, but that’s how bugs often are.
I hope this helps someone.
Posted in Technology | 2 Comments »

