Configure Apache MySQL PHP (LAMP) on Ubuntu 12.04

Posted on Updated on

There are many ways to do this but I’ll share the best and the  a easiest way to configure Apache MySQL and PHP (LAMP) on your Ubuntu. this is for Ubuntu 11.04

1. Go to applications->accessories->terminal

2. Enter Following commands accordingly,

sudo apt-get install tasksel

sudo tasksel install lamp-server

3. Give the MySQL root password, that’s all

4.  We want the default site to be /home/YourUserName/sites/. To do this, we must create a new site and then enable it in Apache2.

To create a new site:

Create a new folder called sites in /home/YourUserName

Copy the default website as a starting point.

sudo cp /etc/apache2/sites-available/default /etc/apache2/sites-available/mysite

5. gksudo gedit /etc/apache2/sites-available/mysite

6. Change the DocumentRoot and Directory to point to the new location. For example replace /var/www/ it with /home/YourUserName/sites/.

Now changes should be as follows,

DocumentRoot /home/YourUserName/sites

<Directory />
Options FollowSymLinks
AllowOverride None
<Directory /home/YourUserName/sites/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all

7. Change the Directory directive, replace to

sudo a2dissite default && sudo a2ensite mysite

8. Finally, we restart Apache2:

sudo /etc/init.d/apache2 restart

9. Click here http://localhost/

10. So It Works!


9 thoughts on “Configure Apache MySQL PHP (LAMP) on Ubuntu 12.04

    Heath said:
    May 19, 2010 at 10:08 pm

    This is a great guide! Quick and easy.

    I have a couple questions:
    Why do you create the “mysite” file instead of editing the default?
    Is “mysite” equivalent to http://localhost/mysite?

    If this is true then do I just copy the default site to “mysite2” to create http://localhost/mysite2?

      amilaudana responded:
      May 20, 2010 at 9:07 am

      Thanks Heath,

      1. its a copy of default, see we have get changed our sites directory to more manageable area.

      2. no. to understand it download
      Extract it in home/administrator/sites directory if you have created it
      rename it as “pma”
      now click here http://localhost/pma/
      You can create sites like that.

    lenja87 said:
    August 1, 2010 at 7:27 pm

    I would like to exchange links with your site
    Is this possible?

      amilaudana responded:
      August 3, 2010 at 10:11 pm

      You can link these posts but will see trackbacks are there.

    Tom Hodges said:
    April 9, 2011 at 5:13 pm


    You Sir, are a legend! Easiest setup I’ve ever done.
    Thanks very much for the info.

    Regards, Tom.

    Dror said:
    April 16, 2011 at 2:04 am

    Thanks Amila for a very nice post.
    It will also work if you change the document root directly in the ‘default’ file and then skip the directory change part.

    Janos Fejos said:
    October 14, 2011 at 11:25 pm

    Hi I did everything you wrote down here. It gives me this error: “Forbidden

    You don’t have permission to access /test.php on this server.
    Apache/2.2.17 (Ubuntu) Server at localhost Port 80”

    What could be the problem any idea?

      amilaudana responded:
      October 25, 2011 at 11:23 am

      check again permissions to the directory.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s