Apache on Ubuntu

how to install LAMP – Apache, MySQL & PHP on Ubuntu 11.10

Ubuntu has become popular not only among desktop users but also among the web developers who uses Linux distribution to deploy their web application (on a VPS or dedicated host), although they preferred to use LTS (Long Term Support – typically of five years for Server Edition) version rather than a regular stable release because of obvious advantages – increased stability (Although, from the next release i.e Ubuntu 12.04 LTS, Desktop version will also get 5 years of support).

Despite of that fact, a lot of users/developers also use Apache server on their localhost for testing/development (e.g wordpress developers use it) and this post is written for those who want to get started with Apache, PHP, MySQL, phpMyAdmin etc with Ubuntu 11.10. Apache is the most popular web server on this planet (total share is above 65%). It is an open source and cross-platform web server. Apache supports a lot of server side language and the features is extensible using modules. PHP dominates the web scripting world and MySQL is the most popular open source database. Most of the websites (including the blog – you’re reading right now) are based on the great combination of Linux, Apache, MySQL and PHP (Commonly called as LAMP).

Setup LAMP in Ubuntu 11.10

step 1. Installing Apache

Apache on UbuntuOpen terminal (press Ctrl+Alt+t) and execute the command –

sudo apt-get install apache2

The above command will install some default modules, packages and libraries but you later install the ones you need. When installation is completed, type the address http://localhost in the browser address bar and you will get a default apache page like this –

 

apache-default-page

MySQLstep 2. Installing MySQL

Execute the command –

sudo apt-get install mysql-server

and enter the root password during installation procedure. I’ve already covered a post in detail about how to install MySQL on Ubuntu 11.10.

step 3. Installing PHP

Execute the command –

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

Then restart the Apache server to load php modules –

sudo /etc/init.d/apache2 restart

To test whether the PHP 5 has been successfully installed or not, create a file phpinfo.php and copy the following content (to the file) –

<?php
print_r (phpinfo());
?>

and put the file in root web directory (/var/www). Then open the address http://localhost/phpinfo.php, then it should display the php configuration details like this –

testing php on Ubuntu

That’s All.. Linux (Ubuntu is itself a Linux based OS), Apache, MySQL and PHP i.e all the components of LAMP has been installed successfully.

To manage MySQL database from a GUI, You may like to install phpMyAdmin – The MySQL web administration tool, a great application for managing – creating and maintaining MySQL database.

How to install phpMyAdmin on Ubuntu 11.10 ?

just execute the command –

sudo apt-get install phpmyadmin

When the installation is complete, move on to http://localhost/phpmyadmin and login (using the MySQL login username(default is ‘root’) and the password (you entered during installation)) to start using it.

Want to learn web server administration (with LAMP) on Ubuntu Server ?

Having apache, MySQL, PHP installed locally on your system is good for learning about the server administration and other cool/great stuffs related to Linux but VPS is very cheap these days so you may want to try Ubuntu (with Apache or other web server) on a VPS for much better (and real) experience – I’ve been using Linode VPS @ $19.95/month (512 MB RAM, 20 GB space and 200GB bandwidth) for a while, and I am loving it.

  • Giulio Giraldi

    Thanks for the tutorial, when I run 

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

    the version of PHP I get installed is 5.3.2-1ubuntu4.10
    I could really make use of a newer version (5.3.2 has a bug that affects Mediawiki), how did you get that installed? 

    thanks, 
    Giulio

  • Martin Redola

    Only one command is necessary: sudo apt-get install lamp-server^

  • Danny Crossley

    Great, nice and easy.

  • Hyubs Ursua

    If your phpmyadmin doesn’t work, open apache.conf:
    sudo gedit /etc/apache2/httpd.conf

    Type the following:
    Include /etc/phpmyadmin/apache.conf

    Note: My httpd.conf was blank from fresh install so don’t be alarmed.

    Update: Forgot to tell that you need to restart your Apache after:
    sudo /etc/init.d/apache2 restart
    or
    sudo service apache2 restart

    • http://isword.tk iSWORD

      This should be added to the original post, because it’s required every time. apache isn’t configured to be used with phpmyadmin by default.

    • Anonymous

      Thank you! Most other blogs omit this step.

    • RedHatcc

      I agree with tenleft… your solution is correct and works perfectly. Thank you hub for supporting and helping others 😉 +Up your post.

  • andrew

    Thanks, great post.

  • vijay pietersen

    this not at all working for me plz help
    i have installed lamp and phpmyadmin in 11.10 but phpmyadmin is not working it show the following
    Not Found

    The requested URL /phpmyadmin/ was not found on this server.

  • vijay pietersen

    can any where i can get free e book

  • http://twitter.com/arjunbajaj Arjun Bajaj

    thanks… finally something which worked. other blogs ommited `php5-mysql` installation instruction, that caused php not working with mysql… thanks a lot… this should be the instruction given on ubuntu’s website… but even they dont know what to install on their own OS….

    • Fabiob1705

      Happens when you use a search engine instead of the official documentation.

      Quote from the official documentation:
      “To use MySQL with PHP5 you should install php5-mysql package. To install php5-mysql you can enter the following command in the terminal prompt: sudo apt-get install php5-mysql”

      Link:  https://help.ubuntu.com/11.10/serverguide/C/php5.html

  • Santhanakumar Niet

    nice post

  • Vkadal

    I could not copy the phpinfo.php into the varwww directory.

  • Vkadal

    After installing everything I  tried to open phpmyadmin. It was asking for the username and pass word. I know the pass word which I assigned during installation. But what is the username? I tried admin, admn,.. It is not working . any help?

    • gbert

      root

  • Itpro007ca

    I followed all the instructions and everything worked,until the install of phpmyadmin,after which I got a “404”,but after adding the “include….” line to and saving the Apache2.conf. file and trying again it worked!I then logged in as “root” + the mysql password I’d already set up!Now,I’ve got some heavy learning to do!

  • Shauvik

    I have found the easiest way to install everything is to do a 

    sudo apt-get install mysql-server phpmyadmin

    This installs everything (phpmyadmin depends on apache & php)..

  • Edvaldo Szymonek

    Thank you so much!

  • cHeJo Felipe

    if you can write or display de phpinfo.php in the directory. before, you can add permision at the /var/www
     directory.

    like: sudo chmod 777 /var/www

  • Qobosanele

    cool
     

  • Nidhi Pallavi

    Hi,
    I am new to both MySQL and PHP as well as linux.I have installed LAMP as the steps provided by you but PHP is  not at all working.  after restarting apache2 and writing of code for phpinfo, i didn’t get the phpinfo page.
    showing the following,
    Not Found

    The requested URL /phpinfo.php was not found on this server.

    And any other files like .html  or .txt  in web directory (/var/www) are not avalaible on this server. This servser shows no content at all. Please provide me with solution.

    Thank you for help in advance!