Install phpMyAdmin with Apache on Debian 11

In this guide, I will take you through how to install phpMyAdmin with Apache on Debian 11. PhpMyAdmin is graphical a MySQL/MariaDB administration tool accessed via a web interface. It is free and simple to use.
PhpMyAdmin interacts with your database by replacing the raw SQL commands although you can use a combination of both. Apache2 will act as a web server by allowing your site to connect to the database.

Install phpMyAdmin with Apache on Debian 11

Step 1: Install Apache on Debian 11

Apache2 is already present in Debian 11 repository making installation easy.

  • Ensure system packages are updated:
sudo apt update
  • Install Apache2 and required modules
sudo apt install apache2 -y
  • Apache2 server automatically runs after installation 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 prese>
     Active: active (running) since Wed 2022-05-11 10:11:41 EDT; 5s ago
       Docs: https://httpd.apache.org/docs/2.4/
    Process: 3247 ExecStart=/usr/sbin/apachectl start (code=exited, status=0/SU>
   Main PID: 3251 (apache2)
      Tasks: 55 (limit: 3531)
     Memory: 8.8M
        CPU: 50ms
     CGroup: /system.slice/apache2.service
             ├─3251 /usr/sbin/apache2 -k start
             ├─3252 /usr/sbin/apache2 -k start
             └─3253 /usr/sbin/apache2 -k start
lines 1-13/13 (END)
  • Confirm if Apache is running without errors in http://your.ser.ver.IP or http://localhost

Managing Apache2 process

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

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

Step 2: Install MariaDB Server

  • Install MariaDB database server.
sudo apt install mariadb-server mariadb-client
  • Enable and start MariaDB server
sudo systemctl enable --now mariadb
  • Secure your database server. Enter y or N depending on your need.
sudo mysql_secure_installation
  • Login to MySQL console
sudo mysql -u root
  • Create a database itnixpro, user itnixpro and password YOURStr0ngPassw0rd
CREATE DATABASE itnixpro;
GRANT ALL ON itnixpro.* TO itnixpro@localhost IDENTIFIED BY 'YOURStr0ngPassw0rd';
FLUSH PRIVILEGES;
QUIT;

Step 3: Install PHP on Debian 11

Install PHP 7.4 and required modules.

sudo apt -y install wget php php-cgi php-mysqli php-pear php-mbstring libapache2-mod-php php-common php-phpseclib php-mysql

It’s time to install phpMyAdmin with Apache on Debian 11.

Step 4: Install phpMyAdmin with Apache on Debian 11

  • PhpMyAdmin present in the repository is outdated. 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 /usr/share/ folder
sudo mv phpMyAdmin-*/ /usr/share/phpmyadmin
  • Next create a temporary folder
sudo mkdir -p /var/lib/phpmyadmin/tmp
  • Grant Apache permission to access phpMyAdmin files:
sudo chown -R www-data:www-data /var/lib/phpmyadmin
  • Create a directory for holding phpMyAdmin configuration files
sudo mkdir /etc/phpmyadmin/
  • Define Blowfish cipher string for cookie authentication by editing existing configuration file.
sudo cp /usr/share/phpmyadmin/config.sample.inc.php  /usr/share/phpmyadmin/config.inc.php
  • Modify the configuration file
sudo nano  /usr/share/phpmyadmin/config.inc.php
  • Enter the value as uyFxu+tR2iLB/2vAKc5Q/o4dUcREACMk or any random 32-bit string.
$cfg['blowfish_secret'] = 'uyFxu+tR2iLB/2vAKc5Q/o4dUcREACMk';
  • Add the TempDir directory you created earlier.
$cfg['TempDir'] = '/var/lib/phpmyadmin/tmp';

Step 5: Configure Apache2 web server

  • Create a new Apache configuration file for phpMyAdmin:
sudo nano /etc/apache2/conf-enabled/phpmyadmin.conf
  • Copy and paste the content below:
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>
  • Finally, restart Apache2
sudo systemctl restart apache2

Step 6: Accessing phpMyAdmin Web interface

Open your browser and type in http://localhost/phpmyadmin or http://your.ser.ver.IP/phpmyadmin. The login page loads and you can enter your username you created or root and password.

You will be redirected to phpMyAdmin dashboard:

You can create a new database by clicking on the Databases tab (only possible to use with root privileges)

Click on the database name on the left panel to create tables

Congrats! You have just managed to install phpMyAdmin with Apache on Debian 11.

Find more information in phpMyAdmin documentation.

Similar interesting tutorials

Install Nginx Web Server on Debian 11/Debian 10

Install Caddy Web Server on Debian 11/Debian 10

Install LAMP Stack on Debian 11

Android Developer | Linux | Technical Writer | Backend Developer

Leave a Comment