Install phpMyAdmin with Apache on Ubuntu 22.04

This an article to help Ubuntu users to install phpMyAdmin with Apache on Ubuntu 22.04. Why phpMyAdmin? PhpMyAdmin is graphical web interface administration tool for managing MySQL and MariaDB databases. It is free and simple to use. You can perform all database functions such as user creation, privilege management and SQL queries. Apache2 on the other hand will serve as web server by connecting your site to the database.

Install phpMyAdmin with Apache on Ubuntu 22.04

Install Apache on Ubuntu 22.04

Apache2 is featured in Ubuntu 22.04 repository making installation straightforward.

  • First update system packages.
sudo apt update && sudo apt upgrade
  • Install Apache2 and required modules
sudo apt install apache2 -y
  • Apache2 server runs by default and you can check status
systemctl status apache2
  • Output
$ systemctl status apache2
● apache2.service - The Apache HTTP Server
     Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled)
     Active: active (running) since Tue 2022-05-10 16:47:40 EAT; 7s ago
       Docs: https://httpd.apache.org/docs/2.4/
    Process: 4500 ExecStart=/usr/sbin/apachectl start (code=exited, status=0/SUCCESS)
   Main PID: 4504 (apache2)
      Tasks: 55 (limit: 3498)
     Memory: 4.8M
        CPU: 61ms
     CGroup: /system.slice/apache2.service
             ├─4504 /usr/sbin/apache2 -k start
             ├─4505 /usr/sbin/apache2 -k start
             └─4506 /usr/sbin/apache2 -k start

Mei 10 16:47:40 itnixpro-VirtualBox systemd[1]: Starting The Apache HTTP Server...
Mei 10 16:47:40 itnixpro-VirtualBox systemd[1]: Started The Apache HTTP Server.

Allow connection through firewall

  • Ubuntu 22.04 has ufw firewall and Apache2 needs to run through port 80 and 443. So enable connection via the firewall.
sudo ufw allow 'Apache Full'
  • Next enable the firewall
sudo ufw enable

Confirm if apache2 is running without issues by visiting your browser typing in http://your.ser.ver.IP or http://localhost

Managing Apache2 process

Start, stop, reload, enable, disable and restart Apache2 server using the command:

sudo systemctl [start|stop|reload|enable|disable|restart] apache2

Install MariaDB Server

Install MariaDB which is an advanced version of MySQL database server.

sudo apt install mariadb-server mariadb-client

Start and enable MariaDB server

sudo systemctl enable --now mariadb

Secure your database server by running the command below and enter Y followed by enter on every step

sudo mysql_secure_installation

Login to MySQL console

sudo mysql -u root

Create a database, user and password

CREATE DATABASE itnixpro;
GRANT ALL ON itnixpro.* TO itnixpro@localhost IDENTIFIED BY 'YOURStr0ngPassw0rd';
FLUSH PRIVILEGES;
QUIT;

Install PHP

Install PHP and required extensions. The command below automatically installs PHP 8

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

Let’s now see how we can install phpMyAdmin with Apache on Ubuntu 22.04

Install phpMyAdmin with Apache on Ubuntu 22.04

  • Download the latest version of phpMyAdmin
wget https://www.phpmyadmin.net/downloads/phpMyAdmin-latest-all-languages.tar.gz
  • Extract the files
tar xvf phpMyAdmin-*-all-languages.tar.gz
  • Move the files to /var/www/html folder
sudo mv phpMyAdmin-*/ /var/www/html/phpmyadmin
  • Then create a temporary folder to avoid warning from phpMyAdmin interface
sudo mkdir -p /var/www/html/phpmyadmin/tmp 
  • Give Apache permission to access phpMyAdmin files:
sudo chown -R www-data:www-data /var/www/html/phpmyadmin
  • Enable Blowfish cipher string in the configuration file for cookie authentication by editing existing configuration file.
sudo cp /var/www/html/phpmyadmin/config.sample.inc.php /var/www/html/phpmyadmin/config.inc.php
  • Edit the configuration file
sudo nano /var/www/html/phpmyadmin/config.inc.php
  • Enter the random string uyFxu+tR2iLB/2vAKc5Q/o4dUcREACMk or a 32-bit string.
$cfg['blowfish_secret'] = 'uyFxu+tR2iLB/2vAKc5Q/o4dUcREACMk';
  • Before exiting the file, add the TempDir directory you created earlier at the end.
$cfg['TempDir'] = '/var/www/html/phpmyadmin/tmp';

Configure Apache2 web server

  • Create Apache configuration file for phpMyAdmin:
sudo nano /etc/apache2/conf-enabled/phpmyadmin.conf
  • Paste the content:
	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>
  • Then restart Apache2
sudo systemctl restart apache2

Accessing phpMyAdmin Web interface

Visit your browser and type http://localhost/phpmyadmin or http://your.ser.ver.IP/phpmyadmin. The login page loads. Enter your username and password you created in the database or use root.

The phpMyAdmin dashboard loads:

You can create a new database and tables

Click on your database name and create a table

That is it! You have managed to install phpMyAdmin with Apache on Ubuntu 22.04.

Conclusion

This article has allowed you install phpMyAdmin with Apache on Ubuntu 22.04. You have learned to install PHP, MariaDB and Apache2 server in addition to their configuration.

Learn more in phpMyAdmin documentation.

Similar interesting tutorials

Install Webmin on Ubuntu 22.04

Install Bacula Server with MariaDB on Ubuntu 22.04

Install Caddy Web Server on Ubuntu 22.04

Android Developer | Linux | Technical Writer | Backend Developer

Leave a Comment