Hint: You can use the Tab key to autocomplete all filenames and directories, so you don't have to type in the complete file or directory name manually.
Note: This tutorial explains how to install PHP 8, but if you still want to install and use the previous version PHP 7.4, you can find the appropriate tutorial here.
This tutorial was last checked and updated on April 3, 2023.
- If you havn't already done so, download the program "PuTTY".
- Connect to your root server or VPS/vServer via SSH using PuTTY. To do this, open PuTTY and enter the domain or IP address of your server in the text box named "Host Name (or IP address)". Then click the "OK" button below.
- Update your package lists with the command
apt update
. - Now install any available updates of the packages already installed on your server using the command
apt upgrade -y
. - Next, install the packages needed for future installations in this tutorial by executing the following command:
apt install ca-certificates apt-transport-https lsb-release gnupg curl nano unzip -y
- Add the repository needed to install PHP 8:
For Debian:- Use the command
curl -fsSL https://packages.sury.org/php/apt.gpg -o /usr/share/keyrings/php-archive-keyring.gpg
to add the key needed for the PHP repository. - Add the repository by executing the command
echo "deb [signed-by=/usr/share/keyrings/php-archive-keyring.gpg] https://packages.sury.org/php/ $(lsb_release -sc) main" > /etc/apt/sources.list.d/php.list
.
- Install the package for managing repositories using the following command:
apt install software-properties-common -y
- Add the repository by executing the command
add-apt-repository ppa:ondrej/php
and pressing enter.
- Use the command
- Now update your package lists again with the command
apt update
. - Install the Apache2 web server and other required packages with the following command:
apt install apache2 -y
- Install PHP 8 and some important PHP modules. The command for this is:
apt install php8.2 php8.2-cli php8.2-common php8.2-curl php8.2-gd php8.2-intl php8.2-mbstring php8.2-mysql php8.2-opcache php8.2-readline php8.2-xml php8.2-xsl php8.2-zip php8.2-bz2 libapache2-mod-php8.2 -y
- Now you need to install the MariaDB server and the client (MySQL) with the command
apt install mariadb-server mariadb-client -y
. - Then complete the configuration of the MariaDB server:
For up to Debian 10 or for Ubuntu:- Now enter the command
mysql_secure_installation
to complete the configuration of your MariaDB server. At the first question regarding the current password, you don't have to type in anything, just press enter. Confirm the next question concerning the change of the root password with enter as well. Now you have to set a password for the MariaDB root user. There are no characters displayed during input, but this is normal. Confirm all further questions (deleting the anonymous user, disabling the external root login for security reasons, removing the test database and updating the privileges/permissions) also with enter. Then the MariaDB server is completely installed and configured.
- Now enter the command
mysql_secure_installation
to complete the configuration of your MariaDB server. At the first question regarding the current password, you don't have to type in anything, just press enter. At the following question regarding switching to Unix socket authentication, type "n" and press Enter. Confirm the next question concerning the change of the root password with enter as well. Now you have to set a password for the MariaDB root user. There are no characters displayed during input, but this is normal. Confirm all further questions (deleting the anonymous user, disabling the external root login for security reasons, removing the test database and updating the privileges/permissions) also with enter. Then the MariaDB server is completely installed and configured.
- Now enter the command
- Go to the directory where phpMyAdmin will be installed using the command
cd /usr/share
. - To download phpMyAdmin, execute the command
wget https://www.phpmyadmin.net/downloads/phpMyAdmin-latest-all-languages.zip -O phpmyadmin.zip
. - Then unzip the archive you just downloaded by executing this command:
unzip phpmyadmin.zip
- Remove the downloaded archive, which is already unzipped, with the command
rm phpmyadmin.zip
. - Now you have to rename the directory to "phpmyadmin". Use this command:
mv phpMyAdmin-*-all-languages phpmyadmin
- After that, assign the required permissions to the phpMyAdmin directory using the command
chmod -R 0755 phpmyadmin
. - Now create an Apache2 configuration file for phpMyAdmin by executing the command
nano /etc/apache2/conf-available/phpmyadmin.conf
. - Add the following content to this configuration file:
# phpMyAdmin Apache configuration
Alias /phpmyadmin /usr/share/phpmyadmin
<Directory /usr/share/phpmyadmin>
Options SymLinksIfOwnerMatch
DirectoryIndex index.php
</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 your changes to the configuration by pressing CTRL + X, then hit the "Y" key followed by enter.
- Activate the Apache2 configuration file you just added with the command
a2enconf phpmyadmin
and then execute the commandsystemctl reload apache2
to reload the Apache2 web server. - Create the temporary directory that phpMyAdmin needs by running the command
mkdir /usr/share/phpmyadmin/tmp/
. - Now assign the required owner permissions for this temporary directory to the web server user with the command
chown -R www-data:www-data /usr/share/phpmyadmin/tmp/
. - Note: Up to Debian 10 as well as under Ubuntu, you can't log in to the MariaDB server as the root user (for example, via phpMyAdmin) using the password authentication for security reasons by default. However, this is possible under Debian 11. If you don't use Debian 11, perform the following steps to allow root login using password.
- For up to Debian 10 or for Ubuntu:
- Log in to your MariaDB server using the command
mysql -u root
. - Execute the commands
UPDATE mysql.user SET plugin = 'mysql_native_password' WHERE user = 'root' AND plugin = 'unix_socket';
as well asFLUSH PRIVILEGES;
. This will change the authentication plugin of the root user from the UNIX socket back to standard authentication. - Finally leave the MariaDB console with the command
exit
.
- Log in to your MariaDB server using the command
- Your Apache2 web server including PHP 8, the MariaDB server and phpMyAdmin is now ready to use. By default, the web directory is "/var/www/html/". You can access the phpMyAdmin web interface in your web browser by appending "/phpmyadmin" to the IP address or domain of your server. There you can log in to the MariaDB server - depending on which variant you chose after step 25, either with the user "root" or with your additionally created user.