How to install and configure Apache,PHP,MySql and phpMyadmin (LAMP) on ubuntu

33
SHARES

On Windows Click Here: How to install and configure Apache,PHP,MySql and phpMyadmin on windows

On Linux mint Click Here How to install and configure Apache, PHP, MySql and phpMyadmin on Linux Mint

UPDATED FOR Ubuntu 16.04 (Xenial Xerus)
Step 1:
Installing apache

To install apache on ubuntu, Open Terminal. To open terminal click the Dash home from unity launcher. And type terminal in the search field.And click Terminal .

terminal

And type the below code in terminal and hit enter.

sudo apt-get install apache2

Type your ubuntu password and press enter.

Type y and hit enter to confirm apache installation.

After the successful installation  , open your favorite browser and type

http://localhost/

in the address bar and press enter. If you will see ‘It works!’ in the Apache2 Ubuntu Default Page, then your apache works fine.
Apache2 Ubuntu Default Page: It works

Step 2:
Installing PHP

To install PHP on your ubuntu OS, Open Terminal. And type the below code in terminal and hit enter.

sudo apt-get install libapache2-mod-php

Type your ubuntu password if needed.

Type y and hit enter to confirm PHP installation. This will install PHP7 on ubuntu.
After the successful installation restart Apache using the below code

sudo /etc/init.d/apache2 restart

or use the below code to restart

sudo systemctl restart apache2

Install php 7 and php 5.6 in the same system:

You can also install php 5.6 and php 7 in the same system. To install php 5.6 along with php 7, you need to add ondrej php PPA.

To add this PPA. open your ubuntu terminal. And add the below code in terminal and press enter key.

sudo add-apt-repository ppa:ondrej/php

then type the below command

sudo apt-get update

Then type the below command in terminal and hit enter.

sudo apt-get install php5.6

If you want to install some other php extensions use the below code to install them.

sudo apt-get install php5.6-mysql php-gettext php5.6-mbstring php-xdebug libapache2-mod-php5.6 php5.6-cgi php5.6-cli php5.6-curl php5.6-gd php5.6-intl php-imagick php5.6-imap php5.6-mcrypt php-memcache php5.6-pspell php5.6-recode php5.6-sqlite3 php5.6-tidy php5.6-xmlrpc php5.6-xsl php-xcache php5.6-fpm

You can switch the PHP version easily with the below code.

To switch from php7.0 to php5.6:

Type the below command in terminal and press enter key

sudo a2dismod php7.0 ; sudo a2enmod php5.6 ; sudo service apache2 restart

then

sudo ln -sfn /usr/bin/php5.6 /etc/alternatives/php

To switch from php5.6 to php7.0:

Type the below command in terminal

sudo a2dismod php5.6 ; sudo a2enmod php7.0 ; sudo service apache2 restart
sudo ln -sfn /usr/bin/php7.0 /etc/alternatives/php

Test PHP installation

To test PHP is installed, Type below code and hit enter (only for php7)

sudo gedit /var/www/html/phpinfo.php

in the terminal and type your ubuntu password if needed. It will open the phpinfo.php file in gedit.Type below code in the phpinfo.php file, save and exit it .

<?php phpinfo() ?>

Now open your favorite browser and type http://localhost/phpinfo.php in the address bar and press enter. If you will see the below page , then your php works fine.
phpinfo

To check the installed PHP version in terminal, type the below command in terminal and hit enter.

php -v

php version check
Step 3:
Installing MySql

SEE ALSO:   How to disable recently used app and file list in Ubuntu Dash

To install MySql on ubuntu, Open Terminal. And type the below code in terminal and hit enter.

sudo apt-get install mysql-server

Type your ubuntu password if needed.

Type y and hit enter to confirm MySql installation.
During the installation you will be prompted for a password.Choose something secure and type the password and hit enter .

Repeat the password and press enter.

To install the mysql client, type the below command in terminal and press the enter key in your keyboard

sudo apt-get install mysql-client

To check the MySQL server status, use the below command

sudo systemctl status mysql

Install php mysql, php curl and php json modules:

To install php mysql, php curl and php json modules use the below command in terminal.

sudo apt-get install php7.0-mysql php7.0-curl php7.0-json

Step 4:
Installing phpMyadmin

phpMyAdmin is a free software tool written in PHP intended to handle the administration of MySQL over the World Wide Web.

Open Terminall. And type the below code in terminal and hit enter.

sudo apt-get install phpmyadmin

Type your ubuntu password if needed.

Type y and hit enter to confirm phpMyadmin installation.

During the installation you will be prompted for a configure database for phpmyadmin wjth dbconfig-common.

Select ‘Yes’ to configure database for phpmyadmin wjth dbconfig-common.

phpmyadmin config 1

Then Enter password of the database’s administrative user.

and select OK and press enter.

phpmyadmin config 2

Then enter your MySQL application password for phpmyadmin:

and select OK and press enter.

phpmyadmin config 3

During the installation you will be prompted for a webserver configuration. Select apache2

(already selected) press enter.

After the successful installation and configuration, restart apache using the below command.

sudo systemctl restart apache2

Then open your browser and type

http://localhost/phpmyadmin/

in the address bar and press enter. It will open the Phpmyadmin admin login page.

Type your username and password to login.

phpMyAdmin on ubuntu

In case phpMyAdmin is not working or you get an empty phpmyadmin page, then please do the following steps.

Open terminal, and type the below command :

sudo gedit /etc/apache2/apache2.conf

it will open the apache2.conf file in gedit with root permission.

Add the below line at the end of the file and  save and the exit it.

Include /etc/phpmyadmin/apache.conf

Restart apache service using the below command.

sudo systemctl restart apache2

Then type the below code in terminal.

sudo apt-get install php-mbstring php7.0-mbstring php-gettext

Then restart mysql using the below command.

sudo /etc/init.d/mysql restart

Then open your browser and type

http://localhost/phpmyadmin/

in the address bar and press enter. It will open the Phpmyadmin admin login page.

Type your username and password to login.

You’re now ready to start building your local website. just put all of your files into

/var/www/html/

If you forget your username and password, just type the below command in terminal

sudo gedit /etc/phpmyadmin/config-db.php

Note down the username and password.

phpmyadmin username and password on ubunut

You may also like...

56 Responses

  1. Boby says:

    Thanks for this post. But to install in ubuntu server this tutorial helps me
    http://tut.julfi.com/install-apache-php-mysql-ubuntu/

  2. kalidasan says:

    Very nice post. Thanks 🙂

  3. somenody says:

    hi… this tutorial helped a lot ! But when we entered password i have just pressed ENTER now i can not access(log in) to phpMyAdmin. What i should do ? Please help me! i typed root, SPACE but i doesn’t works !

  4. bdbahman says:

    ubuntu 13.04

    well done…

    tanx

  5. Keir says:

    Hi, why do you not select “yes” on the database installation like this guide? http://draalin.com/installing-phpmyadmin-in-ubuntu/

    I am just wondering why.

    Thanks

  6. Coding-Romy says:

    Wow.. it works!!! Wonderfull!!

  7. siddhartha says:

    it was really helpful for me thank you very much.

  8. Renee says:

    Thanks this was very helpful

  9. Adrian says:

    Thanks, i have been trying to do this for days!! u really saved me from a lot of headaches

    Thanks once again

  10. shanoj says:

    works fine.really helpfull.thanks alot….

  11. ahmed ali says:

    Thanks man … i was stuck

  12. Nagendra says:

    thanks alot yaar..it was very useful post…:)

  13. puppypark says:

    I use 11.4 …I am too lazy to upgrade

  14. basil2style says:

    really wasome i like it..plz say what is the main use of phmyadmin? Did every1 use it?

  15. Ladi Oluwa says:

    thanks!

  16. Contact says:

    Works great! Highly recommended!

  17. Iulian Peride says:

    Thank you 

  18. Kalicharan Sikarwar says:

    you are really simple and great

  19. Matheus says:

    hey all worked for meee!!! thankssss is my first expirience!!!!! sucess!!!!

  20. Bichnm says:

    You are simply the best !

  21. Ifmartins says:

    It works very well! Thank you

  22. Eric_grego says:

    Very good tutorial!

  23. Rmoorthyk says:

    Thanks

  24. Mithu Hassan says:

    Thanks for interesting and useful 🙂

  25. Harishk says:

    Thank you for tutorial

  26. Sam says:

    Thanks for the great tutorial. Thumbs up!..

  27. DrK says:

    I followed the steps blindly but I’m at the last step. What’s my mysql user name and password?

  28. ALTAiR says:

    Thanx a lot buddies. Very helpgul.
    We did this inside window with the help of Virtualbox on an ubuntu desktop 11.

  29. Rami says:

    you can just include this in apache.conf

    include /etc/phpmyadmin/apache.conf

  30. GoldenBeast says:

    Thanks Alot !!#23

  31. happyfreak says:

    tnx alot – newbie here and this was the thing i’m looking for.. tnx much

  32. Mad says:

    This tutorial was complete in all respects, the installation finished like a sweetheart ! Thanks 🙂

  33. babour says:

    Best tutorial on the subject and I have seen a lot of them!

    Thank a lot and great job!

  34. Hamza Waqas says:

    Thanks mate.. Its works. You made it easy for me to work on LAMP now. 🙂

  35. seafury says:

    Hi Thanks for very helpfull post.

    A question what theme are you using on your ubuntu?

    Thanks.

  36. German says:

    very usefull, tnx

  37. sak says:

    Thanks for this man!

  38. CaptHeggie says:

    Hey thanx a lot .. It was really Helpful

  39. Matt says:

    Thanks a lot! This is exactly what I was looking for… I had made the LAMP installation but phpmyadmin was coming up with a 404 error until I configured it using your instructions. Very helpful article!

  40. Hardy HP says:

    Once more please,

    I’m still have problems how to configure mysql connected and can be updated fom my php scripts? cause likely mysql still no connected yet. my friend who using other distro recommended to edit httpd.conf in etc/httpd/ but the folder no found in my ubuntu 11.04.

    please help

    Thank

  41. Hardy HP says:

    Phpmyadmin installed ok, making directories my_site in var/www ok, but why no text/images displayed when I try to open http://localhost/my_site ?
    Please help.

    Best Regard.

  1. February 19, 2011

    […] on your localhost, you must setup apache and mysql first. We have already posted a tutorial on How to install and configure Apache,PHP,MySql and phpMyadmin on ubuntu.Please read […]

  2. February 19, 2011

    […] 7 on your localhost, you must setup apache and mysql first. We have already posted a tutorial on How to install and configure Apache,PHP,MySql and phpMyadmin on ubuntu.Please read […]

  3. February 23, 2011

    […] 1.6 on your localhost, you must setup apache and mysql first. We have already posted a tutorial on How to install and configure Apache,PHP,MySql and phpMyadmin on ubuntu.Please read […]

  4. April 3, 2011

    […] on your localhost, you must setup apache and mysql first. We have already posted a tutorial on How to install and configure Apache,PHP,MySql and phpMyadmin on ubuntu. Please read […]

  5. April 16, 2011

    […] To install phpbb on your localhost, you must setup apache and mysql first. We have already posted a tutorial on How to install and configure Apache,PHP,MySql and phpMyadmin on ubuntu.  Please read first. […]

  6. November 14, 2011

    […] then followed the instructions here  to install Apache, PHP, and MySQL, and that worked smoothly as well.  I installed and was […]

Leave a Reply

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


*