How to: Setup LAMP on Ubuntu

Posted by Mani On January - 31 - 2010

lamp How to: Setup LAMP on UbuntuWeb Server-

To setup a web server and to run a website on a system(localhost) you have setup LAMP or WAMP first. If you are a Linux user, you have to setup LAMP for this purpose and if you use Windows then you setup WAMP. This is a simple guide for running a website on localhost by setting LAMP on Linux machine. I used Ubuntu 8.1 (desktop edition) for this purpose.


LAMP is the acronym for Linux Apache MySql Php,Python,Perl.

WAMP is the acronym for Windows Apache MySql Php,Python,Perl.

We will install all these components and will configure a web server on localhost.

First, we will install and configure Apache.

  • Open the terminal Application -> Accessories -> Terminal and type the command-

sudo apt-get install apache2

Now apache is downloaded and installed automatically.

A www directory will be located in your /var directory. This is your server’s base address where you will place files for your website. /var/www basically stands for localhost. You can test your localhost by typing http://localhost/

Next, we will install PHP.

  • Type the command in the terminal-

sudo apt-get install php5 libapache2-mod-php5

Here, we are downloading and installing PHP5. You can install other versions of php too.

After installation is finished , restart Apache with the command-

sudo /etc/init.d/apache2 restart

To test if everything is fine and working , create a test.php file and add any php code for examle-

<?php
echo 'Welcome to TechTickLe';
?>

Now you can open this file by the url http://localhost/test.php in the web browser . It should prompt Welcome to TechTickLe. If not working, then something is wrong with your local server.

So, your server is working , now you need to store databases for your server back end. Therefore we will install MySql now.

  • Again in terminal execute the command-

sudo apt-get install mysql-server

This way, MySql will be installed for your localhost.

If you are running a server (not for localhost) then you have to bind your ip address to Mysql. You can do it by editing the bind address in the file /etc/mysql/my.cnf . And change bind address’s value (127.0.0.1) by your IP address.

Set your root password for MySql-

  • First type mysql in terminal , it will drop mysql prompt.
  • Then type command .

mysql> SET PASSWORD FOR ‘root’@'localhost’ = PASSWORD(‘xxxxxx’);

where xxxxxx is your desired password.

  • Now we can install phpMyAdmin as graphical interface for MySql.

sudo apt-get install libapache2-mod-auth-mysql php5-mysql phpmyadmin

You can open phpMyAdmin by typing http://localhost/phpmyadmin

It will ask for username and password . You can access it as root and give its mysql’s root password.

Note- The password that you have set for mysql’s root not your system’s root password.

  • Last step is to restart your apache.

sudo /etc/init.d/apache2 restart


This should give a better understanding how a Lamp server’s components are installed and configured.

Comments are welcome!

Thanks.

Suggested reading:
Install LAMP on Ubuntu Maverick and Lucid with One Command
This is probably the simplest way to setup LAMP Server on Ubuntu. It's a single command based installation which allows you to install Apache web server, mysql, php on a ...
READ MORE
Convert Default Online Dictionary to Offline in Ubuntu 10.04 or Later!
Ubuntu comes with the default Dictionary, that can be accessed from the pathways “Applications → Office → Dictionary”. The only problem associated with it is that, it's an Online Dictionary, ...
READ MORE
Install WordPress Locally on Ubuntu Linux with LAMP
Undoubtedly, Wordpress is the best softwares available for blogging. The ease with which you can manage it, is uncomparable to any other blogging platforms. These days, for self-hosted wordpress users, ...
READ MORE
How To Install Skype From Repositories in Ubuntu Linux
Skype is one of the popular, Voice Over Internet Protocol (VoIP) application that lets you make calls from one skype user to another skype user over the internet, free of ...
READ MORE
Guide to Configure Netbeans For Android Application Development on Ubuntu
Most of the programmers would agree that Netbeans is the magical stick that gives our coding pattern an all new zing. When it comes to Android Application, configuring Eclipse IDE ...
READ MORE
How to Check all your Activity Logs in Linux
It is always good to keep track of activities and logs whenever something unusual happens with your system. Sometimes you want to come close to the reasons behind a particular ...
READ MORE
LibreOffice 3.3 Stable Released; How to Install from PPA
The Document Foundation has launched the first stable release of LibreOffice, the free and Open Source office suite, forked from OpenOffice. The first release, LibreOffice 3.3 has been developed by ...
READ MORE
Ubuntu 11.04 Natty Narwhal Alpha 1 Available for Testing
Ubuntu 11.04 Natty Narwhal, first Alpha has been released. Codenamed Natty Narwhal (a medium-sized toothed whale that lives year-round in the Arctic), the development cycle has already been rescheduled from 5 alpha ...
READ MORE
Install LAMP on Ubuntu Maverick and Lucid with
Convert Default Online Dictionary to Offline in Ubuntu
Install WordPress Locally on Ubuntu Linux with LAMP
How To Install Skype From Repositories in Ubuntu
Guide to Configure Netbeans For Android Application Development
How to Check all your Activity Logs in
LibreOffice 3.3 Stable Released; How to Install from
Ubuntu 11.04 Natty Narwhal Alpha 1 Available for

Article by

Mani is a coder passionate about working in open-source projects. You can follow him on Twitter or Join him on Facebook

Mani has written 30 articles for us at TechTickle.

12 Responses to “How to: Setup LAMP on Ubuntu”

  1. [...] This post was mentioned on Twitter by Sahil Malhan, Sahil Malhan and slimb mani, TechTickle. TechTickle said: TeckTickLe- How to: Setup #LAMP on Ubuntu http://bit.ly/bdy4lX (A tutorial for Linux Lovers) #linux #ubuntu [...]

  2. admin says:

    Great tut just to say

    mysql no need for the password command as the install asks you for this also slect apache 2 on mysql set up

  3. jimothy says:

    There are so many folders – where do I save the test.php file?

  4. jimothy says:

    there are so many folders, where do I save the test.php file?

  5. Alex says:

    In the localhost directory -> /var/www

    • jolsen says:

      When I try to create the test.php file at /var/www I receive the following error: Error moving file: Permission denied.

      Looking at permissions, it looks like only root has access. Either I don’t remember ever setting the root password, or I forgot the password. Is there anything I can do so I can put this file in the /var/www folder?

  6. sbn says:

    Hi, when I get to the point where you say Set your root password for MySql-

    * First type mysql in terminal , it will drop mysql prompt.

    Then I get this output in the terminal: mysql
    ERROR 1045 (28000): Access denied for user ‘sbn’@'localhost’ (using password: NO)

    What to do?

    Thanks

  7. I can’t seem to get the localhost/phpmyadmin to work… It’s basically saying it’s not found it… I’m not sure if there should be any sign of it in the directory when I look in the file manager, but there isn’t.

    Any ideas?

    • Mani says:

      Firstly make sure that phpmyadmin is installed. After that if it doesn’t work it means it would have not been linked in /var/www directory. To make this work just create a link from /usr/share/phpmyadmin to /var/www directory
      Use command as root -
      ln -s /usr/share/phpmyadmin /var/www

  8. Andrew Dowell says:

    I got as far a the last stage and also got no connection for
    http://localhost/phpmyadmin/
    so I did
    ln -s /usr/share/phpmyadmin /var/www
    and I do get a connection now but it says

    “phpMyAdmin -

    Cannot load mysqli extension. Please check your PHP configuration. – Documentation”

Leave a Reply

About Me

Welcome to TechTickle! A blog that features Latest technology news, Linux tutorials, Updates related to Social Media, Website & Software reviews and Open Source. We are a group of ordinary individuals, with an extra ordinary quality of sharing our passion and, reaching out to the people in nook and corner. Read more About TechTickle!

Twitter

    Subscribe to E-mail Updates: