LinuxMySQL/MariaDBPHP

Install phpMyAdmin on Ubuntu/Debian OpenLiteSpeed Server

phpMyAdmin is a web-based graphical user interface (GUI) for managing MySQL and MariaDB databases. Developed in PHP, it simplifies database administration tasks by providing an intuitive interface accessible through a web browser. Developers and Linux Server Administrators often install phpMyAdmin during web development to interact with databases, debug queries, and perform routine maintenance tasks. It’s a powerful tool, but caution is necessary when handling critical data. We’re going to install phpMyAdmin on Debian/Ubuntu on one of our backend servers which we created in the MariaDB Database Replication guide. This will allow us to administer the databases on our cluster from a browser.

phpMyAdmin Features

Here are some key features of phpMyAdmin:

  1. Database Management: Create, modify, and delete databases, tables, columns, and indexes.
  2. User Account Control: Manage user accounts, set permissions, and control access to databases.
  3. SQL Execution: Execute SQL queries directly within the interface.
  4. Data Import and Export: Import data from files or export data to various formats.
  5. Query Building: Construct complex queries visually.
  6. Database Graphics: Generate visual representations of database structures.
  7. Global Search: Search for specific data across the entire database.

Install phpMyAdmin in Ubuntu/Debian on OpenLiteSpeed Servers

Our NVMe VPS is running Ubuntu 22 and phpMyAdmin is included in the default repository however, the latest version of phpMyAdmin for Ubuntu and Debian is available on the phpMyAdmin website. We will download and install phpMyAdmin in Ubuntu from the source. We’re installing phpMyAdmin to our NAS storage so the files are available on all hosts in our cluster.

mkdir -p /nas/www/db.f2hcloud.com
cd /nas/www/db.f2hcloud.com 
wget https://www.phpmyadmin.net/downloads/phpMyAdmin-latest-all-languages.zip
unzip phpMyAdmin-latest-all-languages.zip

Chown the new files to www-data:www-data so OpenLiteSpeed can read the files.

chown -R www-data:www-data /nas/www/db.f2hcloud.com

Configure OpenLiteSpeed Virtual Host

Next, we need to create a virtual host in OpenLiteSpeed. We can use the automated script to create this from the command line.

/bin/bash <( curl -sk https://raw.githubusercontent.com/litespeedtech/ls-cloud-image/master/Setup/vhsetup.sh ) -d db.f2hcloud.com

And now login to the OpenLiteSpeed control panel and modify the virtual host’s path to reflect the path to the phpMyAdmin files.

phpMyAdmin OpenLiteSpeed Virtual Host

If you are using Cloudflare your connection should be secure when you virtual the subdomain. But first, ensure you add an A record for your subdomain. In our examples, we are using the subdomain “db”.f2hcloud.com.

Create phpMyAdmin User

Next, we must create a user that can access all databases on the MariaDB Cluster. Create a user and assign these privileges with the below commands.

create user phpmyadmindb@localhost identified by 'PaSsWoRd';

grant all privileges on *.* to dbadmin@localhost with grant option;

Great. So now we have our phpMyAdmin files deployed to our shared storage and we also have a user. In your browser navigate to the phpMyAdmin setup. In our example, we would navigate to https://db.f2hcloud.com/setup.

So next, In the setup click “New Server” and then “Apply” and then “Display“. You do not need to make any changes. Copy the text that is displayed and place it in a file called config.inc.php at the below location. Modify the path to reflect your environment.

/nas/www/db.f2hcloud.com/config.inc.php

Login to phpMyAdmin

Now you can log in to phpMyAdmin on your subdomain with the database user you created above. That user has access to all databases.

Install SSL Certificate

However, If you are not using Cloudflare you will want to install an SSL to secure phpMyAdmin. Use the commands below to install an SSL and configure automatic renewal on your VPS Server.

apt install certbot -y

certbot certonly -d db.f2hcloud.com

Finally, to use the SSL in OpenLiteSpeed navigate to virtual hosts > db.f2hcloud.com > SSL and add the location of the SSL displayed in the console to the Private Key File & Certificate File locations.

That’s it. You have now installed phpMyAdmin and secured it with an SSL. You should consider password-protecting the directory or subdomain phpMyAdmin is using.

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button