Tuesday, September 21, 2010

Setting up a LAMP VPS - Part 1

A popular activity is installing LAMP software on an (unmanaged) VPS. LAMP stands for Linux, Apache, MySql and PHP. With a LAMP server you have a professional working environment used by thousands of businesses around the world. With a VPS LAMP you have an extremely powerful system for only a few dollars a month.

In part 1 we will setup the L and the A and end with a fully functional webserver allowing static content. For this tutorial, I assume your VPS allows you to install/restore a Linux distro and provides you with a SSH login after installing. Most VPSes have this functionality and most offer it for free.

L - Linux
Skip this step if you already have a VPS with Linux on it!

You need to install or restore an image from your control panel. After installation of the image you will receive a (root) password and you are ready to login. When installing a new operating system be advised to make a good backup because everything will be wiped clean of your server!

In this tutorial we will be installing Debian Lenny as the operating system. This OS has the advantage that is stable, secure and I have never encountered an update that breaks the system. The disadvantage is that it is always one step behind the most current stable software packages.
This is not necessarily a bad thing, a good example is the PHP package. PHP is currently at version 5.3, but Debian ships with 5.2. The PHP developers released 5.3.3 which can break earlier 5.3.x code using namespaces. With Debian you are still using PHP 5.2 so you are in no way impacted by this problem.
For this tutorial, Debian is the easiest choice. You can also choose another distro but then you have to change the commands for installing the software.

Installation steps
  1. Access your VPS control panel and restore an OS image to your VPS
  2. You will be given a (root) password to login to your freshly installed server.
  3. If you are connecting from Windows, download Putty and connect to your VPS via SSH. http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html

A - Apache
Apache serves the webpages to your visitors and it is the mostly used webserver in the world. To install Apache we login to the VPS and enter a single command as root, it's as simple as that.
apt-get install apache2
Test the installation by navigating to the domainname or IP address of your VPS. The apache webserver is automatically started after installation and also after a reboot (on Debian Lenny at least). If you don't see a test page check if your server is running a firewall that blocks access. Run this command on your VPS (install links first using apt-get install links):
links http://localhost
If this command works on the VPS but your website does not work remotely you probably have a firewall blocking access from outside. Search with Google for iptables on tips how to change this. It is not advised to disable your firewall completely if there is one running.

Installation is as simple as that. Once complete, you are greeted with a welcome screen, which is simply: It works!

Configuration is not necessary but it is good practice to have the web directory owned by the www-data group and make all web files writable by the www-data group. This means the webserver (and PHP) can also change the files on your VPS, this can be both and advantage and disadvantage!
chgrp www-data /var/www/ -R
chmod g+w /var/www/ -R
If you want to give a user named wilco access to change the webfiles enter this command as root:

gpasswd -a wilco www-data
The system will respond with something like: Adding user wilco to group www-data. Now login as wilco and edit /var/www/index.html!

No comments:

Post a Comment