Category Archive: Servers

Subcategories: No categories

Creating a RAID array

Specifically a soft Raid 1 array on ubuntu 11.10. This guide is not for raiding your boot/main drive, but rather an extra ‘data’ array.

First thing you will need is a computer/server with 2+ drives (that you don’t mind loosing the data on), the Raid mirror will end up being the smallest of the two. You may use/mix advanced format 4KB drives, but I’ll get to that later.
(more…)

Htaccess rule creator for new to old urls

Here is a tool to create redirection rules, primarily for rewriting pages based on a query string to a nice seo url.
Created because .htaccess files are the easiest way to break an entire site.

http://www.xnet.tk/CreateRule.php

Example:
Old Url: http://www.xnet.tk/index.php?page=123&something=else
New Url: http://www.xnet.tk/htaccess/rules/

The generated rule would be:

RewriteCond %{QUERY_STRING} ^page=123&something=else$
RewriteRule .*  htaccess/rules/? [R=301,L]

It can’t handle crossing domains (yet).

lighttpd, php and clean urls

Here’s a situation, You have php running on a lighttpd server via fastcgi and you want clean urls (ie. /post/123/postname).

The typical way to-do this with lighttpd is to set the error-handler to your script.

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

We use an error-handler here rather than rewriting the url as with apache because there’s no way to detect if the url is actually a file (ie. your css/js files).

Problem here is that this will break query strings for anything other than the root url (query strings are what’s after the ?). ie. when accessing /post/123/postname/?confirm=true the confirm will not appear in the $_GET or $_REQUEST arrays while /?confirm=true will.

So how do we fix this? The method I’ve used is to manually parse the query string and put its values into the get and request arrays, as below.

function fix_query_string()
{
    $url = "http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
    $query = parse_url($url,PHP_URL_QUERY);
    if ($query == False || empty($query))
        return;
    $_SERVER['QUERY_STRING'] = $query;
    parse_str($query,$query);
    foreach($query as $key=>$value)
    {
        $_GET[$key] = $_REQUEST[$key] = $value;
    }
}
if (stripos($_SERVER['SERVER_SOFTWARE'], 'lighttpd') !== false)
    fix_query_string();

Hope this helps!

MySQL backed SMTP+IMAP Mail server on Debain Lenny

This is a guide for setting up a mail server with a mysql backend for users and domains using Dovecot for the IMAP Server, Postfix for the MTA and SpamAssassin for preventing spam and all with SSL client-server encryption.

I’ll also assume you have a MySQL server ready for use.
(more…)

Hardware vs Software Raid

Hmm.. Which is better?

I would say software raid is better*, my reasons:

  1. Software raid follows the OS around, upgrade all your hardware, your raid array will still work (In Theory)
  2. Software is easy to update, Firmware is not
  3. If your on a budget, do you really want to trust a cheap raid controller?

[*] Under most conditions, ie. without big budgets, mission critical servers etc…

See Also:
Stackoverflow Blog: Tuesday Outage: It’s RAID-tastic!
Linux: Why software RAID?

Making better use of mod_deflate

Output compression using Gzip and Deflate is a common feature of modern webservers. Webpages can be compressed by the server and then decompressed by the client seamlessly.

By default (at least on debian/ubuntu) Apache has a module installed and enabled called mod_deflate. While great, here is the default configuration:


      AddOutputFilterByType DEFLATE text/html text/plain text/xml

Now at a glance this is fine, But modern webpages consist of more than just html, we have CSS, Javascript, RSS and even JSON, all of which can benefit from compression but aren’t enabled by default.

Here’s a modified config file that will compress these files:


      AddOutputFilterByType DEFLATE text/html text/plain text/xml application/javascript text/css application/rss+xml application/json

This config is usually located at /etc/apache2/mods-enabled/deflate.conf.

With this done jQuery (minified) goes down from 54KB to just 16KB of data send to the client :D

New Webhost!

Moved to xenEurope

I was using a westhost VPS, and although this was fine and the support was brilliant, with the server being in Utah, USA, the latency was poor (~250ms), The server also seemed fairly loaded.

So I’m now with xenEurope, which so far is great, a proper VPS server instead of the cut-down redhat one that westhost provides (with no root access), I now have root access and so have the ability to set it up how i like :D I’ve have setup a Debian 5 (Lenny) server, running apache2, postfix+dovecot (mail), bind9 (dns), MySQL and webmin (web-based server administration). And all in 128Megs of ram :)

The latency for me is just 30ms, and the server is very snappy (as you may notice). But the best part is the price, at 10Euros/month its far cheaper than most UK VPS hosts while being as good.

PHP Soap Server, Part 2: PHP Server and Client

This is in conclusion to Part 1

The example soap service that i will build for demonstration purposes will be a simple schedule service, that can be queried to find out what meeting is next and todays meeting schedule.

Sorry for taking so long to put this out, but better late than never, eh?

All the code/wsdl/xml is available here
And the demo client (Source Code) and server (Source Code)

(more…)

PHP Soap Server, Part 1: Introduction to WSDL

In this multi-part blog im going to talk through how to set up a php soap (Simple Object Access Protocol) server that can be added as a web-reference through visual studio. Im mainly doing this because it took me along time to figure out the finer details of wsdl and soap, and i’d like to try and save other people the same hassle.

The example soap service that i will build for demonstration purposes will be a simple schedule service, that can be queried to find out what meeting is next and todays meeting schedule.

All the code/wsdl/xml is available here
And the demo client and server

PHP Soap Server, Part 2: PHP Server and Client (more…)

Using a Linux Box to share Internet Access

So recently i had to setup my linux server to be able to dialup to the internet and act as a internet sharing box for the other pc’s on the network. This is how i did it. (more…)