In our today’s guide, we will discuss how you can Install phpMyAdmin with Apache on Ubuntu 22.04|20.04|18.04. The phpMyAdmin package available on Ubuntu 22.04|20.04|18.04 repository is a bit old. If you need to install the latest phpMyAdmin on Ubuntu 22.04|20.04|18.04, you’ll have to download the package from the official phpMyAdmin releases page.
For Fedora guys, use our previous guide: How to Install and Configure phpMyAdmin on Fedora
What is phpMyAdmin?
phpMyAdmin is a free and Open source tool written in PHP used to administer MySQL and MariaDB database server from a Web interface. Most Developers prefer to use phpMyAdmin to interact with a database server because of its ease of using, plus advanced SQL editor which makes it easy to build and test complex SQL queries.
Step 1: Install PHP & Extensions
The first software requirement for running phpMyAdmin is PHP. Since phpMyAdmin is written in PHP, you need to install it on the host system. The version of PHP can be the one available on the repository or a more recent version.
If you choose to go with the version of PHP available in your OS repositories, install it by running commands below in your terminal.
sudo apt update
sudo apt install -y php php-tcpdf php-cgi php-pear php-mbstring libapache2-mod-php php-common php-phpseclib php-mysql
Step 2: Install MariaDB Database (Optional)
The next step is to install MariaDB database server if you don’t have one already.
sudo apt install mariadb-server
Secure your database server:
sudo mysql_secure_installation
You’ll need a non root user to access phpMyAdmin dashboard. If you don’t have one, you can create a test one.
Login to mysql shell:
sudo mysql -u root
Create test database and user.
CREATE DATABASE mydemo;
GRANT ALL ON mydemo.* TO mydemo@localhost IDENTIFIED BY 'MyStrongDBPassw0rd';
FLUSH PRIVILEGES;
QUIT
Test login with created user.
$ mysql -u mydemo -pMyStrongDBPassw0rd
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 59
Server version: 10.3.22-MariaDB-1ubuntu1 Ubuntu 20.04
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]>
Step 3: Install Apache Web Server
For this installation setup, we chose Apache as a web server to use with phpMyAdmin. You are free to choose whichever web server you prefer though.
Install Apache on Ubuntu / Debian by running the following commands:
sudo apt -y install apache2
Step 4: Download phpMyAdmin
You can check the released of phpMyAdmin from the downloads page. Thanks William Desportes for the hint on how to pull the latest release of phpMyAdmin.
Download latest version of phpMyAdmin with wget command.
wget https://www.phpmyadmin.net/downloads/phpMyAdmin-latest-all-languages.tar.gz
Extract downloaded Archive:
tar xvf phpMyAdmin-latest-all-languages.tar.gz
Move the resulting folder to /usr/share/phpmyadmin
folder.
sudo mv phpMyAdmin-*/ /usr/share/phpmyadmin
Create directory for phpMyAdmin temp files.
sudo mkdir -p /var/lib/phpmyadmin/tmp
sudo chown -R www-data:www-data /var/lib/phpmyadmin
Create directory for phpMyAdmin configuration files such as htpass file.
sudo mkdir /etc/phpmyadmin/
Create phpMyAdmin configuration file.
sudo cp /usr/share/phpmyadmin/config.sample.inc.php /usr/share/phpmyadmin/config.inc.php
Edit the file /usr/share/phpmyadmin/config.inc.php
and set secret passphrase:
$ sudo vim /usr/share/phpmyadmin/config.inc.php
$cfg['blowfish_secret'] = 'H2OxcGXxflSd8JwrwVlh6KW6s2rER63i';
Configure Temp directory:
$cfg['TempDir'] = '/var/lib/phpmyadmin/tmp';
Step 5: Configure Apache web Server
Create phpMyAdmin Apache configuration file:
sudo vim /etc/apache2/conf-enabled/phpmyadmin.conf
And paste below contents to the file:
Alias /phpmyadmin /usr/share/phpmyadmin
<Directory /usr/share/phpmyadmin>
Options SymLinksIfOwnerMatch
DirectoryIndex index.php
<IfModule mod_php5.c>
<IfModule mod_mime.c>
AddType application/x-httpd-php .php
</IfModule>
<FilesMatch ".+\.php$">
SetHandler application/x-httpd-php
</FilesMatch>
php_value include_path .
php_admin_value upload_tmp_dir /var/lib/phpmyadmin/tmp
php_admin_value open_basedir /usr/share/phpmyadmin/:/etc/phpmyadmin/:/var/lib/phpmyadmin/:/usr/share/php/php-gettext/:/usr/share/php/php-php-gettext/:/usr/share/javascript/:/usr/share/php/tcpdf/:/usr/share/doc/phpmyadmin/:/usr/share/php/phpseclib/
php_admin_value mbstring.func_overload 0
</IfModule>
<IfModule mod_php.c>
<IfModule mod_mime.c>
AddType application/x-httpd-php .php
</IfModule>
<FilesMatch ".+\.php$">
SetHandler application/x-httpd-php
</FilesMatch>
php_value include_path .
php_admin_value upload_tmp_dir /var/lib/phpmyadmin/tmp
php_admin_value open_basedir /usr/share/phpmyadmin/:/etc/phpmyadmin/:/var/lib/phpmyadmin/:/usr/share/php/php-gettext/:/usr/share/php/php-php-gettext/:/usr/share/javascript/:/usr/share/php/tcpdf/:/usr/share/doc/phpmyadmin/:/usr/share/php/phpseclib/
php_admin_value mbstring.func_overload 0
</IfModule>
</Directory>
# Authorize for setup
<Directory /usr/share/phpmyadmin/setup>
<IfModule mod_authz_core.c>
<IfModule mod_authn_file.c>
AuthType Basic
AuthName "phpMyAdmin Setup"
AuthUserFile /etc/phpmyadmin/htpasswd.setup
</IfModule>
Require valid-user
</IfModule>
</Directory>
# Disallow web access to directories that don't need it
<Directory /usr/share/phpmyadmin/templates>
Require all denied
</Directory>
<Directory /usr/share/phpmyadmin/libraries>
Require all denied
</Directory>
<Directory /usr/share/phpmyadmin/setup/lib>
Require all denied
</Directory>
You can restrict access from specific IP by adding line like below:
Require ip 127.0.0.1 192.168.18.0/24
- Where 192.168.18.0/24 is your trusted subnet.
Restart apache web server.
sudo systemctl restart apache2
Step 6: Visit phpMyAdmin Web interface
Open the URL http://[ServerIP|Hostname]/phpmyadmin
to login to phpMyAdmin dashboard with your Database credentials – username & password.
phpMyAdmin dashboard is displayed upon a successful login. It looks something like this:
Enjoy Administering MySQL / MariaDB database server using phpMyAdmin.
Recommended books to read:
- Best Books to learn Web Development – PHP, HTML, CSS, JavaScript and jQuery
- Best Books To Master Web Design
- Best Books To Learn CSS & CSS3
- Best Books To Learn HTML & HTML5
- Best Apache and Nginx reference Books
Thank you again for using our guide to install phpMyAdmin on Ubuntu 22.04|20.04|18.04 Linux system. We hope this guide was helpful to you.