Marcos Placona Blog

Programming, technology and the taming of the web.

Month: April 2009 (page 1 of 2)

Apache 101 – Cache Control

Reading time: 2 – 4 minutes

Continuing with my Apache series, I’ll be today talking about cache control.

According to Wikipedia, the definition for cache is:

a collection of data duplicating original values stored elsewhere or computed earlier, where the original data is expensive to fetch (owing to longer access time) or to compute, compared to the cost of reading the cache. In other words, a cache is a temporary storage area where frequently accessed data can be stored for rapid access. Once the data is stored in the cache, it can be used in the future by accessing the cached copy rather
than re-fetching or recomputing the original data.

We are going to be using two different modules here mod_expires and mod_headers. They handle cache control through http headers sent from the webserver.

So let us install them:

sudo a2enmod expires
sudo a2enmod headers

We are also gonna be using mod_deflate, but since you probably read my last post where I tell how to install and configure it, I won’t be covering its usagein this post.

Now, on our vhost file, we will add a few directives. This is how I do when using this website as an example:

sudo nano /etc/apache2/sites-available/

And will add this anywhere before my tag:

ExpiresActive On
ExpiresDefault "access plus 300 seconds"

Which means I’m enabling cache, and it will only expire 300 seconds (5 minutes) after it was last accessed. You can change this to any value that suits you. I then add this to the bottom of my directory tag:

ExpiresByType text/html "access plus 1 day"
ExpiresByType text/css "access plus 1 day"
ExpiresByType text/javascript "access plus 1 day"
ExpiresByType image/gif "access plus 1 month"
ExpiresByType image/jpg "access plus 1 month"
ExpiresByType image/png "access plus 1 month"
ExpiresByType application/x-shockwave-flash "access plus 1 day"

Which is where I set specific MIME types to have specific cache times. The word access could be replaced by the word modified here, where access means the content “expires” after a certain period of time since it was last accessed, and modified means it expires a certain period of time after it was last modified.

You can now restart you Apache

/etc/init.d/apache2 restart

As I said previously, you could be doing it on your .htaccess instead of vhosts. You would only need to have the:

AllowOverride All

Command in your tag. I don’t like using it, as it creates security holes in the server, but that’s really up to you.

Well, and that’s all you have to do. I hope you’ve enjoyed this tutorial.

Sync your iPhone with Outlook (or Google) Calendar

Reading time: 3 – 4 minutes

We all know how painful it is to keep up to date with our meeting and
obligations. I’ve recently been thinking of a nice way to sync my calendars
from work and personal into a single account.
I then had a very specific spec for it, which is as follows:

  • I need to get my calendar pushed to my iPhone;
  • The calendar must be a merge of my personal calendar, and my business
  • I still want to be able to pick up my google mail emails;
  • I DO NOT want it to pick up my business emails (as I prefer to
    pick them up another way);
  • The calendar must be available anywhere and at anytime

Obviously Google Calendar springs to mind, as we
all know it’s online, and basically that pretty much makes sure you have your
calendar anywhere (as long as you have internet connection). It takes the last
item off my list, as it’s available anywhere, but i still had to work on the
other three items, and here’s what I did:
First of all, you need to make sure you iPhone software is at least on
version 2.2, otherwise this won’t work.
I the downloaded Google Calendar Sync and
installed it. It’s very straoght forward, as you only need to put your account
details into it, and say what kind of sync you wanna have.
In my case, I chose 1-way: Microsoft Outlook Calendar to google
this pretty much tells your MS Outlook Calendar to synch with
Google Calendar every x minutes.
Google Calendar Sync
I then checked my Google Calendar, and everything was there. Excellent, I
just had to make it sync with my iPhone’s Calendar.
I then found some information over at Google’s website. I’ll describe the
next steps here

  • Open Settings on your iphone;
  • Open Mail, Contacts, Calendars.;
  • Tap Add Account;
  • Select Microsoft Exchange;
  • Put an account name in the email field (not your actual google
    mail email);
  • Don’t put anything on domain;
  • put your google mail’s email address on username;
  • put your password (in the password field);
  • Click next;
  • A server field will appear;
  • Enter;
  • Click next and sync;

Make sure you select only calendars, as you have your email account already
And that should be it. in case you have different calendars in different
computers, you can simply follow the same steps of installation for each
computer, and your iPhone settings should remain the same, as everything comes
from Google Calendar.
source: Google Mobile Sync

Apache 101 – Compressing Files

Reading time: 3 – 5 minutes

I’m going to start a server configuration series here, where I’ll be talking about my goals and frustrations when configuring my own webserver. As most of you know, I’ve been using my own VPS for the last two weeks, and promised to post everything about it here.

I won’t be covering things like basic installation, or server set-up. There’s tons of them all over the web, and I ‘m sure most of them would beat anything I wrote here, as some of those guys are real *nix gurus, while I’m only a learner.

On this post, I’ll be talking a little bit more about Apache2, and it’s configurations; to start with, I’ll talk about file compression.

The apache server is a really amazing web-server, that let’s you configure almost everything, as well as create security rules.

Back to the topic, I’ll describe here a few of the necessary steps to enable compression on your apache server.

Compression saves you a lot of server traffic, and helps to make sure pages are served more quickly. It adds a little bit more load to the server, as the server needs to deal with compressed files now; but this will be automatically compensated by the page loading time, and can be easily remediated with some server caching (which will be my
next topic).

In earlier versions of apache, the compressing method used was GZIP. With the apache 2.x, the module has been replaced with mod_deflate, which is much easier to install, don’t need special configurations.

Before we get started, I need to make it clear that this is how you would proceed in a Debian based distro, and this might vary with other distros.

The first thing we need to do, is install the beast on the server:

a2enmod deflate

We the restart apache in order to have the module loaded:

/etc/init.d/apache2 restart

I like to configure compression on a vhost basis instead of global basis, but it’s really up to you. In my case, I simply open my vhost and update it.

sudo nano /etc/apache2/sites-available/

I then simply add the following lines inside my

# compress a few file extensions
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/atom_xml
AddOutputFilterByType DEFLATE application/x-javascript
AddOutputFilterByType DEFLATE text/html

It pretty much says everything, but basically, what I’m doing here is telling mod_deflate to compress files with the specific MIME types.

The next section is really important, as it “tells” your server to negotiate the best way to serve files to different browsers. Some browsers cannot handle file compression, and will get crazy when receiving compressed files, so it’s important the we also add the following lines right after our deflate commands:

BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4.0[678] no-gzip
BrowserMatch ^MSIE !no-gzip !gzip-only-text/html

And that’s all, simply restart your apache server again.

/etc/init.d/apache2 restart

Your files should now be served with 20 – 30% less volume than before. There’s a nice way to check that; go to this url, and check your website performance. On the results, it should say if your files are compressed or not. After applying the changes described above, all the MIME common text mime types should be listed as compressed.

BeerMe v0.2

Reading time: < 1 minute

This is a quick  update for this plugin.
I thought it was a bit boring and didn’t have enough focus. I’ve added some styles to it, and an image, so it looks much nicer now, as you can see at the end of this post
Again, here’s the link for the project download
I hope you enjoy it 😉

My first mango plugin: BeerMe?

Reading time: 2 – 2 minutes

Yes, I went on and got into Mango’s plugin development. Basically on Saturday I was a bit bored monitoring my new server’s performance, and decided to look at plugins development for Mango Blog.
It’s pretty straight forward really, and you only have to create a few files with some pre-defined functions, and off you go.
I always wanted to have a way of nicely asking for donations in my blog. We all know how much this things cost, and sometimes you need to step back, and kindly ask your five readers to make some donations in order to support your infrastructure and the efforts you make to always give a nice experience to them.
Of course I wouldn’t simply place a link to PayPal on the sidebar, so I decided to create this plugin. And that’s why in this post, I’m presenting:


BeerMe is a plugin for Mango Blog that allows you to add a link to PayPal at the bottom of each post. The links are personalized, so you can keep track of which blog post generated more donations.

It’s totally open source, and I still intend to make some changes to it; Also I’ll add a nice image to go with the paypal link (as soon as I have some time to create this image).
An example of the plugin can be seen at the enf of this post, right bellow the bookmark links, and above the tweetbacks. Why not click the link and make your donation? 😉

Click here to download BeerMe
Older posts