Quick LAMP installs using Ubuntu Server 6.06LTS

In this tutorial, I will walk you through the process of installing ubuntu server and making it easy to use for development. For this tutorial, you will need: approx 450Meg of bandwidth for the cd image, 20Meg of bandwidth for the additional packages, a spare pc with the ability to boot from cd, at least 96Meg of RAM, 1Gig Harddrive and a 300Mhz processor and about 30 minutes of time (excluding the time to download the cd image.
There are many Linux distros available and most will support php development out of the box. For a long time, I have been a Fedora user, since it allowed me automate my installations over my network with pxe booting and kickstart. Only recently did I become aware that debian had an equivilent technique which caused me to take a look at debian and debian-based distros. Ubuntu being one of them.

Ubuntu is a debian based distro that prides itself on being optimised for the user, in fact their normal distro is probably one of the friendliest distros to anyone new to Linux. What isn’t as well known, is the fact that they have a server version, which can allow you to setup a LAMP enabled server within 20 minutes.

Downloading the iso

First step is to download a copy of the iso and burn it onto a blank cd. The isos for Ubuntu can be found from one of the mirrors. Choose the one closest to you.

Once the cd image is down, you need to burn it to a cd. I personally use DVD Decrypter to burn isos, since its the best tool for doing so for me, however most cd burning tools such as nero will work as well.

Booting the CD

Now we need to make sure that the system we will be installing onto
is setup to boot from cd. This is normally accomplished by changing the boot order in the bios. I’m not gonna discribe the process here since there are at least 10 different BIOSs and the process is different on all of them. So, please consult your motherboard manual for details.

Once we know that the cd will be looked at first for booting we can start. Place the CD into the drive of the server machine and reboot. A menu will appear after a few seconds similar to the one shown here. Select the option to “Install a LAMP Server” and press enter.

You will then be prompted to setup your language, dialect (if there is one) and keyboard layout.

After a moment or two, you will be prompted for the hostname of the server. If this is going to be the only server you have then the default will be fine.

Now we will be prompted for where we want to install Ubuntu. I’m going to assume that you will be using the whole disk for this tutorial.

Please note, that after this stage data will be written to the harddrive and the chance of retrieving any over written data is low. Please be sure that there is nothing on the harddrive you wish to keep before proceding.

Select “Erase entire disk: -drive description-”. where -drive description- is the detected hardrive.

You will then be prompted as to whether you want to continue. Select yes and press enter.

We are now prompted with a screen to select whether the computer’s internal clock is set to localtime or UTC. If this is going to be a Linux only system then either option is fine, however if you will be dual booting with Windows, then select localtime.

The install takes about 10 minutes. Go and make a coffee, grab a sandwich etc.

Most of the install is now complete. We just need to answer a couple more questions. The first one is the name of the main user of the system,in my case I’m gonna use darkflib which is my nickname on irc, followed by the username they will be known by which will be filled in with an auto generated name based on the name you just entered previously (darkflib again for me). Feel free to change it, lowercase only with no spaces. Next two screen are the password for the user and confirming the password

We are almost done, we just need to Reboot and configure the system for our use.

First Boot

Once the system has started up, which might take a few minutes the first time through, you will see something similar to this prompt to login. Enter the username you selected earlier. You will now be prompted for your password, this will not display while typing so make sure you type it in carefully.

Becoming root

You should now be logged in to your shell. Now we need to fix a couple of things that were missed from the basic install. We will need to type quite a few commands as root, so it might be better to drop to a root shell, we could use the sudo command to run all the commands, but you will be prompted for your password each time. To drop to a root shell do the following

sudo -s

You will need to enter your password again. (secure isn’t it) You will notice that as root your prompt has changed, this is the easiest way to tell if you are running as root.

Installing more packages

Lets install a couple of the packages that were missed off the standard install. Type the following.

apt-get install openssh-server php5-gd php-pear

This will install an ssh server to allow us to login remotely and use scp to upload files if we wish, and a couple of php extensions that are nice to have on the system.

Allowing access to the website files

As standard, the default website’s document root ( /var/www/ ) is owned by the root user. We don’t want to have to be logged in as root to be able to develop sites so lets change it to our normal user.

chown -R darkflib:darkflib /var/www/

Where ‘darkflib’ is the username you chose earlier. We should now be able to edit files in the docroot as this user.

Securing mysql

As standard, there is no password set for the root user in mysql. If we are going to install phpmyadmin, this will open up a big security hole with all your databases able to be edited or dropped by anyone smart enough to type root with no password. So lets fix that.

mysql -u root

This will drop us into the mysql commandline interface. Now is we type the following we will set a password for root.

\u mysql
UPDATE user SET password=password('mysecurepassword') WHERE user='root';
FLUSH PRIVILEGES;
\q

Enabling the universe

Both phpMyAdmin and php5-mcrypt which phpMyAdmin suggests you install are in the universe repository. This is disabled by default. To enable it we need to enable the two lines in /etc/apt/sources.list .


## Uncomment the following two lines to add software from the 'universe'
## repository.
## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu
## team, and may not be under a free licence. Please satisfy yourself as to
## your rights to use the software. Also, please note that software in

## universe WILL NOT receive any review or updates from the Ubuntu security
## team.
# deb http://gb.archive.ubuntu.com/ubuntu/ dapper universe
# deb-src http://gb.archive.ubuntu.com/ubuntu/ dapper universe
We need to remove the two hash symbols at the beginning of the line. To do this we will be using an editor called nano. It is not the most user friendly editor in the world, but since we only need to edit two lines it should be find for us. So lets backup the file and load the file for editing in nano.


cp /etc/apt/sources.list /etc/apt/sources.list.backup
nano /etc/apt/sources.list

Basic editing command are as follows.


Nano commands

ctrl+x - exit
ctrl+o - write out
ctrl+y - page up
ctrl+v - page down

Use the down cursor key to move down to the correct line and remove the preceding # symbol and space, this will enable the line. Now do the same to the next line. type ctrl+o to write the file and ctrl+x to quit. If you mess up the editing of the file you can always restore the backup version of the file.

Now we need to tell apt-get that it needs to update the lists of the availible files it has. We can do this with the following line which may take a moment or two to run.


apt-get update

Installing phpMyAdmin

We can now install phpmyadmin and the mcrypt extension for php that phpmyadmin suggests.


apt-get install phpmyadmin php5-mcrypt

Setting up FTP

It has been requested that I show people how to setup ftp in Ubuntu. I would recommend against it. The biggest issue is that ftp is unsecure. Anyone able to sniff the packets as they go past has your username and password if they want them. On Ubuntu this is potentially a very big deal, as the first user created has full sudo access. You are essentially giving them root access to your box.

The first task we need to do is create an unpriviledged user.


adduser newuser

You will be taken through a set of prompts to add the new user. We also need to make sure this new user has access to the web root, so we will undo what we did earlier and change the owner of the directory to our new user.


chown -R newuser:newuser /var/www/

We now need to install an ftp server. The usual choice on Ubuntu is Proftpd. We can do this like so.


apt-get install proftpd

We will be prompted whether we want to run Proftpd from inetd or standalone. Select standalone. Proftpd is now started and should be listening for connections.

You should now have a working LAMP server, with phpmyadmin, ftp, and ssh access. Have fun creating.

DarkFlib is a freelance programmer based in the UK and is currently looking for work. You can contact him through his website.

©2006 Technomonk Industries. Republished with permission.

Comments

Leave a Reply

You must be logged in to post a comment.