How to Install phpMyAdmin in Debian 12
In this guide, we will demonstrate how phpMyAdmin is installed on a Debian 12 system. phpMyAdmin requires a standalone Database or as part of the LAMP stack, installed and running on the system before hand.
At the time of making this guide, phpMyAdmin 5.2 was latest, please Navigate to phpMyAdmin download page for latest version when installing and ensure you are on the latest version.
Prerequisites
-
Server with root access.
-
Server with Apache, PHP, and MariaDB installed and running.
- You can refer to the article we have for setting up LAMP Stack in case you do not have the required services running.
Update the System
We first update the system to make sure that all our installed packages are up to date. Your Debian system can be updated easily with the following command.
apt update
apt upgrade
Install the required phpMyAdmin packages.
apt install php-mbstring php-zip php-gd
Install via APT Repository
Using APT
package manager, we can quickly install and setup the phpMyadmin on the server.
This will automatically find the most suitable version to download and install.
Follow the instructions as shown below:
Install the phpmyadmin
package,
apt install phpmyadmin
During the configuration, you will be prompted to select a webserver and enter Admin password.
Choose Apache2 as the web server in this step,
Choose the option Yes to configure the database for phpmyadmin by itself using bdconfig-common
,
Next, Enter the password for phpmyadmin,
Next, Skip to the step Create Database and User
Downloading phpMyAdmin
For installing a specific version of the phpmyadmin, you'll need to manually download the software. Navigate to phpMyAdmin download page to check the latest stable version.
Then run the following command to download it.
wget https://files.phpmyadmin.net/phpMyAdmin/5.2.1/phpMyAdmin-5.2.1-all-languages.tar.gz
Extract the downloaded file.
tar xvf phpMyAdmin-5.2.1-all-languages.tar.gz
Move the phpMyAdmin-5.2.1-all-languages
to /usr/share/
directory.
mv phpMyAdmin-5.2.1-all-languages /usr/share/phpmyadmin
Configuring phpMyAdmin
Create a sub-directroy with the following command.
mkdir -p /var/lib/phpmyadmin/tmp
Make the web server user www-data
as the owner of this directory.
chown -R www-data:www-data /var/lib/phpmyadmin
Make a copy to the file /usr/share/phpmyadmin/config.inc.php
cp /usr/share/phpmyadmin/config.sample.inc.php /usr/share/phpMyAdmin/config.inc.php
Install and use the pwgen program to generate a random string,
apt install pwgen
Edit the /usr/share/phpmyadmin/config.inc.php
file as follows using preferred text editor.
nano /usr/share/phpmyadmin/config.inc.php
Generate Random a Password,
pwgen -s 32 1
Enter a string of 32 random characters in between single quotes in config.inc.php
file.
root@vps:~# pwgen -s 32 1
4A4rw39Bz5Gys5SWRrKt2RNB7GcI3qKH
root@vps:~#
Note: Do not re-use "STRINGOFTHIRTYTWORANDOMCHARACTERS", use the random 32 character generated above instead.
Enter a string of 32 random characters in between single quotes.
$cfg['blowfish_secret'] = 'STRINGOFTHIRTYTWORANDOMCHARACTERS';
/* YOU MUST FILL IN THIS FOR COOKIE AUTH! */
Then uncomment this section of the /usr/share/phpmyadmin/config.inc.php
file will look like as follows:
/* Storage database and tables */
$cfg['Servers'][$i]['pmadb'] = 'phpmyadmin';
$cfg['Servers'][$i]['bookmarktable'] = 'pma__bookmark';
$cfg['Servers'][$i]['relation'] = 'pma__relation';
$cfg['Servers'][$i]['table_info'] = 'pma__table_info';
$cfg['Servers'][$i]['table_coords'] = 'pma__table_coords';
$cfg['Servers'][$i]['pdf_pages'] = 'pma__pdf_pages';
$cfg['Servers'][$i]['column_info'] = 'pma__column_info';
$cfg['Servers'][$i]['history'] = 'pma__history';
$cfg['Servers'][$i]['table_uiprefs'] = 'pma__table_uiprefs';
$cfg['Servers'][$i]['tracking'] = 'pma__tracking';
$cfg['Servers'][$i]['userconfig'] = 'pma__userconfig';
$cfg['Servers'][$i]['recent'] = 'pma__recent';
$cfg['Servers'][$i]['favorite'] = 'pma__favorite';
$cfg['Servers'][$i]['users'] = 'pma__users';
$cfg['Servers'][$i]['usergroups'] = 'pma__usergroups';
$cfg['Servers'][$i]['navigationhiding'] = 'pma__navigationhiding';
Add the following line to bottom of the file,
$cfg['TempDir'] = '/var/lib/phpmyadmin/tmp';
Finally, save & exit the file.
Create Apache Configuration for phpMyAdmin
Create a configuration file with the following command.
nano /etc/apache2/conf-available/phpmyadmin.conf
Paste the following text into the file.
# 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 file. Then enable this configuration.
a2enconf phpmyadmin.conf
Reload Apache for the changes to take effect.
systemctl reload apache2
Create a Database and User
This will be used for accessing the Database over the phpmyadmin panel.
For security reasons, we will create a user other than root
account and have limited accessability.
Enter the MariaDB CLI:
mariadb -u root -p
Create Database:
CREATE DATABASE myDatabase;
Create the user and grant it the appropriate permissions and Replace password
with your preferred password.
pma_user
is the username we created, but you can replace it with your preferred name.
GRANT SELECT, INSERT, UPDATE, DELETE ON myDatabase.* TO 'pma_user'@'localhost' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON myDatabase.* TO 'pma_user'@'localhost' IDENTIFIED BY 'password' WITH GRANT OPTION;
EXIT;
Open your browser's address bar to check if phpMyAdmin is installed: http://yourserver-ip-address/phpmyadmin/.
You should see a page similar to the screenshot shown below,
Login with the username and password that was created earlier.
This concludes the topic of installing phpMyadmin on a Debian 12 system.
CrownCloud - Get a SSD powered KVM VPS at $4.5/month!
Use the code WELCOME
for 10% off!
1 GB RAM / 25 GB SSD / 1 CPU Core / 1 TB Bandwidth per month
Available Locations: LAX | MIA | ATL | FRA | AMS