So I don’t know about you, but when I first approached setting up a web-server, I was a little overwhelmed by the amount of information out there. Now having had experience in setting up and running different types of server, from apache web-servers to subversion servers, Ruby-On-Rails servers to mail servers, I thought I’d share some of the knowledge I have gained. I’ll admin I’m not an expert on all these areas but in the coming series of blog posts I hope to shed some light on how to get your self on your feet when it comes to managing your own servers.
NOTE:
It has come to my attention that I overlooked some packages to install when creating a LAMP server. I have updated this blog accordingly
Now most of my experience has been with configuring and running Ubuntu servers, from 8.04LTS through to 10.04LTS. I have two servers running 9.10LTS and this server running 10.04LTS, and hope to be running all 10.04LTS servers soon. Of course you can choose any flavour of Linux you like, but Ubuntu is one of the most supported, document versions out there. Coincidently, all my servers are hosted on VPS.net which is one of the first providers to offer cloud servers based on nodes. For more info check out their website www.vps.net.
What does LAMP stand for?
As yet I have strayed away from explaining what a LAMP configuration is, well no more. LAMP is an acronym for Linux, Apache, MySQL and PHP. I don’t necessarily expect you to understand what each of these technologies are, just know that they are the very basic building blocks you need to run a web-server. Some of the more experienced out there will say “why is he talking about trying to create a LAMP server? You can get pre-configured Linux servers with them on”. Well the simple answer is that I like to have control over how I setup up my configurations and I’ve yet to find a version off-the-shelf that I like.
Anyway, I digress. Here is a quick overview of each of the parts of a LAMP configuration:
- Linux – The operating system upon which all other parts of an open source web-server run. Without an operating system, you might as well give up now
- Apache – This is the actual web-server part of the system. Apache deals with serving the pages out to clients who request them.
- MySQL – Most websites these days are backed up by a database of some sorts. MySQL is easy to install, use and best of all free.
- PHP – A “widely-used general-purpose scripting language that is especially suited for Web development and can be embedded into HTML”.
Now after that whistle stop tour of LAMP, lets get down to it and make a working server using Ubuntu 10.04LTS.
Configuring a LAMP system
I’m going to forgo explaining the “L” part of LAMP. Most server providers will supply a copy of Linux pre-install. If I get enough demand for it I’ll explain how to install it in a later blog. If you are running an older version of Ubuntu the basics still apply and in the future I aim to write a blog on updating a previous version of Ubuntu.
Preparing your Ubuntu Installation
Once you have successfully installed Ubuntu you need to do some basic things to the install to ensure it is secure and up-to-date. The first thing to do is set up the sources.list of aptitude, I have posted about this before here. After you have followed those steps you are ready to get going with preparing the rest of the install
NOTE:
If you are running a different version of Ubuntu to the versions listed change the “lucid” or “karmic” parts to the codename for your version of Ubuntu.
Installing the AMP part of the LAMP System
So we’ve made sure that you now have the latest updates for your system. Now to get down with the apache install
sudo apt-get install apache2
You now have apache running on your system. However, you may also want to run secure websites. Fortunately this is easy to set up, first we need to enable the ssl module, then enable the default ssl site and finally restart apache to commit the changes
sudo a2enmod ssl sudo a2ensite default-ssl sudo /etc/init.d/apache2 restart
You now have a Apache set up on your server. It’s a simple as that. While this may sound good you can only serve static HTML pages. Lets add some more functionality to your system with the PHP install.
sudo apt-get install php5 libapache2-mod-php5 php5-mysql sudo apt-get install php5-cli sudo apt-get install php5-cgi
The first line installs all the vital parts of PHP, while the second line allows you to execute PHP script from the terminal and the third line allows for PHP script to be executed without apache. Finally, we need to restart apache, which you need to do this every time you change the configuration of Apache.
sudo /etc/init.d/apache2 restart
Now to the penultimate part of the install, MySQL. Now this is really simple follow the onscreen instruction after executing the following line. It will ask you to create a root password for the database. This is important as the root user has master access to every database, so make it strong. I have also included the package to allow you to enter SQL directly from a SSH client.
sudo apt-get install mysql-server mysql-client
Finally, we need to add the packages to help communication between MySQL and PHP and Apache. This is done below by first installing the packages, enabaling the MySQL module in Apache and restarting Apache.
sudo apt-get install libapache2-mod-auth-mysql php5-mysql sudo a2enmod auth_mysql sudo /etc/init.d/apache2 restart
That’s it you now have a fully functioning LAMP install on your system. This is only a fraction of the story. In future blogs I intend to expand on how to administer, secure and ultimately utilise this setup to allow you to run an effective web server