Knowledgebase

MySQL | Install Apache2, PHP8, MySQL (MariaDB), and PHPMyAdmin on Ubuntu 22.04 / Ubuntu 20.04

Do you want to install Apache2, PHP8, MySQL (or MariaDB) and PHPMyAdmin (LAMP) on your Ubuntu 22.04 / Ubuntu 20.04 operating system? Then you are in the right place!

It is important that you first update the package list of your Ubuntu operating system and install possible updates. You can do this with a simple command:

apt update && apt upgrade -y

 

After the package list and the packages have been successfully updated, you still need to install the necessary packages for LAMP, as well as add the PHP package list to be able to install PHP8 later. We will also install Apache2 at the same time to save time in the process. You can do this with the following command:

 

apt-get install nano curl unzip ca-certificates apt-transport-https lsb-release gnupg apache2 -y && apt install software-properties-common -y && add-apt-repository ppa:ondrej/php

 

After you have added the additional packages and the PHP8 package list, you must now update your package list again to be able to successfully install PHP8.

apt-get update && apt-get install php8.1 php8.1-cli php8.1-common php8.1-curl php8.1-gd php8.1-intl php8.1-mbstring php8.1-mysql php8.1-opcache php8.1-readline php8.1-xml php8.1-xsl php8.1-zip php8.1-bz2 libapache2-mod-php8.1 -y

 

Afterwards, MySQL (or MariaDB) will be installed on the server and the setup will be carried out. Please make sure that you use a secure MySQL password during setup. After entering your desired MySQL password, you can freely decide whether to accept (y) or reject (n) the further steps.

apt install mariadb-server mariadb-client -y && mysql_secure_installation

#Then answer the queries simply with "y" (as well as set the root-MySQL password).

Additional information on "mysql_secure_installation": The first query asks whether you would like to create a password for the root (MySQL) user, confirm this accordingly with "y" and enter your desired MySQL password for the root user (the normal root MySQL user will however run restricted, therefore a further account with "root" permission or with full "Grant-All" permission will be created in the further course). The next queries can all be confirmed with "y", as only the deletion of the anonymous user, prohibiting the external root login (for security reasons), removing the test database, as well as updating the rights will be asked.

 

After successfully completing the MySQL setup process, you can now install and set up PHPMyAdmin:

cd /usr/share && wget https://www.phpmyadmin.net/downloads/phpMyAdmin-latest-all-languages.zip -O phpmyadmin.zip && unzip phpmyadmin.zip && rm phpmyadmin.zip && mv phpMyAdmin-*-all-languages phpmyadmin && chmod -R 0755 phpmyadmin

 

Once you have successfully completed the installation and setup of PHPMyAdmin, you only need to create an Apache2 configuration file for PHPMyAdmin to link your PHPMyAdmin with Apache2:

nano /etc/apache2/conf-available/phpmyadmin.conf

The content for phpmyadmin.conf:

#PHPMyAdmin-Apache2-Konfiguration

Alias /phpmyadmin /usr/share/phpmyadmin

<Directory /usr/share/phpmyadmin>
    Options SymLinksIfOwnerMatch
    DirectoryIndex index.php
</Directory>

<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>

 

After you have successfully created the phpmyadmin.conf, you only need to activate the configuration file and reload Apache2. Afterwards, create a temporary directory for PHPMyAdmin and grant the necessary permission:

a2enconf phpmyadmin && systemctl reload apache2 && mkdir /usr/share/phpmyadmin/tmp/ && chown -R www-data:www-data /usr/share/phpmyadmin/tmp/

 

Now you can successfully log into the MySQL console with the following command:

mysql -u root

 

As the last step, you just need to create a MySQL account (it would be important not to change "root", but to create a different username and a strong and secure password to have maximum security). Change "USER" and "PASSWORD" in the following commands:

#IMPORTANT! CHANGE USER AND PASSWORD TO YOUR DESIRED MYSQL ACCESS DATA AND DO NOT USE "root", "username", "user" OR "admin" AS USERNAME!


CREATE USER 'USER'@'localhost' IDENTIFIED BY 'PASSWORD';

GRANT ALL PRIVILEGES ON *.* TO 'USER'@'localhost' WITH GRANT OPTION;

 

Then you can call up and use your PHPMyAdmin without problems under http://<Your-Server-IP>/phpmyadmin

 

You can also exit the MySQL console at any time with the following command:

exit

 


 

Do you have a vServer / root server and would like to have more performance? Then a look at our range of root servers couldn't hurt!

With the discount code "KernelHost-Tutorials" you also receive a 10% discount (permanent) on your tariff!

More details:

Hardware: https://www.kernelhost.com/en/hardware

Datacenter: https://www.kernelhost.com/en/datacenter

DDoS-Protection: https://www.kernelhost.com/en/ddos-protection

PrePaid: https://www.kernelhost.com/en/prepaid

Didn't the instructions help you? You can contact us here via ticket! We're here to help.

 

© KernelHost.com - Re-posting these instructions on your website is not permitted.

  • MySQL, Ubuntu, Ubuntu-20.10, Ubuntu-20.04, Ubuntu-21.04, PHP8, PHPMyAdmin, PHP, Apache2, MariaDB
  • 151 Users Found This Useful

Was this answer helpful?

Related Articles

Java-17 auf Ubuntu-22.04 / 20.04 installieren

Sie möchten gerne Java-17 auf Ihrem Ubuntu 22.04 / 20.04 Betriebssystem installieren? Dann sind...

Java-8 / Java-11 auf Ubuntu 22.04 / Ubuntu 20.04 installieren

Sie möchten gerne Java-8 oder Java-11 auf Ihrem Ubuntu 22.04 / Ubuntu 20.04 Betriebssystem...

Backup MySQL databases daily on Ubuntu

You own an Ubuntu OS at your VPS / VDS / dedicated server and want to automatically daily secure...