Sunday, June 19, 2016

How to install PHP MySQL on Lubuntu 16.04

The next thing to do after installing apache web server is to install php and mysql, so that you can start developing some web pages. To install php and mysql on lubuntu 16.04 is little bit different than the previous version of lubuntu.

On lubuntu 16.04 you can't install php version 5 anymore, lubuntu 16.04 support for the newer php which is php 7, so the command you used to run to install php 5 won't work.

How to install php on lubuntu 16.04
Before installing php, it's a good idea that you install apache web server first before installing php, read my previous post on how to install apache web server on lubuntu 16.04.

If you are ready, this is the command for installing php on lubuntu 16.04 xenial xerus, this one does work on lubuntu 16.04.

sudo apt-get install php7.0

Next, we need to make sure the apache web server can recognize when someone accessing .php file on the web server, to do that, run this command:

 sudo apt-get install libapache2-mod-php

Now, we can do a test whether or not the apache web server really does recognize .php file, still on the command line, execute this command to create info.php.

sudo leafpad /var/www/html/info.php

Then copy paste this code to leafpad and save and exit.


Finally, open your web browser and go to URL http://localhost/info.php, it will show information about your php environment setting and that means the apache web server does recognize php file.

How to install mysql on lubuntu 16.04
The lasting we need to do now is installing mysql database, unlike php, the command for installing mysql database server doesn't change on lubuntu 16.04.

You can install mysql database server and mysql command line client with this command:

sudo apt-get install mysql-server mysql-client

During installation, you will asked to enter password for user root for mysql database, remember the password because you will needed to access the database server.

After mysql server is installed, we need to make sure that the php can access it, we need to install php module for mysql, and since we are using php7 the command is little bit different than the usual.

sudo apt-get install php7.0-mysql

Now we can test connection to mysql database by creating a php file that's connect to mysql database server, if it's work then our work is done here.

sudo leafpad /var/www/html/mysql-connect.php

Copy paste this code to the leafpad, exit and save.

$mysqli = new mysqli("localhost", "user", "password", "mysql"); 
$result = $mysqli->query("SELECT 'Hello, dear MySQL user!' AS _message FROM DUAL"); 
$row = $result->fetch_assoc(); 
echo htmlentities($row['_message']); 
NOTE: Change the user and password part with your own user and password for your mysql database server.

Open your web browser and go to url http://localhost/mysql-connect.php, it should says 'Hello, dear MySQL user!' and that means now you can start developing with php and mysql on lubuntu 16.04, all you need now is a good text editor to write php codes.


  1. This comment has been removed by a blog administrator.

  2. This comment has been removed by a blog administrator.

  3. This comment has been removed by a blog administrator.

  4. Web services are client and server applications that communicate over the World Wide Web’s (WWW) HyperText Transfer Protocol (HTTP). Web services provide a standard means of inter operating between software applications running on a variety of platforms and frameworks. Web Design Services