Linux.com

Home

Easy LAMP Server Installation

 

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.


 

Comments

Subscribe to Comments Feed
  • shams Said:

    hi, first off, thanks. i tried the single command one. but i am facing a problem as i selected the 'lamp' and hit the enter button it says like this pacific@pacific-laptop:~$ what to do? i am kid in linux world

  • Collin Said:

    It has entered the Linux command line. Nothing is wrong

  • Geoff Said:

    Switch first to your root on your terminal just type su and enter your root password then you can continue following your step

  • ilia Said:

    Very complete and useful Thank you so much.......

  • Luca Said:

    Could you please assist me? When I try to put in the sudo /etc/init.d/mysql start command, it tells me this "Rather than invoking init scripts through /etc/init.d, use the service(8) utility, e.g. service mysql start Since the script you are attempting to invoke has been converted to an Upstart job, you may also use the start(8) utility, e.g. start mysql luca-studio-laptop1@Studio-laptop:~$ " Could you please help me here?

  • Dave Said:

    try this: sudo service apache2 restart hope this works!

  • jobin Said:

    1. VPCEH26EN:~$ su Password: su: Authentication failure here the password i entered is the root user passwrd but it is showing like this.why it is showing like this 2.i had given the command sudo tar xvfz xampp-linux-1.5.3a.tar.gz -C /opt and when ever the root password is entered the msg showing on the terminal is like this tar (child): xampp-linux-1.5.3a.tar.gz: Cannot open: No such file or directory tar (child): Error is not recoverable: exiting now tar: Child returned status 2 tar: Error is not recoverable: exiting now can i get a solution for this...

  • Luke Said:

    Thankyou, very nice post which worked flawlessly on Linux Mint 14! The mySQL installation asks for the password during installation so the SET PASSWORD returned '0 lines changed' so mint users i think your okay to leave out this step. Luca: regarding your query, simply type 'start mysql' in the terminal to start the mysql server, that is basically all you need to take from your post above.

  • AbdelraoufAdjal Said:

    Ok, what about: $sudo apt-get install lamp-server^ don't forget the " ^ "

  • Samuel Said:

    You can use: sudo apt-get install lamp-server^

  • srinu Said:

    friends help me; Is it possible to install lamp server in windows. then how? with reason

  • Walter Goedecke Said:

    Hello. Does it matter if one has a non-server version of Linux? If not, what is the advantage of having the server version? Thanks

  • guest Said:

    my machine doesn't bootup after using sudo tasksel , it installed many of the exiisting linux packages. this is post is misinforming.. the author should have check it my himself..

  • funnyboy Said:

    Your funny, don't play with linux its not for you. This tutorial is excellent.

  • grammar nazi Said:

    You're funny.... Don't play with English; it's not for you.

  • JohnL Said:

    Nice one thanks very much for this excellent tut. All up and running in Linux Mint without a hitch :)

  • abdullah Said:

    how to switch between LAMP screen (main window) and command prompt?

  • blackman Said:

    hey guys iam gettin with hte password when i hit the entre it quite

Who we are ?

The Linux Foundation is a non-profit consortium dedicated to the growth of Linux.

More About the foundation...

Frequent Questions

Join / Linux Training / Board