Enabling mod_rewrite and .htaccess in the LAMP Virtual Appliance
Life is just one damned thing after another.
–Elbert Hubbard
In the past few weeks, there’s been a figurative landslide of tiny problems that have produced (ironically enough!) a pretty unproductive stretch of time here at OEIC Labs, which is how I’ll now be referring to myself. Fortunately, I’ve found that these times teach me how the technologies I use every day actually work, and leave me wiser in the long run. The challenge is keeping a positive mindset, rather than dropping a double axehandle on my monitor. Or so I’ve been told.
Since I’m sure you’re chomping at the bit, frothing at the mouth and generally getting all lathered up in exertion over the prospect of reading exactly what technological hurdles I’ve had to jump over, allow me to present them.
For a new project, I needed to integrate RETS Retriever with cakePHP. RETS Retriever is a PHP application that connects to a Real Estate Transaction Standard (RETS) server, makes formatted requests and displays the returned real estate listings. Since it’s an application, I figured on installing it, running a configuration wizard and that’s about it. If you’ve read my blog before, you’ll know I was wrong.
Installation: check! Configuration: check! Retrieve listings: uh, no dice! I assumed my configuration was incorrect, so I changed the server URL four different ways and was still unable to connect. At this point, as I usually do, I delve into the code to see what’s happening. After tracing through the stack, I find the connection call, plug in a static value of google.com, and am able to open a connection. Hmmm. Why can’t I open a connection to the RETS server then? Because RETS operates on port 6103, of course. And my hosting company has it firewalled. And won’t open it. Lesson 1: Never use shared hosting if you’re a developer. Surprising it took me three shared hosting companies to learn this. Zing!
Ok, I’m going to need a new development server for the project. I’ve been wanting to experiment with VMWare Server and Virtual Appliances for a while, so here is the perfect opportunity. I download the two products, after determining the server I’m going to install them on had a bad NIC that was eating my internet connection. I only wasted one day talking to Verizon about that though. I get the appliance running on the server, and everything works! You can see that I’m unaccustomed to such wild success. I install RETS Retriever on my new VM, and get a connection to the RETS server.
Now we’re cooking! The only problem is that the RETS server isn’t returning any listings. I’m fairly certain there are some properties on the market somewhere in this great nation, so I know I’ve got something to work out. Once again, I do a stack trace through the code, and determine there’s a configuration issue. Lesson 2: It’s usually a configuration issue. Don’t waste time poring through code, if there are config files to play with first. Assume you’re the idiot first, not the other guy.
Luckily, thanks to my code perusal, I find a nice debug feature that I enable in the Retriever code, and I learn I’m passing bad parameters to the server. Lesson 3: Anything that has Standard in its name will be anything but. There are a lot of RETS server implementations out there, and they disagree about what defines a real estate property. Anyway, I get rid of the bad parameters one by one, and finally pull down some listings. A tiny triumph!
After about three days of poking around at something that I thought would take 2 hours, I can finally start working on the meat of the problem, integrating Retriever with cakePHP. I get the latest cake release, unpack it to my VM, open it up in Firefox and discover that mod_rewrite isn’t enabled in Apache. This I did not expect. Uh guys, every major open source application from the last 3 years uses mod_rewrite in some capacity. If you want this VM to be used as a server, mod_rewrite should be enabled. Now I have to hunt down the Apache configuration files, which are always different for the different Linux distros.
Aha, after nine paragraphs of prefacing, we finally arrive at the title subject of this post! Release your clenched jaw and rejoice! Enabling mod_rewrite for the Ubuntu 7.04 LAMP Virtual Appliance is quite simple via the command line:
cd /etc/apache2/mods-enabled ln -sv ../mods-available/rewrite.load rewrite.load apache2ctl -k graceful
Apache restarts and mod_rewrite is enabled, so I pull up my cakePHP install again and see that my CSS can’t be found. This is most curious, so I assume it is because the cake packaged .htaccess file is wrong in some fashion. I replace it with another .htaccess file I know works with cake, but no luck. Is it possible, dare I say it… .htaccess is disabled too?
Indeed, that’s the case. .Htaccess is being ignored by Apache. I’m shocked. Why? For a virtual server advertised as uniquely easy to use, there are quite a few oversights as to what it would actually be used for. Anyway, it’s also quite simple to enable .htaccess:
vim /etc/apache2/sites-enabled/000-defaultOn line 12 of that file, replace
AllowOverride None
with
AllowOverride All
and restart apache with the apache2ctl -k graceful command from above. Now you have a functional LAMP web server! That’s all it takes - now I can get some work done. It makes me wonder what to call what I’ve been doing for the past 4 days. Pre-work? Work-like? Workishness?
Lesson 4: It always take 6 times longer than you think it will.
2 Comments Jump to comment form | comments rss | trackback uri
September 14, 2009 / 3:17 am
This post was a big help, I was sure I’d done everything correctly in enabling mod_rewrite but didn’t realise that htaccess was disabled. I can’t believe that this stuff isn’t already setup, after all most modern web apps use these features.
Say what?
XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>
About this entry
Categories
- App Design (8)
- Blogs (6)
- Business (4)
- Code Philosophy (2)
- Javascript (1)
- Open Source (5)
- PHP (15)
- Thoughts (2)
- Tools (10)
- Usability (3)
- Wordpress (2)
- Zend Framework (9)

February 5, 2008 / 11:41 pm
This is really helpful, thank you.