Since I rebuilt my VPS the other day there a number of tweaks and changes I need to make which can speed up the website – one of the easiest ones with the biggest effect on pageload time is to have apache serve compressed versions of pages to users. Here’s how to do it, and test that it’s working.
Enabling mod_deflate and mod_headers
Chances are good that you already have mod_deflate and mod_header on your server (they typically come with the apache install) – so all you need to do is enable them. To do so, open your main apache config (for example, on mine it’s /etc/httpd/conf/httpd.conf and uncomment the LoadModule lines for each module, so that they end up like this:
With that done, you can head down to the bottom of the config file and add the following section to enable compression of all html, css, js, xml and such.
The .ace compression format is rather legacy, but you still find the occasional old file compressed in it, and p7zip-full won’t extract ’em. There’s a package in Ubuntu 10.04 called unace, and you’d expect this to do the job – only it doesn’t. It’s version 1.2 which is absolutely legacy…. I mean seriously, it’s archaic – and it won’t extract “modern” .ace files.
So, to get this all sorted, just head on over to Softpedia and grab unace v2.5 (which itself was built in 2003!), extract the tar.gz, and then either use the unace binary from where it is or sling it in your /usr/bin/ directory for convenience.
Lets say you’ve got a bunch of folders taking up a large swathe of space which you never really use but want to keep, just not taking up stacks of your NAS… How can you easily compress them all up to individual archives of each folder? Dead easy:
Save that to a file, chmod +x it and run in the location you want to compress the folders. Every folder (and all contents within) will be compressed to its own foldername.7z archive.
With 7z, -mx9 is the flag for maximum compression, and -mmt says to use multiple CPUs to speed up compression, so omit that part if you’re on a single core machine.
2016 Now-That-I-Think-Of-It Update
The way I use this script is by simply putting it into a file called zipeach, making it executable, and then moving it to /usr/local/bin – which makes it convenient to be able to compress all folders in your pwd at whim.
Also, in case it’s important to you, the 7z format does not maintain file permissions, so if you need to preserve file permissions then you’ll likely want to compress each folder into a .tar archive, and then compress that into a .tar.7z.