Install Apache2, MySQL5, PHP5 and PHPMyAdmin on Ubuntu

This is a collection of guide how to install Apache Httpd Web Server complete with latest PHP (as Apache mod), MySQL for Ubuntu. As a bonus, I even through in an additional guide to install PHPMyAdmin. Please do note that most of this guide can be found elsewhere which is listed at the bottom of the guide.

Getting Started

I’m sure everyone here is familiar on how to use Terminal which is available from:

Applications > Accessories > Terminal

Install Apache Httpd Web Server

To install Apache, type the following command into your Terminal:

> sudo apt-get install apache2

Testing Apache

Paste the following command into your Terminal

> sudo /etc/init.d/apache2 start

Then open http://localhost/ or http://127.0.0.1 from your web browser. At first run, you would probably see a directory listing or a HTML page with a text saying “It’s Work“.
apache-work
To browse the file please navigate to the following folder

> cd /var/www/

Install PHP

Similar to Apache, all you need to do is type the following command in your Terminal:

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

After the installation is complete, do restart your Apache Http Web Server.

> sudo /etc/init.d/apache2 start

This allow PHP to be include as Apache mod.

Testing PHP

A simple way to test your PHP is via phpinfo() function which display all related configuration of your PHP. To do so type the following command in your Terminal.

> sudo gedit /var/www/phpinfo.php

This will open gEdit text editor which you will type in

<?php phpinfo(); ?>

Open http://localhost/phpinfo.php in your web browser and you will get something like this:

You should see all of the info about your PHP installation listed on the page.

Install MySQL

Again, type the following command in your Terminal

> sudo apt-get install mysql-server

Note: As MySQL is installing, it will ask you to configure your root password. Make sure that you type it correctly, as it will only ask you once.

You might need to manually start MySQL for the first time, do so by typing this command in your Terminal.

> sudo /etc/init.d/mysql start

Testing MySQL

After that is finished, you can test MySQL by running this, where 123 is your password

> mysql -uroot -p123
mysql> show databases;
mysql> quit

Install PHPMyAdmin

As usual, run the following command in terminal

> sudo apt-get install phpmyadmin

This process is quite, as slow as MySQL installation and there are time you need to provide some information in order to complete the process but it quite optional. Once finish you need to create a soft link in /var/www/ to /usr/share/phpmyadmin using these command.

> sudo ln -s /usr/share/phpmyadmin /var/www/phpmyadmin

Now open up http://localhost/phpmyadmin your web browser.

Conclusion

If you find anything missing do drop a comment below. Any additional information are also welcome.

Reference

  1. How to install Apache, MySQL and PHP (LAMP) in Ubuntu 7.10
  2. Screencast: Install Apache 2.2, MySQL 5, PHP 5, phpMyAdmin for Linux Ubuntu 8.10
Posted in MySQL, PHP, Ubuntu | 15 Comments

15 Responses to Install Apache2, MySQL5, PHP5 and PHPMyAdmin on Ubuntu

  1. Akmal Hisyam says:

    great tutorial!
    before this i just use xampp to avoid the mess installing them one by one.. :-)

  2. Zaki says:

    Wanted to include oci8 installation for PHP as well but too long, will post on it went I have the time.

    I did use XAMPP for Windows before this and try installing it under Ubuntu but just not as flexible as you hope it to be, especially when you already familiar with production server running on separated installation.

  3. megat says:

    great tutor! i thought difficult to me to install that on my ubuntu. really useful for my web project! thanks.

  4. Feras Wilson says:

    Very Good Tutorial! I have Step-By-Step same tutorial as this but much easier, check out my site: feraswilson.com

    Thank you!

  5. shuji tan says:

    Hi Hoster,

    Thanks for you guideline. your website is very good.I like it..thanks. :) please work hard to publish more info on setup webserver and etc.

    thank you.

    Regards
    Shuji

  6. apad says:

    great tutorial, can you post latest guide for ubuntu 9.XX?

  7. hanep says:

    good one. i was about to search for my Ubuntu 9.10 apache2, mysql and php5 installation.

    i did use xampps before for windows but a feeling of bit simpler with linux/ubuntu.

  8. almamun says:

    Great.. very very helpful.. loads of thanks.

  9. abhay says:

    good tutorial..

    short and simple steps. very helpful

  10. krushna chandra swain says:

    Thank you, A great Tutorial

  11. darthz says:

    why is the soft link created after installing phpmyadmin ?

    btw-GREAT tutorial,keep it going.Regardz

  12. graham says:

    thank you very much. as always Linux community pulling together, I hope we will be around when MS is dead, gone and buried under the sands of time, not that i have a problem with MS.

  13. balamurugan says:

    Hi.. i need to install Lamp in my ubuntu forums… the following errors displaying while i install mysql server…

    Err http://in.archive.ubuntu.com jaunty-updates/main mysql-server-5.0 5.1.30really5.0.75-0ubuntu10.5
    403 Forbidden
    Err http://security.ubuntu.com jaunty-security/main mysql-server-5.0 5.1.30really5.0.75-0ubuntu10.5
    403 Forbidden [IP: 91.189.92.167 80]
    Failed to fetch http://security.ubuntu.com/ubuntu/pool/main/m/mysql-dfsg-5.0/mysql-server-5.0_5.1.30really5.0.75-0ubuntu10.5_i386.deb 403 Forbidden [IP: 91.189.92.167 80]
    E: Unable to fetch some archives, maybe run apt-get update or try with –fix-missing?

    how can i solve this problem? very urgent…

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>