Resources: Linux and Apache

With explaining the inner workings of all the switches, you can extract / compress .tar.gz archives easily with the following codes:

Compress .tar.gz

$ tar cvzf archive_name.tar.gz dirname/

Extract .tar.gz

$ tar xvfz archive_name.tar.gz

So I’ve been delving further into getting a development server running, and have built a fully functioning webserver running with Ubuntu on an Oracle VirtualBox. Who says you need flash hardware?!

So I pull down a full backup of all my sites, and cross my fingers that all runs without any further hacking. This is infact the case, with the exception of ONE small (but significant) problem – none of my .htaccess rewrites are working, including those within WordPress.

After much testing, hacking and breaking, I managed to figure it out. Within your .htaccess file (or site configuration file, in my case /apache2/sites-available/james), add the following code:

Options -MultiViews

Now I’m not totally sure of how it all works, but it solves the problem, so I’m happy!

Developing a site and you want to have a nice temporary page for visitors? Drop in this code at the top of your .htaccess file and make your pretty 'Coming Soon' page in the root called 'offline.html'.

RewriteEngine on
RewriteCond %{HTTP_HOST} example\.co\.nz [NC]
RewriteCond %{REQUEST_URI} ^/$
Rewriterule ^(.*)$ http://example.co.nz/offline.html [L,R=302]

Struggling to track down where your hard drive or web server space is going? This command prints out the 20 largest files and folders:

du -a /home | sort -n -r | head -n 20

Having issues with upper and lowercase file names? Use this script to programatically convert all extensions to lowercase. It will affect all files within the current folder.

find . -name '*.*' -exec sh -c ' a=$(echo {} | sed -r "s/([^.]*)\$/\L\1/"); [ "$a" != "{}" ] && mv "{}" "$a" ' \;

You can relatively easily set up uTorrent to run as a webUI from your webserver. This requires Ubuntu 9+ and a download of uTorrent. Make sure you also install PeerGuardian!

Read more

Out of the box, most webservers will run Apache processes as user 'www-data', which has it's own group. If you then try to move/delete/edit any files created by this user via FTP or SSH, you are likely to be denied access. This often happens when files are uploaded with a CMS. Login via SSH as root and drop in this command which will add your user to the www-data group. This will allow your user to edit files that are shared within the www-data group. Win!

sudo usermod -a -G www-data [yourusernamehere]

Often you'll need to transfer a file from your webserver to your local environment. This can be a bit tricky if your local environment is a headless webserver (or you just don't like FTP). With this command you can transfer your files over an SSH connection, when your remote server is running a non-standard SSH port.

rsync -av --progress --rsh='ssh -p1234' [email protected]:/remote/file /local/folder/

Recently I needed to redirect traffic when the domain was NOT www.website.co.nz. This is often handy if you have several domains hinged off one virtual host.

RewriteCond %{HTTP_HOST} !^www\.website\.co\.nz$ [NC]
RewriteRule .* http://%{HTTP_HOST} [R=301,L]

Personally I prefer web URL's to exclude www, and so I implement the following code on all project's .htaccess file:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.jamesbarnsley.co.nz$ [NC]
RewriteRule ^(.*)$ http://jamesbarnsley.co.nz/$1 [R=301,L]

Another reason this is important is that www.yoursite.co.nz and yoursite.co.nz are treated as two unique websites. Any SEO rankings for yoursite.co.nz does not apply to www.yoursite.co.nz!

1 2

Let's work together