Installing and configuring LAMP on Ubuntu - Part 1

In this multi-part article, I'm going to be showing you how to install the popular LAMP stack - that's Linux, Apache, the MySQL database system and PHP (in this example, although you can have Perl, Python etc. instead) for running your own website or web development server.

The LAMP stack is a very popular setup and many websites run on it (including FOSSwire!). Best of all, all four of the tools in the stack are free and open source and really easy to get started with. For this tutorial, I'm going to be showing you how to install LAMP on Ubuntu 7.04 Feisty Fawn, but the process is very similar for other Linux distributions too. By the way, if you have a Windows machine that you want to do this on, check out this tutorial on our sister site GizBuzz instead for a nice easy WAMP setup.

Step One - get the software

All the stuff you need is pre-loaded into Ubuntu's software repositories, and it's really simple to install everything you need. If you're doing a new install, you may want to take a look at the server edition of Ubuntu as it allows for a pre-configured profile that you can pick at install time.

For this tutorial, I'm going to assume you've already got your Ubuntu desktop up and running, though.

To get stuff installed, you need to install the following packages:

  • apache2
  • php5-mysql
  • libapache2-mod-php5
  • mysql-server

The most universal and quickest way to do this is to pop open a terminal and type in the following command:

$ sudo apt-get install apache2 php5-mysql libapache2-mod-php5 mysql-server

Step Two - do some minimal configuration

Let that download and install. Once that's all finished, we need to do just a little bit of configuration before we can start using our new LAMP setup and that is to set a root password for the MySQL database server (without this step, you will have an insecure setup).

It's pretty simple to do:

$ mysqladmin -u root password yournewrootpassword

That will set your MySQL root password, which you can now use to log in to your MySQL server.

Step Three - start using it!

That's pretty much all the configuration you need to do, so you can now grab any web applications you want and install them. Don't use the root MySQL user for your databases though if you are working in an environment where you need things to be secure. Set up a user and database for each application you install (you can use something like PHPMyAdmin for this).

In the next part of this tutorial, I'll be looking at some awesome tweaks you can make to your LAMP setup and how to easily install some of the most popular web applications.

Tips and tricks

To start and stop the servers independently of rebooting (for example after changing configuration files, you can use these commands):

Apache and PHP

$ sudo /etc/init.d/apache2 restart

Replace 'restart' with either 'start' or 'stop', as needed.

MySQL

$ sudo /etc/init.d/mysql restart


Update:
Part 2 of the tutorial is now online, with tweaks, hacks and more configuration!

Avatar for peter Peter Upfold - http://peter.upfold.org.uk/

Peter Upfold is a technology enthusiast from the UK. Peter’s interest in Linux stems back to 2003, when curiosity got the better of him and he began using SUSE 9.0. Now he runs Linux Mint 9 on the desktop, runs a CentOS-based web server from home for his personal website and dabbles in all sorts of technology things across the Windows, Mac and open source worlds.

Home » Articles »

Discussion: Installing and configuring LAMP on Ubuntu - Part 1

  1. # Posted on 01 June 2007 at 10:40 AM

    [...] Posts Installing and configuring LAMP on Ubuntu - Part 2Welcome back! In Part 1 of this tutorial, I looked at installing the tools you need to get your own web server up and [...]



  2. # Posted on 08 June 2007 at 11:43 AM

    [...] Posts Installing and configuring LAMP on Ubuntu - Part 2Welcome back! In Part 1 of this tutorial, I looked at installing the tools you need to get your own web server up and [...]



  3. Shahryar Ghazi (guest)

    # Posted on 27 June 2007 at 12:59 PM

    good work!



  4. # Posted on 03 July 2007 at 03:03 PM

    [...] up and mess around with your...Installing and configuring LAMP on Ubuntu - Part 2Welcome back! In Part 1 of this tutorial, I looked at installing the tools you need to get your own web server up and [...]



  5. # Posted on 06 August 2007 at 07:50 PM

    [...] WebminShare some more and Cleaning upOpen another Port and sFTP/SCPDe-bling-anizeWrapping Up2) Installing and configuring LAMP on Ubuntu - Part 1In this multi-part article, I’m going to be showing you how to install the popular LAMP stack [...]



  6. Sam (guest)

    # Posted on 16 August 2007 at 08:34 PM

    Good guide, one can also add the Unbuntu desktop GUI afterwards by following this guide.

    http://www.zaphu.com/v1/2007/08/07/ubuntu-lamp-server-setup-guide-with-desktop-gui/

    Hope that is useful.

    -Sam



  7. # Posted on 30 September 2007 at 08:26 PM

    [...] week, and as I have done with every other reinstall; I have followed the excellent tutorial (parts 1 and 2) written by Peter Upfold. I have always had great success in getting it to run, and his is [...]



  8. Josh (guest)

    # Posted on 30 September 2007 at 08:49 PM

    Hmm.. I just used this tutorial (reinstalled my OS, so i needed to reinstall my LAMP) .. and for some reason nothing is working right. Apache is running, but for some reason php5 wasnt installed, my mysql is refusing to accept my root password, and when i visit http://localhost it asks me if i want to download a no-named PHTML file. Any help or suggestions would be nice.



  9. # Posted on 06 October 2007 at 06:52 AM

    [...] That’s going to go in and install every package needed to run a LAMP server. There is also an excellent tutorial on how to setup the LAMP and configure it on FOSSwire.com (1)(2). [...]



  10. # Posted on 18 October 2007 at 10:29 PM

    [...] past week, and as I have done with every other reinstall; I followed the excellent tutorial (parts 1 and 2) written by Peter Upfold. I have always had great success in getting it to run, and his is [...]



  11. # Posted on 02 May 2008 at 01:23 PM

    [...] The references used to achieve (and write) this were LAMP Installation On Ubuntu, Installing LAMP on Ubuntu 7.10 and Installing and configuring LAMP on Ubuntu. [...]



  12. # Posted on 03 December 2008 at 02:04 AM

    [...] search was stumbling onto this tutorial. Which led me to search for more tutorials, where I found this, this, this, this and this. And of course I’ve done nothing more than skim these before my [...]



  13. # Posted on 08 January 2009 at 03:05 PM

    [...] PHPmyadmin by following one of the many tutorials available. The best one according to me, is this one. It describes the process to install LAMP and configure it by providing the right commands. But it [...]



  14. olly (guest)

    # Posted on 07 February 2009 at 11:29 AM

    i followed that install above but it didnt tell you how to setup php - when i visit index.php the browser trys to download the php file. The tut should explain how to configure php too any ideas



Home » Articles » Installing and configuring LAMP on Ubuntu - Part 1