The LEMP stack (Linux, Nginx, MySQL, PHP) is a popular solution for hosting dynamic websites and applications. In this tutorial, you will learn how to install and configure the LEMP stack on Ubuntu 22.04.
Step 1: Update Your System
Before starting the installation process, ensure your system is up-to-date by running the following command:
sudo apt update && sudo apt upgrade
Step 2: Install Nginx
Nginx is a high-performance web server used in the LEMP stack. Install it using the following command:
sudo apt install nginx
After installation, start and enable Nginx:
sudo systemctl start nginx
sudo systemctl enable nginx
Step 3: Install MySQL
MySQL is the database server used in the LEMP stack. To install MySQL, run the following command:
sudo apt install mysql-server
Once installed, run the security script to enhance MySQL security:
sudo mysql_secure_installation
Step 4: Install PHP
PHP is a server-side scripting language that processes dynamic content. Install PHP and the necessary extensions:
sudo apt install php-fpm php-mysql
PHP-FPM (FastCGI Process Manager) allows Nginx to handle PHP requests efficiently.
Step 5: Configure Nginx to Use PHP
To configure Nginx to process PHP files, open the default server block file:
sudo nano /etc/nginx/sites-available/default
Find the following section and modify it:
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
}
Save the file and restart Nginx:
sudo systemctl restart nginx
Step 6: Test PHP
To verify that PHP is working with Nginx, create a PHP info file:
sudo nano /var/www/html/info.php
Add the following code:
<?php phpinfo(); ?>
Save the file and visit http://your_server_ip/info.php
to confirm PHP is working correctly.
Conclusion
You have successfully installed the LEMP stack on Ubuntu 22.04. This powerful combination of Nginx, PHP, and MySQL will allow you to host dynamic web applications efficiently.
If you’re looking for a reliable hosting solution for your LEMP stack, consider using Linux VPS UK. A Linux VPS offers flexibility and high performance, making it perfect for hosting your website or application. Whether you need Linux VPS or Linux VPSVirtual Private Servers, this hosting provider offers reliable and secure solutions.
Hosting options such as Linux VPSServer VPS and Linux VPSVirtual Dedicated Server Hosting are ideal for businesses needing scalable and secure hosting. With UK Linux VPS services, you can enjoy efficient VPS Linux VPSHosting that meets your needs. Many businesses across Europe, including Italy, rely on Linux VPS Italy for their hosting needs.
Explore more about hosting options, including Virtual Private Server Hosting Windows and Linux VPS Hosting UK, at Linux VPS UK.