How to install phpMyAdmin on Debian

Post Reply
User avatar
Spray
Former staff
Former staff
Posts: 630
https://www.youtube.com/channel/UC40BgXanDqOYoVCYFDSTfHA
Joined: Wed Dec 28, 2011 10:41 pm
Location: Oregon

How to install phpMyAdmin on Debian

Post by Spray »

This tutorial assumes you've followed the previous installation guide for LAMP on Debian, available here: viewtopic.php?f=46&t=15659

Installation

phpMyAdmin gives you a web-based UI to interact with the MariaDB server. phpMyAdmin is no longer offered in the default Debian 10 repositories as of this writing, so we'll need to install it from source.

First, we'll need to install some required PHP modules:

Code: Select all

sudo apt-get install php-mbstring php-zip php-gd
Confirm this installation with "y" and Enter.

Next, we need to download the latest phpMyAdmin release from the phpMyAdmin Download Page.

Navigate to the list of available downloads and find the most recent version of phpMyAdmin ending in "tar.gz", then right-click on that link and copy the URL. The most recent version as of this writing is 4.9.4. You can use the all-languages or english only version, whichever you prefer.

Now, we'll download this version to the server using wget, replacing the URL with the one you've copied:

Code: Select all

wget https://files.phpmyadmin.net/phpMyAdmin/4.9.4/phpMyAdmin-4.9.4-all-languages.tar.gz
Next, extract the downloaded file:

Code: Select all

tar xvf phpMyAdmin-4.9.4-all-languages.tar.gz
Then, move the extracted folder to the /usr/share folder, and rename it to "phpmyadmin":

Code: Select all

sudo mv phpMyAdmin-4.9.4-all-languages/ /usr/share/phpmyadmin
Create a tmp directory that phpMyAdmin will need to use later:

Code: Select all

sudo mkdir -p /var/lib/phpmyadmin/tmp
Next, we'll need to make the web server user (www-data) the owner of both of these directories:

Code: Select all

sudo chown -R www-data:www-data /usr/share/phpmyadmin
sudo chown -R www-data:www-data /var/lib/phpmyadmin

phpMyAdmin Configuration

Create a configuration file by copying the default sample configuration file included with the installation files:

Code: Select all

sudo cp /usr/share/phpmyadmin/config.sample.inc.php /usr/share/phpmyadmin/config.inc.php
Open this file using a text editor, such as nano:

Code: Select all

sudo nano /usr/share/phpmyadmin/config.inc.php
Create a random 32 character password and fill this in on the following line:

Code: Select all

$cfg['blowfish_secret'] = '';
An example of this may look like:

Code: Select all

$cfg['blowfish_secret'] = 'm7WSudFRSW8VEv4otwLzfNho55pBnmpD';
Save and close the text editor. For nano, you can use Ctrl+ X, Y, then Enter.

Apache Configuration

Create a phpmyadmin.conf file in the /etc/apache2/conf-available/ directory:

Code: Select all

sudo nano /etc/apache2/conf-available/phpmyadmin.conf
Copy and paste the following content into this file:

Code: Select all

# phpMyAdmin default Apache configuration

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>
Save and close the text editor. For nano, you can use Ctrl+ X, Y, then Enter.

Next, enable the file for use with Apache using the command:

Code: Select all

sudo a2enconf phpmyadmin.conf
Finally, reload Apache2 using the command:

Code: Select all

sudo systemctl reload apache2
When this is complete, you can go to http://your-server-ip-here/phpmyadmin/ and access the installation of phpMyAdmin!
Post Reply