Friday, January 6, 2017

How to install PHP MySQL on Ubuntu 16.04


I believe since ubuntu 16.04 LTS, the default php version on ubuntu repo is php version 7.0, so if you want php on ubuntu 16.04, you have to use php 7.0.

Installing php 7 is little bit different, i mean the package name is different, but everything else is still the same, all right let's get started.

Before installing php 7, of course you need to have a web server, so first you need to install apache web server, on ubuntu 16.04 the installation of apache web server is like this:
sudo apt-get install apache2
How to install PHP 7 on ubuntu 16.04 

Use this command to install php 7 on ubuntu 16.04 (or any ubuntu above 16.04)
sudo apt-get install php7.0

After that, you need to make the php recognize by the web server, run this:
sudo apt-get install libapache2-mod-php
You can put your php files on /var/www/html/ , let's create a simple php info page just to make sure that the php 7 is working properly.
sudo gedit /var/www/html/whatever.php
Copy paste code below into the gedit and save the file
<?php
phpinfo();
?>
Now open url http://localhost/whatever.php, using any browser you like




How to install MySQL on ubuntu 16.04

Next let's install mysql database using this command:
sudo apt-get install mysql-server mysql-client
During installation you will be asked for password, enter the password and remember it, because you are going to need it later.

Once installed, we need to link mysql to php by installing this package
sudo apt-get install php7.0-mysql
That's it php and mysql should works now, you can start developing web application, happy coding !!

No comments:

Post a Comment