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.

Important: This tutorial is for Debian 9 (latest Debian version). However, if you still use Debian 8, you'll find the appropriate tutorial for Debian 8 here.

This tutorial was last checked and updated on January 27, 2019.

Are you looking for very good, powerful and cheap servers? I've been renting my servers at Contabo for 5 years now and I can highly recommend Contabo to everyone!
  1. If you havn't already done so, download the program "PuTTY".
  2. 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.
  3. Update your package lists with the command apt update.
  4. Now install any available updates of the packages already installed on your server using the command apt upgrade -y.
  5. 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 curl nano unzip -y
  6. Use the command wget -q https://packages.sury.org/php/apt.gpg -O- | apt-key add - to add the key needed for the PHP repository.
  7. Add the repository needed to install PHP 7.3 by executing the command echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" | tee /etc/apt/sources.list.d/php.list. PHP 7.3 is not yet available through the official repositories.
  8. Now update your package lists again with the command apt update.
  9. Install the Apache2 web server and other required packages with the following command: apt install apache2 -y
  10. Install PHP 7.3 and some important PHP modules. The command for this is: apt install php7.3 php7.3-cli php7.3-curl php7.3-gd php7.3-intl php7.3-json php7.3-mbstring php7.3-mysql php7.3-opcache php7.3-readline php7.3-xml php7.3-xsl php7.3-zip php7.3-bz2 libapache2-mod-php7.3 -y
  11. Now you need to install the MariaDB server and the client (replacement for MySQL since Debian 9) with the command apt install mariadb-server mariadb-client -y.
  12. 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.
  13. Restart the Apache2 server by executing the command systemctl restart apache2. Now both the Apache2 web server including PHP 7.3 and the MariaDB server are ready for use. By default, the web directory is "/var/www/html".
  14. Since the phpMyAdmin version, which can be installed using the packaging tool (apt) on Debian 9, is outdated and doesn't fully support PHP 7.3, the installation must be done manually. To do this, first visit the phpMyAdmin website, right-click on the top right download button and then copy the download link.
  15. Now open PuTTY again and go to the directory where phpMyAdmin will be installed using the command cd /usr/share.
  16. To download phpMyAdmin, enter the command "wget", followed by a space, and then right-click in the PuTTY window. By doing this, you paste the download link and the command should look like this: wget https://files.phpmyadmin.net/phpMyAdmin/4.8.5/phpMyAdmin-4.8.5-all-languages.zip. Now press enter to start the download.
  17. Then unzip the archive you just downloaded by executing the command "unzip", followed by a space and the archive name. For example, the command should look like this: unzip phpMyAdmin-4.8.5-all-languages.zip
  18. Remove the downloaded archive, which is already unzipped, with the command "rm" and a space as well as the archive name behind it (e.g. rm phpMyAdmin-4.8.5-all-languages.zip).
  19. Now you have to rename the directory to "phpmyadmin". Use the command mv phpMyAdmin-4.8.5-all-languages phpmyadmin. Again, make sure to use the correct archive name as it may be different from the example in this tutorial because of the changing version numbers.
  20. After that, assign the required permissions to the phpMyAdmin directory using the command chmod -R 0755 phpmyadmin.
  21. Now create an Apache2 configuration file for phpMyAdmin by executing the command nano /etc/apache2/conf-available/phpmyadmin.conf.
  22. 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

    # Disallow web access to directories that don't need it
    <Directory /usr/share/phpmyadmin/templates>
        Require all denied
    <Directory /usr/share/phpmyadmin/libraries>
        Require all denied
    <Directory /usr/share/phpmyadmin/setup/lib>
        Require all denied
  23. Save your changes to the configuration by pressing CTRL + X, then hit the "Y" key followed by enter.
  24. Activate the Apache2 configuration file you just added with the command a2enconf phpmyadmin and then execute the command systemctl reload apache2 to reload the Apache2 web server.
  25. Note: For security reasons, you can no longer log in directly to the MariaDB server as the user "root" using the normal password authentication (for example, via phpMyAdmin). You can either enable it (not recommended on production systems) or alternatively create another user with all permissions (recommended) if you need it (for example, for the use of phpMyAdmin). An explanation of these two methods can be found in the next two steps.
  26. Method 1 - Enabling root login via password authentication (not recommended on production systems): Log in to your MariaDB server using the command mysql -u root and then execute the commands UPDATE mysql.user SET plugin = 'mysql_native_password' WHERE user = 'root' AND plugin = 'unix_socket'; as well as FLUSH 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.
  27. Method 2 - Create an additional user with all permissions (recommended): Log in to your MariaDB server using the command mysql -u root and then execute the commands CREATE USER 'username'@'localhost' IDENTIFIED BY 'password'; as well as GRANT ALL PRIVILEGES ON *.* TO 'username'@'localhost' WITH GRANT OPTION;. Replace "username" and "password" with your desired username and password. Finally close the MariaDB console with the command exit. Then you can log in to the MariaDB server with the newly created user (e.g. via phpMyAdmin)
  28. Your Apache2 web server including PHP 7.3, the MariaDB server and phpMyAdmin is now ready to use. 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.