New Server

This site has moved to a new VPS from ChicagoVPS. The only reason I am no longer with ChunkHost is because I was able to get a server will better specs for half the price. If you run a site that actually gets traffic (not like my sites) then I still highly recommend ChunkHost.

FatFree PHP Framework rewriting with Lighttpd

I’ve been working with PHP for several years now, but have never used any of the numerous frameworks out there. I’m a little late to the game, but I figured it was time I started being a little more productive. There is no need to write all of the boring stuff if there is already a framework that will do it for me.

I’ve decided that my first framework to toy with will be FatFree.  Everything worked perfectly if I only had a default route, but trying to use additional routes always resulted in a FatFree generated 404 page.  I’ve spent the last hour looking through the documentation (and searching the web) for the proper Lighttpd rewrite rule, but they were all exactly the same as what I already had.  I decided to try the same trick with FatFree that I used for WordPress permalinks – setting the 404 error page to index.php.

 

$HTTP["host"] == "example.com" {
server.document-root = "/home/jason/www/example.com"
server.error-handler-404 = "/index.php"
}

Immediately, my routes were all working!  I’m sure this will cause some sort of issue down the road but I am happy for now.

Setting up your own Git server

Even for just the hobbyist programmer, a good way to keep track of your changes is always a good idea.  There are many options out there, but why not have a little fun and set up your own Git server?  It is incredibly easy to do.

Since I am a lone programmer on most things, I’m not going to bother with a multiuser setup.  Remember, this is with the hobbyist programmer in mind.

While ssh’d into your intended server, install git.

$ sudo apt-get install git-core

Well, that was painless.  Git is now installed and ready to go.  It’s pretty empty right now, so how about we add a new project?  While still logged into your server, create a new Git repository.

$ mkdir NewProject.git
$ cd NewProject.git
$ git init --bare

And done.  We can now log out of our remote Git server and grab our new project.

$ git clone user@example.com:NewProject.git

Now you can start writing your new project and feel safe from the bonehead mistakes that can wreck a few hours of work.  For more information on the usage of Git, check out Git for the lazy.

Mitigate the @font-face lag

I recently discovered @font-face and I quickly realized it is going to be in my toolbox for a while.  I decided to utilize this new found wonder while working on this site.  I found nice fonts and tried not to go too overboard with it.  I think it looks good.

There was a problem though.  There was a lag between the site loading, and the fonts displaying.  From what it seems, the fonts are downloaded every time, and only after everything else has loaded.  I didn’t like this and decided to turn to a technique I tend to shy away from, a Data URL.

A Data URL is a way to embed data directly into the code of a webpage.  An example would be encoding an image into the HTML/CSS of a page and then displaying it without an additional download. This is good if you want to distribute a single file with all the resources needed to view it properly without including several files. This is handy, but it can increase the file size significantly.  Many times, the encoded resource is larger then the original. There are trade offs.

  1. Generate base64 string
    • $ base64 fontname.ttf > fontname.base64
    • This generates the string, but it has new line characters in it. We don’t want those.
    • $ tr -d ‘\r\n’ < fontname.base64 > fontname.final
  2. Paste base64 string into our CSS
    • Our original @font-face looked like this:
      @font-face { font-family: fontname; src: url(‘fontname.ttf’);}
    • Open up fontname.final in your text editor of choice and copy all of it to the clipboard.
    • Paste the follow code overtop of the original and put the encoded data in the right spot. Make sure there aren’t any new lines.
      @font-face { font-family: fontname; src: url(‘data:font/opentype;base64,[ENCODED DATA]‘);}

Done. Now you get all the benefits of providing your own fonts without the lag that normally comes with it.

Roll your own WordPress Server

While setting everything up for the relaunch I decided to document my steps and make it my first tutorial.  Smart, huh?

For this tutorial I am using a 512MB VPS from ChunkHost running Debian 6.  I absolutely love ChunkHost, but that is a topic for another discussion.

This tutorial assumes you have a basic understanding of the Linux shell and are comfortable editing files.  You will also need, at least, sudo access to install and edit configurations.

After the headache that NginX has given me in terms of PHP, I decided to go with Lighttpd this time around.  I was amazed at how painless everything was.

  1. Install Lighttpd:
    • $ sudo apt-get install lighttpd
  2. By default, Lighttpd looks in /var/www for content.  I prefer to have everything in my home directory.
    • $ mkdir /home/jason/www
    • $ sudo nano /etc/lighttpd/lighttpd.conf
    • Here we want to change the server.document-root to /home/jason/www
  3. Now, let’s start Lighttpd.
    • $ sudo /etc/init.d/lighttpd start
  4. Install MySQL and PHP
    • $ sudo apt-get install mysql-server php5-cgi php5-mysql
    • You will be prompted for a MySQL root password. Don’t forget it, we’ll need it later.
  5. Enabling PHP support in Lighttpd
    • $ sudo nano /etc/lighttpd/conf-enabled/10-cgi-php.conf
    • In this file, we’ll want the following.
      • server.modules += (“mod_cgi”)
      • cgi.assign = (“.php” => “/usr/bin/php5-cgi”)
  6. Reload Lighttpd
    • $ sudo /etc/init.d/lighttpd force-reload
  7. Create MySQL database and user
    • $ mysqladmin -uroot -pPASSWORD create wordpress (your root password from earlier)
    • $ mysql -uroot -pPASSWORD
    • mysql> grant all on wordpress.* to username@’localhost’ identified by ‘password’ (You pick the username and password here)
  8. Install WordPress
    • $ wget http://wordpress.org/latest.tar.gz
    • $ tar zxf latest.tar.gz -C /home/jason
    • $ cp -r wordpress/* /home/jason/www

And, that’s the hard part. Not so bad, huh? As long as your have your DNS pointing at your VPS, just fire up a browser and point it at your domain. You should be prompted with the first step of the WordPress isntallation process.