Install Apache2, PHP 7.4, MariaDB (MySQL) and phpMyAdmin on Linux

  • Views Views: 591
  • Last updated Last updated:
  • INSTALL APACHE2, PHP 7.4, MARIADB (MYSQL) AND PHPMYADMIN ON LINUX

    1. If you have not already done so, download the "PuTTY" program.

    2. Use PuTTY to connect to your root or vServer via SSH. To do this, open PuTTY and enter the domain or IP address of your server in the "Host Name (or IP address)" text field. Then click OK at the bottom.

    3. Now update your package lists with the apt update command

    4. Install any available updates of the packages already installed on your server with the command apt upgrade -y

    5. Next, install the packages that are required for further installations with the following command: apt install ca-certificates apt-transport-https lsb-release gnupg curl nano unzip -y

    6. Add the package source needed to install PHP 7.4:
      For Debian:
      1. Using the command wget -q add https://packages.sury.org/php/apt.gpg -O- | apt-key add - the key required for the PHP package source.
      2. Use the command echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" | tee /etc/apt/sources.list.d/php.list to add the package source.

        For Ubuntu:
      3. Install the package to manage the package sources using the following command: apt install software-properties-common -y
      4. Use the command add-apt-repository ppa: ondrej/php to add the repository now.
    7. Now update your package lists again using the apt update command.

    8. Install the Apache2 web server and other required packages with the following command: apt install apache2 -y

    9. Then install PHP 7.4 as well as some important PHP modules. The command for this is: apt install php7.4 php7.4-cli php7.4-common php7.4-curl php7.4-gd php7.4-intl php7.4-json php7.4-mbstring php7.4-mysql php7.4-opcache php7.4-readline php7.4-xml php7.4-xsl php7.4-zip php7.4-bz2 libapache2-mod-php7.4 -y

    10. Next, install the MariaDB server and client (MySQL) using the apt install mariadb-server mariadb-client -y command.

    11. Now enter the command mysql_secure_installation to safely complete the configuration of the MariaDB server. The first time you are asked for the current password, you do not have to enter anything, just press the Enter key. Confirm the next question regarding changing the root password with Enter. Now you have to assign a password for the root user of the MariaDB server. No characters appear as you type, but this is normal. Confirm all the following questions (deleting the anonymous user, prohibiting the external root login for security reasons, removing the test database and updating the rights) with Enter. Then the MariaDB server is completely installed and configured.

    12. Change to the directory where phpMyAdmin will be installed with the command cd /usr/share

    13. To download phpMyAdmin, run the command wget https://www.phpmyadmin.net/downloads/phpMyAdmin-latest-all-languages.zip -O phpmyadmin.zip

    14. Unzip the archive you just downloaded with the following command: unzip phpmyadmin.zip

    15. Remove the downloaded archive, which is now already unzipped, with the command rm phpmyadmin.zip

    16. Then you have to rename the name of the extracted directory to "phpmyadmin". You do this with the following command: mv phpMyAdmin-*-all-languages phpmyadmin

    17. Then assign the required rights to the phpMyAdmin directory using the command chmod -R 0755 phpmyadmin

    18. Now create an Apache2 configuration file for phpMyAdmin by running the command nano /etc/apache2/conf-available/phpmyadmin.conf

    19. Now 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>


    20. Save your changes to the configuration by pressing CTRL + X, then the "Y" key and then press Enter.

    21. Activate the Apache2 configuration file you just added with the a2enconf phpmyadmin command and then run the systemctl reload apache2 command to reload the Apache2 web server.

    22. Create the temporary directory that phpMyAdmin needs by executing the command mkdir /usr/share/phpmyadmin/tmp/

    23. Now give the web server user the required owner rights for this temporary directory using the command chown -R www-data:www-data /usr/share/phpmyadmin/tmp/

    24. Note: For security reasons, you can no longer log into the MariaDB server directly as a root user using the normal password authentication (e.g. via phpMyAdmin). You can either enable this anyway (not recommended on production systems) or, alternatively, create another user with all rights (recommended) if you need this (e.g. for phpMyAdmin). You will find an explanation of these two options in the next two steps.

    25. Variant 1 - enable root login via password authentication (not recommended on productive systems): Log into PuTTY using the command mysql -u root on the MariaDB server and then run the commands UPDATE mysql.user SET plugin = 'mysql_native_password 'WHERE user =' root 'AND plugin =' unix_socket '; and FLUSH PRIVILEGES; the end. This changes the authentication plug-in of the root user from the UNIX socket back to standard authentication. Finally, exit the MariaDB console with the exit command.

    26. Variant 2 - Create additional user with all rights (recommended): Log into PuTTY using the command mysql -u root on the MariaDB server and then execute the commands CREATE USER 'username'@'localhost' IDENTIFIED BY 'password'; and GRANT ALL PRIVILEGES ON *.* TO 'username'@'localhost' WITH GRANT OPTION; the end. Replace "username" and "password" with your desired username and password. Finally, exit the MariaDB console with the exit command. You can then log in to the MariaDB server with the newly created user (e.g. via phpMyAdmin).

    27. Your Apache2 web server including PHP 7.4, MariaDB server and phpMyAdmin is now ready for use. By default, the web directory is located under "/var/www/html/". You can reach the phpMyAdmin web interface by adding "/phpmyadmin" to the IP address or domain of your server in the browser. There you can now log in to the MariaDB server - depending on which variant you selected after step 25, either with the user "root" or with your additionally created user.
  • Loading…