PHPMyAdmin is a free tool written in PHP and is used to manage mySQL databases over the web.
Ever sine I started with PHP development I have been accustomed to using PHPMyAdmin to manage my databases. The interface is simple and have all the required tools that I require for my mySQL operations.
PHPMyAdmin comes bundled up with the XAMPP software. But I wanted to use it independently of the Software or Apache. Since for my WordPress or Laravel setups I tend to use the built-in web-server provided by PHP. I tried spinning up PhpMyAdmin on the same and it worked just fine.
In this post I have written down the step by step guide on setting up PHPMyAdmin on your Ubuntu machine along with the installation of PHP and MySQL
# 1. Install PHP
You can skip this step if you already have php installed in your system. You can confirm by running the following command.
Use coupon 5balloons on this Cloudways Affiliate URL to get special discount.
Ubuntu 20.04 comes with PHP 7.4 in its upstream repositories. You can just update the repositories and run the apt install command to install the latest PHP version.
sudo apt udpate sudo apt install php
Once you have it installed, you can confirm by checking the current version.
# 2. Install MySQL
Since we’ll be using PHPMyAdmin to manage our MySQL databases. We’ll need to have the mySQL server setup in the ubuntu machine.
You can skip this step if you already have mySQL installed in your system. Confirm it by executing the following command
Follow along the steps to Install MySQL on your machine.
Run the following command to install mysql server and php mysql connector
sudo apt-get install mysql-server php7.4-mysql
Once you have mysql installed, If you are looking to set a password for your mysql connectiona and also configure other security aspects. You can configure the security options by executing the following command, and following along with the questions asked.
If you are okay with the blank password for your mysql you can skip this step.
Next Up, To be able to connect to MySQL to a client (PHPMyAdmin in this case), we need to be able to connect to mysql without sudo privileges. Execute following commands.
sudo mysql -u root -p
Enter your password once prompted, It will login you into mysql console
Execute the following query
mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';
Be sure to alter the password in the above command to match your mysql password or leave blank if you haven’t set any password for your mysql.
mysql> FLUSH PRIVILEGES;
exit; out of mysql prompt and try logging in again without sudo privilege.
# 3. Download PHPMyAdmin
This step is straightforward. Head over to the PHPMyAdmin website. https://www.phpmyadmin.net/ and download the latest version of the software.
At the time of writing this tutorial the latest version of PhpMyAdmin available is 5.0.2
Extract the downloaded zip and place the phpmyadmin folder in the desired directory. I have placed mine under ~/code directory.
# 4. Configure PHPMyAdmin (No Password)
If you haven’t set any password for PhpmyAdmin. By Default phpMyAdmin won’t allow you to login and will present you with the following error.
Login without a password is forbidden by configuration (see AllowNoPassword)
Thus, if you have no password for the mySQL you need to perform an additional step in the configuration flie.
Copy the file Config.sample.inc.php and create a flie named conifg.inc.php with the same contents, change the following parameter to true instead of false.
$cfg['Servers'][$i]['AllowNoPassword'] = true;
# 5. Run PHPMyAdmin on Builtin Server
Running PHPMyAdmin on builtin PHP Server is easy. Open the terminal and navigate inside the phpmyadmin directory.
Run the following command
php -S localhost:4000
This will start the phpmyadmin on localhost server and on port 4000. You can change the port number as you desire.
Open your browser and navigate to the URL http://localhost:4000 and you should see the following login screen.
Enter the credentials, leave the password blank if you haven’t setup mySQL password and now you can login into the PHPmyAdmin on Ubuntu using builtin PHP Server.
You can read more details about how to Setup Auto Login into PHPMyAdmin, so that you dont have to put credentials everytime.
That’s all about Setting Up PHPMyAdmin on your Ubuntu v 20.04.