Install LEMP Stack (Nginx, MariaDB, PHP) on Ubuntu 22.04
The LEMP stack, which stands for Linux, Nginx internet server, MariaDB/MySQL database server, and PHP, is the easiest era stack to host traffic-intensive web pages and packages.
This LEMP stack is an alternative choice to the LAMP stack that makes use of Apache as a internet server as a substitute of Nginx.
In this submit, we can see how one can set up LEMP Stack on Ubuntu 22.04.
Install Linux
Follow the step by step information to put in Ubuntu 22.04 or improve Ubuntu 20.04 to Ubuntu 22.04.
Proceed to the set up of AMP (Nginx v1.18, PHP-FPM v8.1, MariaDB v10.6) on Ubuntu 22.04.
Install EMP Stack
Install Nginx
Nginx is an open-source internet server that gives HTTP, opposite proxy, caching, and load-balancing capability. It’s a perfect selection to Apache, and it’s easy to arrange.
From Ubuntu Repository
Nginx package deal is to be had at the Ubuntu repository. Installing Nginx from the Ubuntu repository is the very best approach. Use the apt
command to put in Nginx.
sudo apt replace sudo apt set up -y nginx
Nginx webserver’s default report root is /var/www/html/
and the configuration recordsdata are discovered below the /and so on/nginx/
listing.
By now, the Nginx internet server must be up and working. To take a look at the Nginx, open a internet browser and discuss with the beneath URL.
http://your-ip-add-ress
You gets a internet web page Welcome to nginx! that confirms the Nginx has been effectively put in and is up and working.
From Nginx Repository
First, set up the beneath applications for putting in the Nginx repository.
sudo apt replace sudo apt set up -y curl gnupg2 ca-certificates lsb-release
Then, Add the Nginx repository and signing key to the gadget.
curl -fsSL https://nginx.org/keys/nginx_signing.key | sudo gpg --dearmor -o /usr/percentage/keyrings/nginx-keyring.gpg echo "deb [arch=amd64 signed-by=/usr/share/keyrings/nginx-keyring.gpg] http://nginx.org/packages/ubuntu `lsb_release -cs` nginx" | sudo tee /and so on/apt/resources.checklist.d/nginx.checklist
Finally, set up the Nginx package deal the usage of the apt
command.
sudo apt replace sudo apt set up -y nginx
Nginx’s default report root is /usr/percentage/nginx/html
. The configuration recordsdata are discovered below the /and so on/nginx/
listing.
If required, get started the Nginx carrier after the set up.
sudo systemctl get started nginx
To take a look at the internet server, open a internet browser and discuss with the beneath URL.
http://your-ip-add-ress
You gets a internet web page Welcome to nginx! that confirms the Nginx has been effectively put in and is up and working.
Install MariaDB
MariaDB is a drop-in alternative for MySQL that helps all usual MySQL options. We will arrange MariaDB as a part of a LEMP stack in our set up.
Install the MariaDB server v10.6 from the Ubuntu repository.
sudo apt set up -y mariadb-server mariadb-client
MariaDB carrier must be up and working at this second. So, test the standing of the MariaDB carrier the usage of the beneath command.
sudo systemctl standing mariadb
Then, make the MariaDB server safe by means of working the mysql_secure_installation command.
Install PHP
The PHP FastCGI Process Manager (FPM) is a procedure supervisor to regulate FastCGI SAPI (Server API) in PHP. It is an alternate PHP FastCGI implementation and is useful for larger and busier websites. PHP-FPM can deal with extra requests in step with 2nd than different PHP FastCGI implementations.
Install php-fpm package deal and PHP MySQL extension.
sudo apt set up -y php-fpm php-mysql php-cli
If you may have put in Nginx from the reliable Nginx repository, you want to switch the possession and workforce of PHP Unix socket to nginx.
Depending at the PHP model, exchange the possession and workforce from www-data
to nginx
for Unix socket.
sudo sed -i 's/pay attention.proprietor = www-data/pay attention.proprietor = nginx/g' /and so on/php/8.1/fpm/pool.d/www.conf sudo sed -i 's/pay attention.workforce = www-data/pay attention.workforce = nginx/g' /and so on/php/8.1/fpm/pool.d/www.conf
Create Nginx Server Blocks
Now, create a digital host at the Nginx server for the next main points to check the LEMP stack.
Server Name: www.holhol24.native
Document Root : /usr/percentage/nginx/html/website online.holhol24.native OR /var/www/html/website online.holhol24.native
Create a digital host configuration record www.holhol24.native.conf
in /and so on/nginx/conf.d/
OR /and so on/nginx/sites-enabled/
listing.
Add the next server block to the above record. You might alter the server_name
and root
as in step with your requirement.
server { server_name holhol24.native www.holhol24.native; root /usr/percentage/nginx/html/www.holhol24.native; location / { index index.html index.htm index.php; } location ~ .php$ { come with /and so on/nginx/fastcgi_params; fastcgi_pass unix:/run/php/php8.1-fpm.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; } }
Then, create the report root listing for the server block.
sudo mkdir /usr/percentage/nginx/html/www.holhol24.native
Next, position a PHP record onto the report root to validate the processing of PHP.
echo "" | sudo tee /usr/percentage/nginx/html/www.holhol24.native/index.php
Finally, restart the Nginx and PHP-FPM services and products.
sudo systemctl restart nginx sudo systemctl restart php8.1-fpm
Test LEMP Stack
First, create a number access on your area (www.holhol24.native) within the /and so on/hosts
record to check the LEMP stack in the neighborhood. Then, open up your internet browser and kind your area title within the cope with bar.
http://www.holhol24.native
The web page will seem like the beneath:
As you’ll see within the screenshot, the PHP is operating via FPM/FastCGI (Server API).
Scroll down the web page to view the PHP strengthen for MySQL, XML, and different extensions.
Conclusion
I am hoping this submit helped you set up LEMP Stack on Ubuntu 22.04.