Easy LAMP Server Installation

84951

 

The LAMP server (Linux, Apache, MySQL, PHP (or Perl) is one of the most important servers you might ever set up. It will happily serve up dynamic, database-driven web sites without needing constant babysitting. Since the LAMP server’s underlying foundation is Linux it enjoys rock-solid reliability, security, and can be installed on all kinds of hardware (from that old white-box you have to a multi-CPU, RAID-enabled rack server).

But to most people, Linux is unfamiliar territory. To those, the idea of installing an entire server environment from command line is absurd and, most likely, impossible. It’s not. Actually, installing a LAMP server is, on the contrary, quite easy. And in this article I will show you two different ways to install a LAMP server. I will show you how to install a LAMP server one piece at a time and then I will show you how to install a LAMP server with a single command.

NOTE: This article won’t actually deal with the installation of Linux. I will assume you are already dealing with a working Linux install. And this article will be installing the LAMP server on a Ubuntu 9.10 machine. This machine can be either a standard installation or a Ubuntu Server installation. Either way, it’s all command line from here.

Because the OS is already installed, all we have to install is Apache, MySQL and PHP. So there are only three major steps to take care of in order to get your LAMP server up and running. Remember, you are going to be using the command line, so open up your favorite terminal window (or, if you’re using a GUI-less server install, log in). We’ll tackle the installation a bit out of order (from the acronym).

Apache

Apache is the web server piece of our puzzle. From within your terminal window issue the command:

sudo apt-get install apache2

If, by chance, you are using a distribution that does not use Sudo, you will need su to the root user and issue the above command without the sudo command.

Depending on your OS installation, the above command might need to pick up some dependencies. If so, okay those dependencies.  At the end of the installation, Apache should automatically start. If it doesn’t, issue the following command:

sudo /etc/init.d/apache2 start

You can now open up a browser and point it to the IP address (or domain) of the server to get the famous “It works!” page. You are ready to move on to PHP.

PHP

For the purposes of this article, we will assume the “P” stands for “PHP.”  To begin the process of installing PHP, issue the following command:

sudo apt-get install php5 libapache2-mod-php5

NOTE: Again, depending upon your OS installation, this might require some dependencies to be met. Allow apt-get to pick up those dependencies.

When the installation is complete, restart Apache with the command:

sudo /etc/init.d/apache2 restart

Now, let’s give PHP a little test to make sure it has installed. In your terminal window, create a new file called test.php.

Save that file and place it in /var/www/. Now, open up your browser to the address http://ADDRESS_OF_SERVER/test.php. Where ADDRESS_OF_SERVER is the actual address of your server. You should see “Test PHP Page” in the browser. You are now ready to move on to MySQL.

MySQL

MySQL is the database piece of the puzzle. This installation requires a few more steps than what you’ve just experienced. The first step is to install the server itself with the command:

sudo apt-get install mysql-server

Again, depending upon your OS installation, there might be some dependencies to be installed. After the installation is complete you need to log into the MySQL prompt and give the administrative user a password. Do this by following these steps:

  1. Log into MySQL with the command mysql -u root -p.
  2. As no password has been configured, you will only need to hit enter when prompted for the password.
  3. Enter the command SET PASSWORD FOR ‘root’@’localhost’ = PASSWORD (‘YOURPASSWORD’); Where YOURPASSWORD is the password you want to use for the administrative user.
  4. Now quit the MySQL prompt by issuing the command quit and hitting enter.
  5. Start the MySQL server with the command sudo /etc/init.d/mysql start.

That’s it. Your LAMP server is now up and running. But what about this one-command method? Simple. From your terminal window, issue the command:

sudo tasksel

This command will open a curses-based tool (see Figure 1) which allows you to select numerous software options for installation. One of those selections is a LAMP server. All you need to do is mark LAMP server for installation (scroll down with your arrow keys and then hit the space bar to select). Once you have selected LAMP server, hit the Tab key on the “button” and hit the Enter key.

taskselYou will have to answer a single question when you get to the MySQL portion of the install (what you want to use for the admin password). That’s it.

Your LAMP server is ready for you. Of course all you have is a bare-bones LAMP server. Since this article does not dive deep into the trenches of any of the packages, you will want to familiarize yourself with these tools before you really start playing around with them. But – even with what you have, you can now overlay a tool like Drupal, Joomla, or Xoops! on top of your LAMP server.

And remember, when placing any server in the eye of the public, make sure that server is as secure as possible. Don’t just assume that, because it’s Linux, it’s immune to attacks. If it’s on line, it’s vulnerable.