How to install PHP MySQL on Xubuntu 18.04


How to install PHP MySQL on Xubuntu 18.04

If you already install apache web server, the next thing to do is installing php and mysql database, in this article i will show you how to install php 7.2 and mysql 5.7 on xubuntu 18.04 bionic.


How to install PHP on Xubuntu 18.04
  • open command line on xubuntu
  • run update command
  • sudo apt-get update
  • install php 7.2
  • sudo apt-get install php7.2
  • done!
Once installed you can test php by creating script that runs phpinfo() function, like this:
<?php 
phpinfo(); 
?>


How to install MySQL on Xubuntu 18.04
  • open command line on xubuntu
  • run update command
  • sudo apt-get update
  • install mysql server
  • sudo apt-get install mysql-server
  • open mysql from command line
  • sudo mysql
  • run this query to update mysql password for user root (change the 'yourpassword' part with your own password)
  • ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'yourpassword';
    FLUSH PRIVILEGES;
    quit
  • try login with the new password
  • mysql -u root -h localhost -p
  • exit mysql cli
  • quit
  • install php module for mysql
  • sudo apt-get install php7.2-mysql

Once mysql is installed you can test by creating php script that connect to mysql, like this:
<?php 
$mysqli = new mysqli("localhost", "root", "yourpassword", "mysql"); 
$result = $mysqli->query("SELECT 'Hello, dear MySQL user!' AS _message FROM DUAL"); 
$row = $result->fetch_assoc(); 
echo htmlentities($row['_message']); 
?>

Share this

Previous
Next Post »