How to Install LEMP Stack on Ubuntu 20.04
The LEMP stack is one of the most popular kits as the basis for a web site. It consists of a Linux server, Nginx web server, MySQL database management systems and PHP. We're going to take a look at the process of installing a LEMP stack in Ubuntu 20.04. All commands must be run as root or add sudo before them.
In the Serverspace you can create a server with already installed app "LEMP".
Installing Nginx
First, let's update the package manager cache and install Nginx.
apt install nginx
If the firewall is enabled, you need to allow access to the server on port 80:
Output:
Rules updated (v6)
You can now check if the Nginx web server is running by entering your server's public IP address into your browser's address bar. You will see the following page:
Installing MySQL
To install MySQL server enter:
Once installed, run the script and follow the instructions to configure the recommended MySQL security settings. The most secure setting will be achieved with affirmative answers and the strictest password complexity check.
Installing PHP
Install the following packages to get PHP running on the server.
Configuring Nginx for PHP Processing
In this tutorial, we'll show you how to configure PHP processing using the default virtual host as an example. When configuring Nginx to work with multiple domain names, this setting will also apply. Nginx virtual host basic configuration guide.
Open the default virtual host configuration file.
Add the next code to the end of the server section:
location ~ .php$ { include snippets/fastcgi-php.conf; fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
Save and close the file and check the configuration for errors:
Restart Nginx:
Testing PHP on Nginx Server
We will now create a .php file on our server and check if PHP is running. Create a file:
Paste the following content here:
Now enter your server's public IP address into your browser's address bar with /info.php at the end:
If you see the following content, PHP works fine with Nginx.