You want to install Apache2, PHP 8, MySQL / MariaDB and phpMyAdmin on your Debian 10, Debian 11, Ubuntu 20.04 or Ubuntu 22.04 server? This post walks you through it step by step.
Start by refreshing the package lists:
apt update
Then install every available update for the packages already on your server:
apt upgrade -y
Next, install the packages the later steps depend on:
apt install ca-certificates apt-transport-https lsb-release gnupg curl nano unzip -y
Now add the package source PHP 8 comes from. The two distributions differ here.
On Debian: add the key the PHP repository is signed with.
wget -q https://packages.sury.org/php/apt.gpg -O- | apt-key add -
Then add the repository itself:
echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" | tee /etc/apt/sources.list.d/php.list
On Ubuntu: install the package that manages additional sources first:
apt install software-properties-common -y
Then add the repository:
add-apt-repository ppa:ondrej/php
Whichever distribution you are on, refresh the package lists again so the new source is picked up:
apt update
Install the Apache2 web server:
apt install apache2 -y
Then PHP 8 together with the modules phpMyAdmin needs:
apt install php8.0 php8.0-cli php8.0-common php8.0-curl php8.0-gd php8.0-intl php8.0-mbstring php8.0-mysql php8.0-opcache php8.0-readline php8.0-xml php8.0-xsl php8.0-zip php8.0-bz2 libapache2-mod-php8.0 -y
Next comes the database. Install the MariaDB server and client:
apt install mariadb-server mariadb-client -y
Now secure the installation. When it asks for the current root password the first time, there is none yet — just press Enter. Confirm the prompt about changing the root password, then set one. Nothing appears on screen while you type it, which is normal and not an error. Confirm the remaining questions with Enter, and the MariaDB server is fully configured:
mysql_secure_installation
Change into the directory phpMyAdmin will live in:
cd /usr/share
Download the current release:
wget https://www.phpmyadmin.net/downloads/phpMyAdmin-latest-all-languages.zip -O phpmyadmin.zip
Unpack it:
unzip phpmyadmin.zip
Remove the archive, which you no longer need:
rm phpmyadmin.zip
Rename the extracted directory to something shorter:
mv phpMyAdmin-*-all-languages phpmyadmin
Give the directory the permissions it needs:
chmod -R 0755 phpmyadmin
Create an Apache2 configuration file for phpMyAdmin:
nano /etc/apache2/conf-available/phpmyadmin.conf
Put the following into that file:
# phpMyAdmin Apache configuration
Alias /phpmyadmin /usr/share/phpmyadmin
<Directory /usr/share/phpmyadmin>
Options SymLinksIfOwnerMatch
DirectoryIndex index.php
</Directory>
# Deny web access to directories that do not 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 with CTRL + X, then Y, then Enter.
Enable the configuration you just wrote:
a2enconf phpmyadmin
Reload Apache2 so it takes effect:
systemctl reload apache2
Create the temporary directory phpMyAdmin expects:
mkdir /usr/share/phpmyadmin/tmp/
And hand it to the web server user:
chown -R www-data:www-data /usr/share/phpmyadmin/tmp/
One thing to be aware of: for security reasons you can no longer log in to MariaDB as the root user with ordinary password authentication, which is what phpMyAdmin uses. You have two ways around that. Enabling it anyway works but is not advisable on a production system; creating a separate user with full privileges is the better option. Both are described below.
Option 1 — allow root to log in with a password (not advisable in production): connect to the MariaDB server with
mysql -u root
and run:
UPDATE mysql.user SET plugin = 'mysql_native_password' WHERE user = 'root' AND plugin = 'unix_socket';
followed by:
FLUSH PRIVILEGES;
This switches the root user's authentication plugin from the UNIX socket back to ordinary password authentication. Leave the console with the exit command.
Option 2 — create an additional user with full privileges (recommended): connect with
mysql -u root
and create the user:
CREATE USER 'username'@'localhost' IDENTIFIED BY 'password';
then grant it everything:
GRANT ALL PRIVILEGES ON *.* TO 'username'@'localhost' WITH GRANT OPTION;
Replace username and password with your own values. Leave the console with the exit command; from then on you can log in to MariaDB with that user, phpMyAdmin included.
Your Apache2 web server with PHP 8, MariaDB and phpMyAdmin is now ready to use. The web root sits at /var/www/html/ by default. To reach the phpMyAdmin interface, add /phpmyadmin to your server's IP address or domain in the browser, and log in with either the root user or the additional one, depending on which option you chose.
Frequently asked questions
Which Debian and Ubuntu versions does this guide cover?
Debian 10 and 11 as well as Ubuntu 20.04 and 22.04. The only step that differs between the two distributions is how the PHP 8 repository is added.
Why can I not log in to MariaDB as root through phpMyAdmin?
By default the root user authenticates through the UNIX socket rather than a password, and phpMyAdmin uses password authentication. Either switch the plugin over or, better, create a separate user with full privileges.
Where do my website files go?
Apache2 serves /var/www/html/ by default. phpMyAdmin lives in /usr/share/phpmyadmin and is reached by adding /phpmyadmin to your server's address.