• Home
  • Linux
  • Ubuntu
  • Debian
  • CentOS
  • Linux Commands
  • About Us
  • Donate
TecNStuff
Menu
  • Home
  • Linux
  • Ubuntu
  • Debian
  • CentOS
  • Linux Commands
  • About Us
  • Donate

How to Install LEMP Stack on Ubuntu 22.04

Written by Admin, Updated On January 21, 2023
lemp, mariadb, mysql, nginx, php, ubuntu
How to Install LEMP Stack on Ubuntu 22.04

The LEMP is a short name that describes a Linux operating system, with an Nginx (pronounced like “Engine-X”) web server. The backend data is stored in the MySQL or MariaDB database and the dynamic processing is handled by PHP. This tutorial describes how to install a LEMP stack on an Ubuntu 22.04 server.

We will show you how to install Nginx, install and secure MySQL, and install PHP.

How to Install LEMP Stack on Ubuntu 22.04#

You will need non-root user having sudo privileges to be able to install packages.

Step 1 – Installing Nginx#

Nginx is a high performance HTTP server. It’s available in default Ubuntu repositories. We’ll use the apt package manager to obtain this package.

At first, you have to update the packages index and install Nginx by running the following commands:

sudo apt update
sudo apt install nginx

The Nginx web server will start automatically once the installation is finish.

If you have the ufw firewall enabled, you will need to allow connections to Nginx. To list ufw profiles, run:

sudo ufw app list
Available applications:
  Nginx Full
  Nginx HTTP
  Nginx HTTPS
  OpenSSH

Currently, we have not configured SSL certificate, we need allow only HTTP traffic on port 80:

sudo ufw allow 'Nginx HTTP'

After that, verify the change by running:

sudo ufw status

It will show that HTTP traffic is now allowed:

Status: active

To                         Action      From
--                         ------      ----
OpenSSH                    ALLOW       Anywhere
Nginx HTTP                 ALLOW       Anywhere
OpenSSH (v6)               ALLOW       Anywhere (v6)
Nginx HTTP (v6)            ALLOW       Anywhere (v6)

To verify installation, open your web browser and enter your SERVER_IP_OR_DOMAIN as URL and it should open nginx default page as given below.

http://SERVER_IP_OR_DOMAIN
nginx-default-page-1

Step 2 – Installing MySQL#

Next, we need to install the database system to store and manage data for website. MySQL is a popular database management system. By default, MySQL 8.0 is available in Ubuntu repositories. Run the below command to install:

sudo apt install mysql-server

Once the installation finished, it’s recommended that you run a MySQL in-built security script.

sudo mysql_secure_installation

You will be asked to set the root password, remove the anonymous user, restrict root user access to the local machine, and remove the test database. You should answer Y (yes) to all questions.

Step 3 – Installing PHP#

You have installed Nginx and MySQL. Now we will install PHP to serve dynamic content for the web server.

PHP 8.2 packages are available under the default repositories on Ubuntu 22.04 LTS. We will install php-fpm module along with an additional helper package, php-mysql. php-mysql will allow PHP to communicate with your database backend. Execute below command:

sudo apt install php-fpm php-mysql

At this stage, you have your PHP components installed. In next step, we’ll configure Nginx.

Step 4 – Configuring Nginx to Process PHP Pages#

At this point, you have installed all the components of LEMP. Edit the Nginx server block configuration file and add the following lines so that Nginx can process PHP files:

server {
  # other code

  location ~ \.php$ {
    include snippets/fastcgi-php.conf;
    fastcgi_pass unix:/run/php/php4.0-fpm.sock;
  }
}

Save and close the file. Restart the Nginx service for the changes to take effect:

sudo systemctl restart nginx

Step 5 – Test PHP with Nginx#

Now your LEMP components are install and ready to test it. Create a test PHP file called info.php in your document root:

sudo nano /var/www/html/info.php

Add following code lines to this file:

<?php
phpinfo();

Save and close the file. Open this page using your server’s public ip address followed by /info.php as following:

http://SERVER_IP_OR_DOMAIN/info.php

Conclusion#

This tutorial shown you how to install LEMP (Nginx, MySql, PHP) stack on Ubuntu 22.04 Jemmy Jelifish server.

If you have any questions or feedback, leave a comment below.

If our content helps you, please consider buying us a coffee

Thank you for your support.

Share On
Share on Facebook
Share on Twitter
Share on Reddit
Share on Tumblr
 Previous Article How to Install Memcached on Ubuntu 22.04
Next Article   How to Install LAMP on Ubuntu 22.04

Related Posts

  • How to Install WordPress with Nginx on Debian 11

    How to Install WordPress with Nginx on Debian 11

    March 22, 2023
  • How to Install Apache, MySQL, PHP (LAMP) on Ubuntu 22.04

    How to Install LAMP on Ubuntu 22.04

    March 20, 2023
  • How to Install Memcached on Ubuntu 22.04

    How to Install Memcached on Ubuntu 22.04

    March 16, 2023

Leave a Reply Cancel reply

DigitalOcean Referral Badge

Popular Posts

  • How to Install Microsoft Edge Browser on Ubuntu 22.04
    How to Install Microsoft Edge Browser on Ubuntu 22.04 March 14, 2023
  • How to Install Ruby on Ubuntu 22.04 LTS
    How to Install Ruby on Ubuntu 22.04 LTS February 27, 2023
  • How to Install LEMP Stack on Ubuntu 22.04
    How to Install LEMP Stack on Ubuntu 22.04 March 18, 2023
  • How to Install Set Up Apache Virtual Hosts on Ubuntu 22.04
    How to Set Up Apache Virtual Hosts on Ubuntu 22.04 March 2, 2023
  • How to Install MariaDB on Debian 11 Bullseye
    How to Install MariaDB on Debian 11 Bullseye March 8, 2023
© 2020 TecNStuff All rights reserved. This website is using and storing cookies on your browser. By using this website you agree our Privacy Policy.  Follow us -  Twitter | Facebook