Gold Plated Blog Posts
Whatev.
Wednesday, June 6, 2007

We have liftoff

With the help of my co-worker Alec (whose finger is visible at right), I've managed to get the development of Popratings.com started. Every development project has a first step, and most of them involve the words "Hello, World!".

I'm really terrible at IT-related work so I feared setting up an environment would be painful but it was actually not so bad. I decided to go with Ubuntu Server Version 7 as a development environment. As a user, I'm more comfortable operating in Windows (which I'm not necessarily proud of, but it is a fact) but for programming, I've been working in Linux for the last 5 years so I prefer that.

Since I don't have a spare computer lying around, or space for one, I found a VMWare image at thoughtpolice.co.uk and have set up the environment there. To start working, I installed PHP 5.0, Subversion, and Vim using Aptitude, which was all very easy. I decided to go with Subversion mainly because I don't really know anything about it and I've heard good things. As for Vim, I haven't decided what I'm going to do for an IDE but Vim will suffice in the interim.

For a few different reasons, I want to have a lot of control over the way the URLs look in Popratings. Because of this, I'm using Mod_rewrite inside Apache to map all URLs that aren't images to a front controller, which I call TrafficController.php (although I certainly could have come up with a more useful name, this is my first PHP project in a couple years so I'll learn from my mistakes). In addition to providing his finger for the photo, Alec also gave me the idea to use .htaccess files to route traffic to a front controller class, although I believe you could also do it for an entire site as opposed to a single directory using 000-default in /etc/apache2/sites-enabled/. Alec used .htaccess files for a site he worked on a few months ago and said it worked out well.

I also decided to add a sub-directory for Popratings in the default directory that Apache serves files from (/var/www/) so that I can easily support more sites in the future from the same server. I can add directories to this folder as my list of sites grows. To accomplish this as well as the URL rewriting, I followed these steps:

  • enable Mod_rewrite by adding a symlink from etc/apache2/mods-available/rewrite.load to /etc/apache2/mods-enabled/rewrite.load. The command for that is ln -s /etc/apache2/mods-available/rewrite.load /etc/apache2/mods-enabled/rewrite.load

  • in /etc/apache2/sites-enabled/000-default, set the DocumentRoot to /var/www/popratings/ so that Apache knows where to get the files specific to Popratings

  • in /etc/apache2/sites-enabled/000-default, change /var/www/ to /var/www/popratings/ so that the settings in 000-default are applied to the files specific to Popratings

  • in /etc/apache2/sites-enabled/000-default change "AllowOverride None" to "AllowOverride all" to allow rewrites

  • create a file at /var/www/popratings/.htaccess so that I can control traffic sent to the document root

Then, my .htaccess file looks like this:
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^$ /home/
RewriteCond %{REQUEST_FILENAME} !^.*css
RewriteCond %{REQUEST_FILENAME} !^.*js
RewriteCond %{REQUEST_FILENAME} !^.*jpg
RewriteCond %{REQUEST_FILENAME} !^.*gif
RewriteCond %{REQUEST_FILENAME} !^.*png
RewriteRule ^(.*)$ TrafficController.php?uri=$1
There are a couple notes to mention here. One is to make sure that when you add "FollowSymLinks" to Options, if you leave the plus sign out, you'll override the other settings for Options that are defined in 000-default. This is a problem if you're writing PHP (and other non-HTML languages) because you'll get a "Forbidden" error. From what I've read of the documentation, I think it's because the "MultiViews" Option gets overridden, although I may be mistaken. At any rate, using the plus sign in front of FollowSymLinks adds it to the other options rather than overwriting them.

To explain a bit about the rewrite rules and conditions, the first rule states that if there is nothing after "popratings.com" in the request, direct the traffic to /home/. The next conditions take all images and include files out of the scenario and tells everything after "popratings.com" to be added as a parameter to TrafficController.php with the name "uri". Note that this includes cases where a user was just accessing the home page, in which case "/home/" is added as the uri parameter. In other words, the URL continues through the redirect rules even after being altered by one of them. Also note that the list of files to exclude from the rules is probably incomplete; you may want to add .exe, .pdf, and/or .xml, among others. As the list gets longer, you may want to change the regular expression so that it only requires one RewriteCond for all necessary file types.

This information was all available on the web but it was not usually specific to my operating system and was not all in one place, so it took a little work. I'm now ready to get some real work done. Unfortunately after setting up this environment, I sat down to actually do that work last night and realized that while I know a lot of design theory, I've forgotten almost all the PHP practice :-( While the progress may take a little bit of effort to get going, I'm sure it will be like riding a bicycle.

Saturday, June 2, 2007

Heavy reading

Since leaving Portland for India, I've had more time to sit and read than I normally would. I saw this coming and in the weeks before I left, stocked up on some interesting reading. As a pet project, I'm going to start building a website for a domain name I registered over a year ago, Popratings.com. Right now it's just a lot of ads from my registrar but when it's finished it will be a site for users to submit reviews on various things. I'll get more into the details of the functionality in a later post, but rest assured that it will include social networking, Web 2.0, and Ajax, as well as any other buzz words that happen to be popular at the time. It's really just a way for me to get back into programming and, more specifically, into PHP.

Since this project is aimed at getting more familiar with some of the technologies I've used in the past and using some skills I've picked up while working at my current job, I want to do everything myself. Given that this covers several different areas, I chose four books to read based on what I'll need to know and what I'm not already comfortable with. The four books are The Principles of Beautiful Web Design by Jason Beaird, User Interface Design for Programmers, by Joel Spolsky, PHP 5 Objects, Patterns, and Practice, by Matt Zandstra, and Beginning JavaScript with DOM Scripting and Ajax: From Novice to Professional, by Christian Heilmann.

I've only had a chance to read the first three selections but so far they're all worth reading. Joel Spolsky is someone who I have a lot of respect for as a developer and an entrepreneur. I've been reading his blog over the past year, which is what prompted me to get his book. Although it's a bit brief, he really has some very simple but effective things to say. His book has stood out the most as being a valuable asset for anyone designing user interfaces- it should definitely not be limited to programmers.

The second two books have certainly been useful. Beaird had a lot of good techniques to share. Towards the end of the book, he walks us through the process of designing an actual website for a client he had, which was helpful. Some of the material throughout was covered in my high school art class but I'm sure it's helpful for many people.

PHP 5 Objects, Patterns and Practice has been a great source of information. The first third covers new features to PHP 5, which you can really skim through if you know Java (yes, Java). The last third covers several PHP tools, including package managers and automated build tools, and will be a great reference. The heart of the book focuses on implementing several design patterns in PHP. There's actually not very much PHP-specific information in this portion. In fact, you might be better off reading the beginning and end of Zandstra's book and Design Patterns: Elements of Reusable Object-Oriented Software by the "Gang of Four", which is referenced throughout PHP 5 Objects, Patterns and Practice.

I'm looking forward to putting these to use; I plan to start writing Pop Ratings in the next week and hope to get a lot done while I'm in India. As I go along, I'll be logging anything particularly difficult or interesting that happens so that hopefully it will be useful for others working on similar projects.

The articles in this blog are authored by Cameron Hinkle, Software Engineer for Nike. The thoughts and opinions expressed are not shared by Nike or any of its affiliates.