Web Development

Adding multiple IPs to Ubuntu and Allowing Apache to use one of the IPs


# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).

# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
auto eth0
iface eth0 inet static

auto eth0:0
iface eth0:0 inet static


//Server config here

Linux, MySQL, PHP

Beginners Guide to LAMP server Setup

LAMP – Linux Apache MySQL PHP server which can often have parts of the removed for other languages such as Perl or Prostge SQL but most commonly known as Linux Apache MySQL and PHP.

Lamp is the first letter combination of the build up of a typical Linux based server. In this tutorial we will learn how to set-up one of these server and get it working properly.

Tutorial Warning

This tutorial does not follow through Apache or PHP security protocols and although it might be fine on a normal server that would host, say, a video site I would not recommend this guide for commercial set-ups which require absolute security.

As another note this is under Ubuntu 9.04 and most Ubuntu versions are the same interface-wise, however, the instructions may differ from different distros and even Operating Systems.

First things first you must install Apache, so terminal:

sudo apt-get install apache

After that follow this tutorial here (Okay, so I could have actually wrote the tutorial but I like this tutorial so I thought I would link this instead =]).

Okay, so you have just followed the tutorial I linked and came back here, good. You are now ready to begin everything else since setting up Apache is only a fraction of the process. We will immediately move onto PHP and MySQL installation.

Both of these can be download from the universe just:

sudo apt-get install mysql-server
sudo apt-get install php5

At some point throughout the PHP installation you will be asked to state which server PHP is being installed to, just say Apache 2.x (or 2.2 as it’s sometimes stated). There is also a stoppage within the MySQL set-up when the installer asks for a password, if you try enter a slightly secure yet memorable password then it should be okay.

Now just open phpmyadmin (localhost/phpmyadmin) and enter root as the user and your password you entered on the MySQL set-up. You should now see the database server and the databases upon it. If you don’t just drop a comment and I’ll get back to you.

Wooo, you have the actual server set-up, not that hard was it. Now we need to set-up the environment itself with extensions and such like, all of these are optional, however useful.


What is PEAR:DB? DB is a database abstract layer. Still a bit confused? Okay, basically imagine your PHP code with the SQL in it, underneath that is the SQL server right? Wrong, DB acts as a layer between those taking in standardised functions and spitting them out as database queries only difference is that DB can spit these queries out for almost every main stream server out there.

This means in layman’s terms that you would never have to rewrite SQL code so long as you live and not only that you get some pretty cool functions that make your life so much easier. I love easy, I never have time for hard.

To install DB simply type into terminal:

sudo apt-get install php-db

Once this is completed you have the extension. Now you need an example along with a little bit of a tutorial on how to use this extension.

I have decided to explain the rest of this section in a new post. It is a bit long to post here.

PHP mcrypt

PHP mcrypt controls encrytion within any PHP script. To install this extension simply type:

sudo apt-get install php5-mcrypt

Then for its usage:

	function linEncrypt($pass) {
		$iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB);
		$iv = mcrypt_create_iv($iv_size, MCRYPT_RAND); //Creating the vector
		$cryptedpass = mcrypt_encrypt (MCRYPT_RIJNDAEL_256, $this->mykey, $pass, MCRYPT_MODE_ECB, $iv);
		return $cryptedpass;

Most of the things here are just default in built commands, except for $mykey. This is a key that the encrypt-or uses to encrypt with (i.e. “S3M_LL4N”). Except for the key everything else is pretty much set default for my basic RIJNDAEL encryption.


This has already been written here


An essential user friendly function for any website which requires an upload page. This extension will effectively allow the developer to track the progress (all the details, even remaining seconds) of an upload.

For an accurate description on it’s usage and such like check out this page. In this section I will hopefully go over the basics of installing the upload progress function. There is an advanced tutorial for readers who are looking for something more intensive to do with this extension.

Okay, first we need to download and install the package. If you enter:

sudo pecl install uploadprogress

I found that for some reason sometimes you need sudo and sometimes you don’t (I am unsure as to the reason this is). You will find that when you first install there will be missing packages and the installer will fail. So to fix this problem we simply:

sudo apt-get install php5-dev

If you are running a server version you may also be missing make package but that one is simple, the phpize command is not instantly understandable (due to it actually being in package: php5-dev). After you have run the uploadprogress setup correctly without faults you will see the uploadprogress extension on your phpinfo(); page and this will signify you are ready to use the extension.


Ffmpeg is perhaps one of the greatest thumb nailing extensions for PHP in existence. it is not the only one but it’s the only one that has done exactly what I want it to have done without exploding.

Now to install Ffmpeg simply type:

sudo apt-get install ffmpeg

And to test do this:


The result should be:

FFmpeg version 0.5-svn17737+3:0.svn20090303-1ubuntu6, Copyright (c) 2000-2009 Fabrice Bellard, et al.
  configuration: --enable-gpl --enable-postproc --enable-swscale --enable-x11grab --extra-version=svn17737+3:0.svn20090303-1ubuntu6 --prefix=/usr --enable-avfilter --enable-avfilter-lavf --enable-libgsm --enable-libschroedinger --enable-libspeex --enable-libtheora --enable-libvorbis --enable-pthreads --disable-stripping --disable-vhook --enable-libdc1394 --disable-armv5te --disable-armv6 --disable-armv6t2 --disable-armvfp --disable-neon --disable-altivec --disable-vis --enable-shared --disable-static
  libavutil     49.15. 0 / 49.15. 0
  libavcodec    52.20. 0 / 52.20. 0
  libavformat   52.31. 0 / 52.31. 0
  libavdevice   52. 1. 0 / 52. 1. 0
  libavfilter    0. 4. 0 /  0. 4. 0
  libswscale     0. 7. 1 /  0. 7. 1
  libpostproc   51. 2. 0 / 51. 2. 0
  built on Apr 10 2009 23:18:41, gcc: 4.3.3
At least one output file must be specified

Ok so you have the extension now you need an example of its usage:

$comm = 'ffmpeg -itsoffset -00:01:15 -i "/home/sam/inetpub/htdocs/the_stage/'.$filePath.'" -vcodec png -vframes 1 -an -f rawvideo -s 800x600 "/home/sam/inetpub/htdocs/the_stage/upload/'.$randThing.'.png"';

$comm string forms a system command, a terminal command and system() executes that command. You can always use a different command which will allow you to return an object like an array:

									$command = sprintf('ffmpeg -i "/home/sam/inetpub/htdocs/the_stage/'.$filePath.'" 2>&1');

But let’s get back to the example. You should notice that in the example I am actually grabbing a image of the film (frame) at 1 min and 15 seconds and saving it to a png file. You always start every command with ffmpeg and then build on the commands from there. Now the actual example is quite easy and straight forward to explain. I set a parameter of time (00:01:15) and a video file (-i “blah/blah/$file.divx”), set certain codec and image size (800×600) and then state the path and name of the file (blah/blah/blah/$file.png).

Ffmpeg is in fact very simple once you understand the basic format of commands. Most of the complicated looking parameters are just instruction saying what image format I want and stating default codec to open the video with. Anyway now you have had a small taste of Ffmpeg.