phpMyAdmin is a free web application for administering MySQL databases and their fork MariaDB. The software is implemented in PHP; this is where the name phpMyAdmin comes from.
This tutorial shows how to install phpMyAdmin on Debian 12 with Apache2 and PHP8. For administration and management of MySQL and MariaDB databases from web browsers.
On Debian 11, the easiest way to install phpMyAdmin is via the Package Manager, withapt install phpmyadminbut this is no longer up-to-date since php 8 is provided.
Since Debian 11 installs from the default repository, phpMyAdmin is provided for PHP 7.4, but if requires a newer PHP version, i.e. for current CMS such as WordPress, where PHP 8 or newer is recommended, phpMyAdmin can be installed manually in just a few steps.
INSTALLATION
The phpMyAdmin installation on Debian is done here as root by using “su -“, for the packages Apache2, MariaDB and PHP 8.2 provided by DEB.SURY.ORG.
First of all, required service packages are installed.
The next step is to install the MariaDB server and (MySQL) client.
$ apt install mariadb-server mariadb-client -y
Then complete the configuration of the MariaDB server.
$ mysql_secure_installation
Since the root password for the database is not yet set, press Enter to skip the initial query. Complete the following queries:
Switch to unix_socket authentication [Y/n] – Enter n to skip.
Set root password? [Y/n] – Type y and press Enter to create a root password for your database. If you already have a root password, enter n to not change the root password.
Remove anonymous users? [Y/n] – Type y and press Enter.
Disallow root login remotely? [Y/n] – Type y and press Enter.
Remove test database and access to it? [Y/n] – Type y and confirm with Enter.
Reload privilege tables now? [Y/n] – Type y and confirm with Enter.
MariaDB is now operational.
Install phpMyAdmin on Debian
First change the directory into install phpMyAdmin on Debian.
$ cd /usr/share
To download phpMyAdmin run the command as follows.
Up to and including Debian 10 and Ubuntu, password authentication to the MariaDB server is not possible by default for root login (e.g. via phpMyAdmin) for security reasons. On Debian 11, however, this is possible. For Debian 10, the following steps can be performed to allow root login using a password as well.
$ mysql -u root
UPDATE mysql.user SET plugin = 'mysql_native_password' WHERE user = 'root' AND plugin = 'unix_socket';
FLUSH PRIVILEGES;
Quit
The Apache2 web server with PHP 8, the MariaDB server and phpMyAdmin is now ready to use.
The phpMyAdmin website can be reached by adding /phpmyadmin to the IP address or FQDN in the browser URL. for example: http://192.168.1.2/phpmyadmin
View and change PHP version
If several PHP versions are installed on the system, an installed PHP version can be activated for the Apache2 web server.
The corresponding module is activated with the Apache helper, with the command a2enmod, and deactivated with a2dismod.
The current PHP version and modules are displayed by creating a php file with the following content. If no other Apache2 site is available, this can be saved as phpinfo.php in the docroot at /usr/share/phpmyadmin.
<?php
phpinfo();
?>
The PHP settings for the Apache2 web server are displayed in tabular form in the web browser. i.e. http://192.168.1.2/phpinfo.php
For productive systems, phpinfo should be removed again.
You might also be interested in the related post here.
This tutorial shows how to install Apache, MariaDB and PHP, call LAMP stack with configuration on a Debian 11 (buster) as a web server complete with Apache/2.4, MariaDB 10, PHP 7.4 and vsftpd as well as Fail2ban and all necessary packages. The estimated time required for the installation is around 10 minutes, at the end of which a web server is ready to use for content management systems. Newly created users for FTP access are automatically chrooted to their own DocumentRoot.
Install Apache MariaDB PHP on Debian Server
We are logged in as root on a Debian 10, first, as always, we have all updates carried out.
apt update
First, required packages are provided as a prerequisite for further installation.
apt install ca-certificates apt-transport-https lsb-release gnupg curl vim unzip -y
The Debian repository does not contain the latest PHP versions, so we use the Sury repository.
Now let’s run the script to complete the configuration of the MariaDB server.
mysql_secure_installation
When you first ask for the current password, you do not have to enter anything, but simply press the Enter key. Confirm the next question regarding changing the root password with Enter. Now a password is assigned for the root user of the MariaDB server (not Linux root). No characters appear as you type, which is normal. Confirm all of the following questions (deletion of the anonymous user, banning the external root login for security reasons, removing the test database and updating the rights) also with Enter. After that, the MariaDB server is fully installed and configured.
Install phpMyAdmin on Debian with MariaDB
Now able to manage the MariaDB databases on the Debian Server, we install by the command cd /usr/share to change the directory path where phpMyAdmin we would install.
For security reasons, password authentication to the MariaDB server is no longer recommended to log in directly as a root user (i.e. via phpMyAdmin).
Create an additional user with all rights, to do this, we log on to the MariaDB server using the MySQL-Client.
mysql -u root
if everything went well, you are now in the MySQL (MariaDB) prompt.
MariaDB [(none)] >
And then hit the following SQL commands to create the MariaDB user and grant the rights.
CREATE USER 'username'@'localhost' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON *.* TO 'username'@'localhost' WITH GRANT OPTION;
FLUSH PRIVILEGES;
Replace “username” and “password“with the desired username and password. Finally type exit to leave the MariaDB console.
MariaDB [(none)] > exit
Now you can log in to the MariaDB server with the newly created user (i.e. also via phpMyAdmin).
http://192.168.2.12/phpmyadmin
Enough – your Apache2 web server incl. PHP 7.4, MariaDB server and phpMyAdmin is now ready to use. The phpMyAdmin WebUI can be reached by add /phpmyadmin to the IP address or FQDN in the browser.
Note. you’ll see the following error message at the bottom of the phpmyadmin page when you first log in to /phpmyadmin.
The configuration file now needs a secret passphrase (blowfish_secret).
You need to add a blowfish password to the phpMyAdmin’s config file. Edit config.inc.php and insert a random blowfish passphrase in the line $cfg['blowfish_secret']here as an example:
vi /usr/share/phpmyadmin/config.inc.php
$cfg['blowfish_secret'] = 'ttTo4Zhy6zEOdUatH6vcOQFbXpnnM/WmOZpO1bM9BH2R7i4WZJVpdBntcsvSDVlM'; /* YOU MUST FILL IN THIS FOR COOKIE AUTH! */
Note. if you use vim for editing, you will notice that after entering the insert mode and paste text by press the right mouse key the blockwise Visual mode is turned on — (insert) VISUAL — that behaves undesirably, but this can be quickly solved by disabling the mouse control for vim, let’s do that right away and run echo "set mouse-=a" > ~/.vimrc
Hint. generating a passphrase is easy as the following command shows.
openssl rand -base64 48
ttTo4Zhy6zEOdUatH6vcOQFbXpnnM/WmOZpO1bM9BH2R7i4WZJVpdBntcsvSDVlM
# or another 48 characters long
date +%s | sha256sum | base64 | head -c 48 ; echo
MjhhMGUwMjYyYjljNWI2MjFiMGZmNmQ5MjdiYjY2MGE2YWNl
Securing and hardening Debian web server
First, the kernel firewall is configured for the web server, only the required services should be allowed incoming. With Debian, the ufw (Uncomplicated Firewall) is enabled by default after installation. The ports required for the web server are opened as follows.
Note: after each change, reload the firewall for the changes to take effect.
firewall-cmd --reload
Install FTP server with vsftpd on Debian
vsftpd is an FTP server for the old File Transfer Protocol. As an acronym, its name stands for Very Secure File Transfer Protocol Daemon. Whether OpenSSH with sftp is standard on every Linux and FreeBSD, but unfortunately FTP is still widely used.
The vsftpd daemon is installed as follows.
apt install vsftpd -y
Edit the vsftpd configuration file for changes.
vi /etc/vsftpd.conf
We disable anonymous login and allow local users to write.
chroot stands for change root and is a function for Unixoid systems to change the root directory. chroot only affects the current process and its child processes, it is a simple jail mechanism in which the FTP utility prevents users from accessing files outside its directory. chroot also provides an easy way to sandbox untrusted data. The chroot settings for VSFTPD users can be found in the file vsftpd.conf at line chroot_local_user and change there to YES, so also with chroot_list_enable.
chroot_local_user=YES
chroot_list_enable=YES
All users are assigned chroot, except for some that are exempt, for this the file /etc/vsftpd.chroot_list is created, which contains users who are excluded from chroot.
Create a vsftpd.userlist file and add users to be denied. The service accounts should be rejected, as they are often used for attacks. Add one user per row, example: vsftpd.userlist
Root
am
Daemon
sys
Sync
one
backup
Admin
sshd
Lp
Sync
proxy
stratagem
Irc
Shutdown
stop
email
news
Uucp
operator
games
nobody
postfix
www-data
Ftp
mysql
Start the vsftpd daemon.
systemctl start vsftpd
fail2ban hardens your web servers
Now it’s a good opportunity to protect your Debian with MariaDB and Apache web server with install fail2ban.
fail2ban is written in Python aims to protect server services against DoS attacks. It checks log files according to predefined patterns and temporarily blocks the corresponding IP addresses in the event of repeated failed access.
fail2ban is installed and configured on Debian as follows.
apt install fail2ban -y
The configuration of fail2ban for a web server with jail filter for watch access to the SSH and FTP service to bann brute-force attacks.
After the configuration file jail.conf has been copied, the file jail.local can be loaded into the editor, all settings here override the value in jail.conf.
vi /etc/fail2ban/jail.local
Settings can be adjusted here and filters for services can be activated or deactivated. The DEFAULT allows a global definition of the options. The options can then be overridden in any jail.
bantime defines the duration of the blocking, here 12 hours (specified in seconds).
findtime defines the duration in which failed attempts can take place, here 10 minutes.
maxretry indicates the number of attempts.
By default, fail2ban is only activated with the SSH filter, further filters are activated with enabled = true.
[sshd]
enabled = true
# To use more aggressive sshd modes set filter parameter "mode" in jail.local:
# normal (default), ddos, extra or aggressive (combines all).
# See "tests/files/logs/sshd" or "filter.d/sshd.conf" for usage example and details.
#mode = normal
port = ssh
logpath = %(sshd_log)s
backend = %(sshd_backend)s
[vsftpd]
enabled = true
# or overwrite it in jails.local to be
# logpath = %(syslog_authpriv)s
# if you want to rely on PAM failed login attempts
# vsftpd's failregex should match both of those formats
port = ftp,ftp-data,ftps,ftps-data
logpath = %(vsftpd_log)s
Fail2ban Jail Filter query status, and verbose output for SSH.
fail2ban-client status
fail2ban-client -vvv status sshd
Note. Since fail2ban 0.10 (IPv6 support) fail2ban executes actionstart IP-family related on demand by first ban per jail, so iptables-multiport would create the chain f2b-sshd only if first IP gets banned in sshd jail.
important tools for the web server as virtual machine
Use the first argument for the domain name and the second for the user name to be created.
Note. do not forget give a secret passwd [username]
After running the script you’ll find a new docroot under /var/www as well as the associated apache virtual host configuration under /etc/apache2/sites-available this is already ebabled.
For HTTPS websites, Certbot can be integrated for Let’s Encrypt SSL certificates, the how to find in this Article.
Conclusion
It is therefore possible to build a complete web server with all the necessary services in a short time without using graphical user interfaces or other tools for setup and administration.