Idroot Us Install Lemp Stack Ubuntu 22 04
Idroot Us Install Lemp Stack Ubuntu 22 04
04 LTS
TUTORIALS, UBUNTU, UBUNTU BASED • MAY 13, 2022 08:59
In this tutorial, we will show you how to install LEMP Stack on Ubuntu 22.04 LTS. For those of you who didn’t
know, LEMP Stack is a combination of free, open-source software. The acronym LEMP refers to the first letters of
Linux (Operating system), Nginx Server, MariaDB (database software), and PHP components to build a viable
general-purpose web server.
This article assumes you have at least basic knowledge of Linux, know how to use the shell, and most
importantly, you host your site on your own VPS. The installation is quite simple and assumes you are running in
the root account, if not you may need to add ‘sudo‘ to the commands to get root privileges. I will show you the
step-by-step installation of the LEMP Stack on Ubuntu 22.04 (Jammy Jellyfish). You can follow the same
instructions for Ubuntu 22.04 and any other Debian-based distribution like Linux Mint, Elementary OS, Pop!_OS,
and more as well.
Prerequisites
A server running one of the following operating systems: Ubuntu 22.04, 20.04, and any other Debian-based
distribution like Linux Mint.
It’s recommended that you use a fresh OS install to prevent any potential issues.
SSH access to the server (or just open Terminal if you’re on a desktop).
A non-root sudo useror access to the root user. We recommend acting as a non-root sudo
user, however, as you can harm your system if you’re not careful when acting as the root.
Convert web pages and HTML files to PDF in your applications with the Pdfcrowd HTML to PDF API Printed with Pdfcrowd.com
sudo apt install lsb-release ca-certificates apt-transport-https software-
properties-common
By default, the Nginx is available on Ubuntu 22.04 base repository. Now run the following command below
to install the latest version of Nginx to your Ubuntu system:
After successfully installation, enable Nginx (to start automatically upon system boot), start, and verify the
status using the commands below:
Confirm the installation and check the installed build version of Nginx:
nginx -v
Ubuntu 22.04 has ufw a firewall running by default. Enable connection through ports 80 HTTP and 443
HTTPS:
Once successfully installed, open a web browser on your system and type the server’s IP in the address
bar. You will get the default Nginx server page:
Convert web pages and HTML files to PDF in your applications with the Pdfcrowd HTML to PDF API Printed with Pdfcrowd.com
By default, the MariaDB is available on Ubuntu 22.04 base repository. Now run the following command
below to install the latest version of MariaDB to your Ubuntu system:
After successfully installation, enable MariaDB (to start automatically upon system boot), start, and verify
the status using the commands below:
Confirm the installation and check the installed build version of MariaDB:
mariadb --version
By default, MariaDB is not hardened. You can secure MariaDB using the
mysql_secure_installation script. you should read and below each step carefully which will set a
root password, remove anonymous users, disallow remote root login, and remove the test database and
access to secure MariaDB:
mysql_secure_installation
You can now connect to the MariaDB server using the new password:
mysql -u root -p
Output:
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 46
Server version: 10.6.7-MariaDB-2ubuntu1 Ubuntu 22.04
Convert web pages and HTML files to PDF in your applications with the Pdfcrowd HTML to PDF API Printed with Pdfcrowd.com
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]>
By default, the PHP is not available on Ubuntu 22.04 base repository. Now run the following command
below to add the Ondrej PPA to your system:
After the repository was added, Update the APT index then install PHP 8.1 using the following command
below:
Confirm the installation and check the installed build version of PHP:
php --version
After successfully installation, enable php-fpm (to start automatically upon system boot), start, and verify
the status using the commands below:
nano /etc/nginx/conf.d/default.conf
server {
listen 80;
listen [::]:80;
server_name _;
root /var/www/html/;
Convert web pages and HTML files to PDF in your applications with the Pdfcrowd HTML to PDF API Printed with Pdfcrowd.com
index index.php index.html index.htm index.nginx-debian.html;
location / {
try_files $uri $uri/ /index.php;
}
location ~ \.php$ {
fastcgi_pass unix:/run/php/php8.1-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
include snippets/fastcgi-php.conf;
}
# A long browser cache lifetime can speed up repeat visits to your page
location ~* \.(jpg|jpeg|gif|png|webp|svg|woff|woff2|ttf|css|js|ico|xml)$ {
access_log off;
log_not_found off;
expires 360d;
}
Save and close the file, then restart the Nginx webserver to take change effect:
nginx -t
sudo systemctl start nginx
To test PHP scripts we need to add the info.php file in the document:
nano /var/www/html/info.php
Let’s make sure that the server correctly displays the content generated by the PHP script by opening this
page in the browser: http://your-IP-address/info.php
Convert web pages and HTML files to PDF in your applications with the Pdfcrowd HTML to PDF API Printed with Pdfcrowd.com
Step 10. Secure Nginx with Let’s Encrypt SSL.
Let’s Encrypt is a certificate authority that provides free SSL certificates for websites. Let’s Encrypt
supports auto installation of certificates on Nginx. Now run the following command below to install it:
Next, run the following command to start the creation of your certificate:
After that, we set up auto-renewal SSL because Let’s Encrypt is valid for 90 days only, so you need to
renew them often using the following command:
Once successfully completed secure Nginx with Let’s Encrypt SSL, now go to ssllabs.com/ssltest/, and
run an SSL test on your domain:
Convert web pages and HTML files to PDF in your applications with the Pdfcrowd HTML to PDF API Printed with Pdfcrowd.com
Congratulations! You have successfully installed LEMP. Thanks for using this tutorial for installing the LEMP
Stack on Ubuntu 22.04 LTS Jammy Jellyfish system. For additional help or useful information, we recommend
you check the official LEMP website.
If you don’t have time to do all of this stuff, or if this is not your area of expertise, we offer a service
to do “VPS Manage Service Offer”, starting from $10 (Paypal payment). Please contact us to get the
best deal!
TAGS: LEMP
Convert web pages and HTML files to PDF in your applications with the Pdfcrowd HTML to PDF API Printed with Pdfcrowd.com