How to Install phpMyAdmin with Apache on Ubuntu 22.04 LTS

Tutorial to learn the steps for installing phpMyAdmin on Ubuntu 22.04 LTS Jammy JellyFish using Apache Web server for managing MariaDB or MySQL via web browser and graphical user interface.

phpMyAdmin is a popular open-source software that we can get almost on all web hosting services for managing databases. However, if you are managing your hosting or cloud server by yourself then you have to install this Database management by yourself.

The program offers a graphical interface with numerous options. These can refer to a complete database and include, for example:

Creating a new database
Delete an existing database
Copy the content to a new database
Backup in a backup
Restore from an existing backup
Transferring from one server to another
Changing users and passwords
Manipulation of access rights

We can perform complex and time-consuming tasks without having to deal with commands and their structure with the help of phpMyAdmin. These include, but are not limited to:

Find variable names or content in databases
Replacing Values
Encryption of plain text using different algorithms, e.g. passwords
Multiple selections of variables via the graphical interface
Checking databases for internal consistency and other errors
Create and delete entries, parameters, or values
Create, copy or remove individual tables
Clear presentation of the structure of databases

Let’s learn how to install phpMyAdmin on Ubuntu 22.04 Server, however, the steps given here will also be the same for other versions of this Linux.

Steps to install phpMyAdmin on Ubuntu 22.04 Server

Estimated reading time: 8 minutes

1. phpMyAdmin Requirements

To perform this tutorial we require an Ubuntu server, a non-root sudo user access, an Apache web server, a Database, PHP, and an active internet connection.

2. Update Ubuntu 22.04 Server

The first thing we should perform is updating our Linux server because most of the packages we need to set up phpMyAdmin will come from the default Ubuntu Jammy JellyFish repository.

sudo apt update && sudo apt upgrade

Also, install:

sudo apt install wget nano

3. Install the LAMP server

We need LAMP Stack which refers to a software bundle comprised of Apache, MySQL/MariaDB, and PHP  installed on a Linux server. Well, for the Linux server, here we are using Ubuntu, the rest we will install in this step.

Apache Webserver

Apache is an open-source web server that is available to install directly using Ubuntu’s default repository:

sudo apt install apache2

Enable its server:

sudo systemctl enable apache2
sudo systemctl restart apache2

Setup MariaDB server

Next, install the MariaDB server which is a fork of MySQL, and work exactly similar to it. Just like apache, it is also available to set up using the default system repository.

sudo apt install mariadb-server mariadb-client

Enable and start 

sudo systemctl enable --now mariadb

Also, secure your MariaDB installation:

sudo mysql_secure_installation

As you run the above command, it will give a text-based wizard to secure your Database server. Here are the questions it will ask:

Enter current password for root (enter for none): Press ENTER.
Switch to unix_socket authentication? Press N, then ENTER.
Change the root password? Press Y, then ENTER.
Remove anonymous users? Press Y, then ENTER.
Disallow root login remotely? Press Y, then ENTER.
Remove test database and access to it? Press Y, then ENTER.
Reload privilege tables now? Press Y, then ENTER.

Install PHP and its extension

phpMyAdmin is a PHP-based SQL database management software, hence we need this scripting language on our Ubuntu system along with some common PHP extensions.

sudo apt install php php-{fpm,mbstring,bcmath,xml,mysql,common,gd,cli,curl,zip}

Also, enable PHP fpm to start with FPM, if not already:

sudo systemctl enable php8.1-fpm --now

4. Install phpMyAdmin on Ubuntu 22.04

Well, the one way to install phpMyAdmin is to use the APT package manager that will download and install it using Ubuntu’s repository. However, the thing which one should be aware of is that the version of phpMyadmin installed using APT will not be the latest one. It is because the long-term version of Ubuntu uses extremely stabled packages, therefore you won’t get the latest release of the software. In such a situation, we can manually download the package of phpMyadmin to configure. Let’s see how to do that.

Download phpMyAdmin’s latest version

The given command will automatically fetch and save the latest phpMyAdmin’s compressed file in Tar format. Just copy and execute it in your command terminal:

wget https://www.phpmyadmin.net/downloads/phpMyAdmin-latest-all-languages.tar.gz

Extract and configure

Once the file is downloaded on your system, extract and move it to your webroot directory.

Extraction:

tar xvf phpMyAdmin-*-all-languages.tar.gz

Now, move it:

sudo mv phpMyAdmin-*/ /var/www/html/phpmyadmin

Also, don’t forget to create a Temporary folder called ‘tmp‘ inside the extracted directory otherwise this will create a warning on the phpMyAdmin interface.

sudo mkdir -p /var/www/html/phpmyadmin/tmp

5. Add Blowfish cipher string

To work properly, phpMyAdmin needs a Blowfish cipher string in the configuration file for cookie authentication. However, by default, there is no main configuration file because we are setting up the phpMyAdmin manually. Instead, there is a sample configuration file that we can rename and use. Here is a command for that:

sudo cp /var/www/html/phpmyadmin/config.sample.inc.php /var/www/html/phpmyadmin/config.inc.php

Now, generate a 32-bit random string:

openssl rand -base64 32
Generate random 32 bit string for BowlFish

Copy the string generated by the above command:

Now, edit the phpMyAdmin configuration file

sudo nano /var/www/html/phpmyadmin/config.inc.php

and past it in the front of the line :

$cfg[‘blowfish_secret’] = ‘your-key‘; /* YOU MUST FILL IN THIS FOR COOKIE AUTH! */

Replace your key with the generated code.

Also, scroll down to the end and add this line.

$cfg['TempDir'] = '/var/www/html/phpmyadmin/tmp';
BowlFish secret key for phpMyAdmin

After that save your file by pressing Ctrl+O, hit the Enter key, and then exit the file editor- Ctrl+X.

Give Apache permission to access PHPMyAdmin files:

sudo chown -R www-data:www-data /var/www/html/phpmyadmin

File and directory permission:

sudo find /var/www/html/phpmyadmin/ -type d -exec chmod 755 {} \;
sudo find /var/www/html/phpmyadmin/ -type f -exec chmod 644 {} \;

6. Create Apache Vhost configuration file

We don’t want to serve the phpMyAdmin user interface on our root domain or IP address, hence, we either use a subdomain or a subfolder. Here we are serving it in a subfolder. Hence, create a configuration file for it.

sudo nano /etc/apache2/conf-available/phpmyadmin.conf

Copy Paste the following lines:

Alias /phpmyadmin /var/www/html/phpmyadmin

<Directory /var/www/html/phpmyadmin>
Options Indexes FollowSymLinks
DirectoryIndex index.php

<IfModule mod_php8.c>
AddType application/x-httpd-php .php

php_flag magic_quotes_gpc Off
php_flag track_vars On
php_flag register_globals Off
php_value include_path .
</IfModule>

</Directory>

# Authorize for setup
<Directory /var/www/html/phpmyadmin/setup>
<IfModule mod_authn_file.c>
AuthType Basic
AuthName "phpMyAdmin Setup"
AuthUserFile /etc/phpmyadmin/htpasswd.setup
</IfModule>
Require valid-user
</Directory>

# Disallow web access to directories that don't need it
<Directory /var/www/html/phpmyadmin/libraries>
Order Deny,Allow
Deny from All
</Directory>
<Directory /var/www/html/phpmyadmin/setup/lib>
Order Deny,Allow
Deny from All
</Directory>

Save the file- Ctrl+O hit Enter, and exit using Ctrl+X.

Activate new configuration:

sudo a2enconf phpmyadmin.conf

Restart the Apache Webserver

To make the changes apply successfully, restart the Apache webserver.

sudo systemctl restart apache2

7. Access the phpMyAdmin web interface

Enter the server IP address or domain name along with /phpmyadmin folder in the browser URL to access this web database management platform.

For example:

https://server-ipaddress/phpmyadmin

or

http://your-domain.com/phpmyadmin

Enter the MySQL database root user and its password to log in phpMyAdmin.

Login phpMyAdmin on ubuntu 22.04 server
Install phpMyAdmin on Ubuntu 22.04 Jammy using Apache

Note: If you get this notification at the footer – The phpMyAdmin configuration storage is not completely configured, some extended features have been deactivated. Find out why. Or alternately go to the ‘Operations’ tab of any database to set it up there.

Create Storage space

Then simply click on the Find out why link and click the “Create” link to automatically create phpmyadmin database.

Create Storage space phpmyadmin ubuntu 22.04

Conclusion

In this way, we can swiftly install the phpMyAdmin on Ubuntu 22.04 LTS Jammy for managing our MySQL or MariaDB database with the help of a web-based graphical user interface.  Because of its security, its extensive functionality, and its comfortable operation, PhpMyAdmin is considered the standard for the administration of MySQL and MariaDB databases. It is included in web hosting offers at many Internet Service Providers (ISPs) and is usually part of the basic configuration of Dedicated and Linux Virtual Servers (VPS). The most common tasks include regularly creating a backup, transferring databases to other servers, and troubleshooting technical failures.

For more, you can visit the official documentation.

Other Articles:

How to access remote MySQL database in local phpMyAdmin
How to Install phpMyAdmin on Debian 11 Bullseye (Apache)
Install Siege Benchmarking Tool on Ubuntu 22.04
How to Install PowerShell on Ubuntu 22.04 LTS

6 thoughts on “How to Install phpMyAdmin with Apache on Ubuntu 22.04 LTS”

  1. After execution this line “sudo systemctl enable -now mariadb”, this error comes “Failed to parse lines ‘ow”
    Any solution?

    Reply
  2. The tutorial was excellent. The steps were precise and very well illustrated. However, after logging into phpmyadmin and getting the …configuration storage is not completely configured… message, selecting Find out why and selecting Create, I still ended up with a message ‘The secret passphrase in configuration (blowfish_secret) is not the correct length. It should be 32 bytes long.’ I am sure I used the exact openssl rand command. The length of the generated string is 44 characters long. Could the rand directive be at fault?

    Reply
  3. hey man i followed all the steps and everything seemed to work but when i try to enter the ip address in my browser it shows “connection failed”

    Reply

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.