More

    How to install LEMP Stack on Ubuntu 20.04 with PhpMyAdmin

    For those of you who don’t know what LEMP is – a combination of software – Linux, Nginx (pronounced: EngineX), MariaDB and PHP.

    You can use LEMP both for testing purposes and in a real production environment to implement web applications with PHP frameworks such as Laravel or Yii or content management systems such as WordPress, Drupal or Joomla.

    You may wonder what the difference is between LAMP and LEMP. The only difference is that the web server contains Apache (in LAMP) and Nginx (in LEMP). Both web servers are pretty good, and although Apache is the most widely used, Nginx does not give up.

    Another widely used application that is usually installed in parallel with the LEMP stack is PhpMyAdmin, a PHP-based web tool to manage the MySQL/MariaDB database server from a web browser.

    If you are looking for the LAMP settings for Ubuntu 20.04, you should read our LAMP Configuration Guide for Ubuntu 20.04.

    Requirements:

    1. Ubuntu Server Installation Guide 20.04

    In this article you will learn how to install and configure the LEMP stack with PhpMyAdmin on the Ubuntu 20.04 server.

    Step 1: Installation of Nginx on Ubuntu 20.04

    1. Nginx is a fast and modern web server designed for a server with many simultaneous connections without consuming too many server resources. This is why it is often preferred in companies.

    NGINX is also often used as a load balancer and cache for web content. It supports name based and IP based virtual hosts (similar to Apache virtual hosts).

    You can install Nginx on your desktop or on the Ubuntu 20.04 server by executing the following command.

    update sudo apt
    $ install sudo apt nginx

    Installation of Nginx under Ubuntu 20.04

    Installation of Nginx under Ubuntu 20.04

    Nginx configuration files are stored in /etc/nginx, and the main configuration file is /etc/nginx/nginx.conf. It is important to note that by default, the document root directory where your web files are stored is /usr/share/nginx/html/. However, you can use the default /var/www/html file, which must be configured in the server block configuration file of your site or application.

    2. The Ubuntu package installer runs systemd to run the Nginx service and allows it to automatically run on any server reboot. Use the following system commands to confirm that the service is being performed and activated.

    $ sudo systemctl nginx$ sudo systemctl nginx included

    Check the status of the Nginx service

    Check the status of the Nginx service

    3. Now it’s time to check if the installation of Nginx was successful by opening the Nginx page in the browser under the IP address of the server.

    http://SERVER_IP

    If you do not know your server’s IP address, you can find it using the IP command as shown in the image.

    additive ip display

    The standard NGINX website must be loaded as shown in the following screenshot to confirm correct installation and operation.

    Configuring the Nginx test

    Configuring the Nginx test

    Step 2: MariaDB Database Installation on Ubuntu 20.04

    4. MariaDB is a relatively new relational database management system that was developed as a spin-off of the MySQL community after Oracle’s acquisition of the company.

    The installation of MariaDB is simple and can be started with the command:

    sudo apt mariad server install mariadb client

    Installing MariaDB on Ubuntu 20.04

    Installing MariaDB on Ubuntu 20.04

    5. The MariaDB service also works automatically and can always be started at system startup, which you can confirm with the following commands.

    sudo systemctl status mariadb
    $ sudo systemctl enabled mariadb

    Consult the MariaDB service

    Consult the MariaDB service

    6. If you want to improve the security of MariaDB, you can run the mysql_secure_installation command, which offers some basic but important configuration options:

    $ sudo mysql_safe_installation

    Then select the option to set the password for the root (or administrator) user of the database, follow the instructions and read the questions carefully. To back up the database server, answer the questions as shown in the screenshot.

    • Enter the current password of the main user (no entry) : Access.
    • Set the root password? Y/n
    • Delete anonymous users? Y/n
    • Denying remote access to the root? Y/n
    • Are you removing the test database and access to it? Y/n
    • Are you restarting the permission signs now? Y/n

    Secure MariaDB server

    Secure MariaDB server

    7. To create, manage and perform database operations, you must execute the mysql shell command with the -u flag to specify the database username and -p flag to specify the user password.

    To log in as root, use sudo (even without the -p flag), otherwise you get an error, which is highlighted in the following screenshot

    $ mysql -u root -p
    $ sudo mysql -u root

    MariaDB shell access

    MariaDB shell access

    Step 3: Installation of PHP in Ubuntu 20.04

    8. PHP is a popular open source language, a flexible and dynamic scripting language for creating websites and web applications. It supports different programming methods. It is important to note that the PHP community is large and diverse, consisting of numerous libraries, frameworks and other useful components.

    NGINX uses FPM (FastCGI Process Manager) or PHP-FPM to process PHP scripts. PHP-FPM is a widely used alternative to PHP FastCGI, which is equipped with many additional features and is used to run a busy website/web application.

    To install PHP and PHP-FPM, run the following command, which will also install some additional required packages.

    $ sudo apt installation php-fpm

    Install PHP and PHP-FPM under Ubuntu 20.04.

    Install PHP and PHP-FPM under Ubuntu 20.04.

    Since PHP 7.4 is the default version of PHP in Ubuntu 20.04, the PHP configuration files are in /etc/php/7.4/ and the PHP-FPM configuration files are in /etc/php/7.4/fpm.

    9. Then check if the php7.4-fpm service works and if it is activated by the following command.

    $ sudo systemctl enabled php7.4-fpm
    $ sudo systemctl enabled php7.4-fpm

    Check the status of PHP-FPM

    Check the status of PHP-FPM

    Step 4: Configuring Nginx to work with PHP-FPM

    10. You must now configure NGINX for proxy client requests to PHP-FPM, which is configured by default to listen on UNIX sockets, as set by the listen setting in the default pool configuration file /etc/php/7.4/fpm/pool.d/www.conf

    $ ship vi /etc/php/7.4/fpm/pool.d/www.conf

    PHP-FPM bus configuration

    PHP-FPM bus configuration

    11. In the configuration file for the default server block (/etc/nginx/sites-available/default), you recommend the location guideline for processing PHP requests so that it looks like the following screenshot

    $ ship vi /etc/nginx/sites-available/default

    Configuring the Nginx block to use the PHP-FPM connector

    Configuring the Nginx block to use the PHP-FPM connector

    Save the file and close it.

    12. Then check the NGINX configuration syntax to make sure it is correct. If all goes well, restart the Nginx service to apply the new changes.

    sudo nginx -t
    sudo systemctl reboot nginx

    Check Nginx configuration

    Check Nginx configuration

    13. Now check if NGINX can work in combination with PHP-FPM to process PHP requests. Create a simple info.php page under the main directory of the document.

    $ echo | sudo tee /var/www/html/info.php

    14. Use the navigation in your browser at the following address. The PHP configuration page should be loaded as shown in the following screenshot

    http://SERVER_IP/info.php

    Read about PHP and PHP-FPM.

    Read about PHP and PHP-FPM.

    Step 5: Installation of PhpMyAdmin in Ubuntu 20.04

    15. PhpMyAdmin is a free and open source PHP application designed specifically to manage MySQL/MariaDB database servers from a web browser. It provides an intuitive graphical user interface and supports a variety of common functions for database management tasks.

    $ sudo apt installation phpmyadmin

    Install PhpMyAdmin in Ubuntu 20.04

    Install PhpMyAdmin in Ubuntu 20.04

    16. When installing the package, you will be asked to configure various aspects of the PhpMyAdmin package. First you will be asked to select the default web server on which it should run. Press Esc because NGINX is not listed.

    Select the web server to configure PHPMyAdmin

    Select the web server to configure PHPMyAdmin

    17. Then PhpMyAdmin needs a database to work. In this package configuration tip, select Yes to configure the database for PhpMyAdmin with the dbconfig-common package.

    Database configuration for PhpMyAdmin

    Database configuration for PhpMyAdmin

    18. In the following note, you must enter the PhpMyAdmin password to register in the MariaDB database. Type a secure password and press the Enter key.

    Create a password for PhpMyAdmin

    Create a password for PhpMyAdmin

    Step 6: Implementation of NGINX for managing the websitePhpMyAdmin

    19. To enable NGINX to manage the PhpMyAdmin website under /usr/share/phpmyadmin, create a SIM link for this directory under the document root and then set the appropriate rights and properties for the PHPMyAdmin directory as follows

    ship ln -s /usr/share/phpmyadmin /var/www/html/phpmyadmin
    $ ship chmod 775 -R /usr/share/phpmyadmin/
    $ ship chown root:www-data -R /usr/share/phpmyadmin/

    20. In addition, make sure that the index directive in the default server block configuration file (/etc/nginx/sites-available/default) contains the index.php file, as shown in the following screenshot

    Definition of the Nginx index policy

    Definition of the Nginx index policy

    21. Then restart the Nginx service to apply the above changes.

    $ sudo systemctl restart nginx

    22. Now go to the PhpMyAdmin website via your browser at the following address

    http://SERVER_IP/phpmyadmin.

    Log in to the login page with the PHPMyAdmin username and password. Remember that root access for the remote user is disabled, unless you have access to PHPMyAdmin on the local host where the MariaDB database is installed, then root access will not work.

    PhpMyAdmin connection

    PhpMyAdmin connection

    PhpMyAdmin Dashboard

    PhpMyAdmin Dashboard

    Finally, make sure you install PhpMyAdmin using our manual: 4 Useful tips for securing the PhpMyAdmin web interface.

    Conclusion

    Your LEMP installation is complete and you can start building your web applications or just play around with the Nginx and MariaDB services you have just installed. They are widely used and highly recommended for system administrators.

    Recent Articles

    Arch Linux Based Distribution from A Beginner

      If you’re in search of an Arch-based newbie’s Linux distribution and simpler to make use of and set up, gives all attainable desktop environments...

    Zerologon: How Bitdefender protects consumers from this Post-Exploit No-Credential Technique

      Zerologon is a zero-credential vulnerability that exploits Home windows Netlogon to permit adversaries entry to the Lively Listing area controllers, first reported in August...

    Hackers gather intelligence on potential opponents of the regime in Iran

      Iranian Group Discovered Spying on Dissidents An Iran linked group, named Rampant Kitten by researchers, has been found focusing on anti-regime organizations in a marketing...

    NCSC warns of a surge in ransomware attacks on educational institutionsSecurity Affairs

      The U.Ok. Nationwide Cyber Safety Centre (NCSC) has issued an alert a couple of surge in ransomware assaults focusing on schooling establishments. The U.Ok. Nationwide...

    Helheim Hassle is a seriously funny adventure puzzle-platforming mix

      What may take the crown for the funniest Linux sport this yr, Helheim Trouble launched earlier in August and it is a real delight...

    Related Stories