Installing and configuring LAMP on Ubuntu - Part 1

  • May 29, 2007
  • Avatar for peter
    Peter
    Upfold

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

Home » Articles »