Monday, November 6, 2017

How to install PHP MySQL on Lubuntu 17.10

How to install PHP MySQL on Lubuntu 17.10

Alright after installing apache web server, now we can install php and mysql database. By default lubuntu 17.10 has php version 7.1 and mysql 5.7 in the repo, so we are going to install that. In this article i'm going to show you how to install php and mysql on lubuntu 17.10 artful.

How to install PHP 7.1 on Lubuntu 17.10
  • open command line/terminal on lubuntu
  • run update command
  • sudo apt-get update
  • install php 7.1 package
  • sudo apt-get install php7.1
  • install libapache2-mod-php package
  • sudo apt-get install libapache2-mod-php
  • create info.php to confirm that php works properly
  • sudo leafpad /var/www/html/info.php
  • copy paste these code to info.php
  • <?php 
    phpinfo(); 
    ?>
  • open url http://localhost/info.php/
  • done!


How to install MySQL 5.7 on Lubuntu 17.10
  • open command line/terminal on lubuntu
  • run update command
  • sudo apt-get update
  • install mysql server and client (during mysql installation you will be asked to enter mysql password for user root, make sure you remember it)
  • sudo apt-get install mysql-server mysql-client
  • install php 7.1 module for mysql
  • sudo apt-get install php7.0-mysql
  • create mysql-test.php to make sure php and mysql works properly together
  • sudo leafpad /var/www/html/mysql-test.php
  • copy paste these codes to mysql-test.php (put your own root password for mysql)
  • <?php 
    $mysqli = new mysqli("localhost", "root", "password", "mysql"); 
    $result = $mysqli->query("SELECT 'Hello, dear MySQL user!' AS _message FROM DUAL"); 
    $row = $result->fetch_assoc(); 
    echo htmlentities($row['_message']); 
    ?>
  • restart apache web server
  • sudo service apache2 restart
  • open url http://localhost/mysql-test.php/
  • done!

2 comments: