In today’s guide, we will discuss how you can Install phpMyAdmin on Debian 10 / Debian 11 Linux. phpMyAdmin is a free and Open source Web application written in PHP for administering MySQL and MariaDB database servers. It is mostly used by Developers and DBAs to interact with a database server because of its ease of use.
phpMyAdmin provides an advanced SQL editor which makes it easy to build and test complex SQL queries. It also allows you to manage Databases, Users, Data import and export, stored procedures and triggers, execute and edit queries, search database globally and much more.
This tutorial explains the steps for installing phpMyAdmin with Apache on Debian 11 / Debian 10 Linux system. Let’s get started.
Step 1: Install PHP
PHP is the main software requirement for running phpMyAdmin. Install it using our guide below.
For simplicity, the commands below can be executed to install PHP and extensions required.
sudo apt -y update
sudo apt -y install wget php php-cgi php-mysqli php-pear php-mbstring libapache2-mod-php php-common php-phpseclib php-mysql
Step 2: Install MariaDB Database Server
If you don’t have existing Database server to manage, you can use our guide to install MariaDB database server on Debian.
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, e.g Nginx.
Install Apache Web Server on Debian system by running the following commands
sudo apt-get -y install wget apache2
Step 4: Install and Configure 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.
DATA="$(wget https://www.phpmyadmin.net/home_page/version.txt -q -O-)"
URL="$(echo $DATA | cut -d ' ' -f 3)"
VERSION="$(echo $DATA | cut -d ' ' -f 1)"
wget https://files.phpmyadmin.net/phpMyAdmin/${VERSION}/phpMyAdmin-${VERSION}-all-languages.tar.gz
For English language only package, use:
wget https://files.phpmyadmin.net/phpMyAdmin/${VERSION}/phpMyAdmin-${VERSION}-english.tar.gz
Extract downloaded Archive:
tar xvf phpMyAdmin-${VERSION}-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
Restart apache web server.
sudo systemctl restart apache2
Step 6: Visit phpMyAdmin Web interface
Access phpMyAdmin Web interface on http://[ServerIP|Hostname]/phpmyadmin
. Use your database credentials – username & password to login.
phpMyAdmin dashboard is displayed upon a successful login. It looks something like this:
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
Conclusion
You now have a phpMyAdmin installed on Debian 10 / Debian 11. You can start managing your database server from a Web dashboard and stress less on mastering MySQL command line.
For other systems, check: