Friday, February 5, 2016

How to install PHP MySQL on Lubuntu 15.10


If you are php web developer, of course you will need to install php and mysql so that you can build some web page or web application. In this article i will show you how to install and setup php mysql on lubuntu 15.10.

I'm using lubuntu 15.10 in this article, but actually it should works also for other version of lubuntu, alright enough talking, i'll show you how to do it.

First of all you will need to install apache web server (apache2), i already create another article that explain the detail how to install and setup apache2. Anyway here's the command for installing apache web server:

sudo apt-get install apache2

Installing PHP

After apache web server is installed, you can go ahead install php package, and here's the command to do that:

sudo apt-get install php5

And then, to make apache web server works with php, we need to add module for apache so that it can work with php, simply by installing this library and then restart the apache service.

sudo apt-get install libapache2-mod-php5
sudo service apache2 restart

Alright now we need to make sure that php and apache are really working together, we are going to create a php file called info.php and run it from the web browser.

sudo leafpad /var/www/html/info.php
Leafpad text editor will appear, and then you need to type this codes:


Save and exit leafpad, and then open up your web browser and go to http://localhost/info.php, if apache and php configured correctly, you should see this page:


Alright, now that we have apache and php working, next we need to install and configure mysql database server, don't worry it should be easy.

Installing Mysql Database

To install mysql database, you need to open your console/terminal and then run this command:

sudo apt-get install mysql-server mysql-client

During installation you will be asked to enter administrator password for mysql database, make sure you remember it, because you will need it to use the database.

Now that, mysql database server is installed, we need to configure mysql so that mysql can work with php, we can do that simply by installing package called php5-mysql.

sudo apt-get install php5-mysql

At this point, theoretically you can start some web development using php and mysql, but to make sure php and mysql really works, let's create php script to connect to mysql database.

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


NOTE: change the password part with your own mysql database password. If successful the result should be like this:


That means, mysql and php is working, you can now start developing some web application with it, happy coding :)

This tutorial is based on these configuration :
  • Lubuntu 15.10 wily werewolf
  • Apache 2 web server
  • PHP 5.6
  • Mysql 5.6

No comments:

Post a Comment