Ubuntu Icons Directory Routing

I had the weirdest problem the other day so I thought I’d write it down! I uploaded a toy script for someone, but it had images in it and they wouldn’t load. The image files existed, and I could request everything around them, files in other subdirectories were okay; the same files in other subdirectories also served correctly. Yet in my error logs I just had lots of:

File does not exist: /usr/share/apache2/icons/ ...

Which was really odd, because my webroot is somewhere else completely!

Eventually I spotted a /icons entry in the configuration for mod_alias in apache, which intercepts all requests to /icons on any virtual host, and rewrites it. Err, thanks? Renaming the directory to “images” solved the problem in this instance, and I hope if you googled for an error message, you will find this page and be able to fix it equally quickly :)

Apache Config: .htaccess or Virtual Hosts?

How to set apache configuration for your web projects? Some settings have to be in the main apache config or in a virtual host, but for many others you have two good choices; either use an .htaccess file, or place the setting in the vhost (virtual host) configuration. Which one you choose depends largely on your project setup, let’s look at each in turn:

The .htaccess File

The biggest item in favour of an .htaccess file is that it belongs in your webroot, and can be checked in to your version control tool as part of your project. Particularly if your project is going to be installed by multiple people on multiple platforms, this can be a very easy way to get development copies of code set up very quickly and for it to be easy for developers to see what should be in their .htaccess files.

With version control, you can also send new .htaccess configuration through by updating your copy of the file – but whether this is a strength or a weakness is up to you to judge! If everyone needs different path settings, for example, and is constantly overwriting your .htaccess file, that’s not a particularly excellent setup! Previously I’ve distributed a sample .htaccess file with a different file name, and added .htaccess itself to the ignore list of the version control tool.

The Virtual Host

Putting settings in the virtual host allows an easy way to configure the environment on a per-server basis, and not to accidentally deploy an incorrect setup. You could still distribute a sample vhost setup for people to use as their basis, exactly as you could for .htaccess.

The biggest reason for using the virtual host, especially on a production server, is that using .htaccess incurs a performance penalty. When you use .htaccess, apache looks in the current directory for an .htaccess file to use. It also searches in the parent directory … and that parent directory’s parent directory … and so on, up to the root of the file system. Imagine doing that on every request to a system under load!

Which To Choose?

It completely depends. At one end of the system, the open source project that will be set up on a relatively large number of systems by potentially inexperienced people – you’d probably choose .htaccess. For a large-scale, live platform deployment, use the apache settings themselves (a virtual host for a server which runs multiple sites – apache’s own settings for a server which only hosts a single site). Where are you on the scale and which will you choose?

Building A RESTful PHP Server: Understanding the Request

Once upon a time, what seems like a lifetime ago, I was away for a couple of weeks, and I wrote a series of posts about serving RESTful APIs from PHP to keep my blog going while I was away. Fast forward a few years and those posts are outdated and still wildly popular – so I thought it was about time I revisited this and showed how I’m writing RESTful PHP servers today!

In the first part of this (probably) 3-part series, we’ll begin with the basics. It might seem boring, but the most important thing to get right with REST is parsing all the various elements of the HTTP request and responding accordingly. I’ve put in code samples from from a small-scale toy project I created to make me think about the steps involved (should I put the code somewhere so you can see it? Let me know). Without further ado, let’s dive in and begin by sending all requests through one bootstrap script: Continue reading

Apache on Ubuntu/Debian

Apache on Debian. Ubuntu

When I first started using Ubuntu, I was coming from a distro journey that started with FreeBSD and took in Mandrake and Gentoo along the way; I hadn’t worked with any Debian-based systems before and was new to the way that Apache is configured on those platforms.

Continue reading