How to Install LEMP Stack (Nginx, PHP, and MariaDB) on Debian 12

 

 

Introduction

The LEMP stack, which consists of Linux, Nginx, PHP, and MariaDB, is a popular choice for hosting dynamic websites and applications. This guide will walk you through the steps to install the LEMP stack on Debian 12, ensuring you have a robust environment for your web projects. Utilizing a Windows VPS UK can further enhance your deployment capabilities.

Prerequisites

  • A server running Debian 12
  • Root or sudo access to the server
  • An internet connection to download packages

Step 1: Update Your System

Before installing the LEMP stack, update your package list and upgrade the existing packages:

sudo apt update && sudo apt upgrade -y

Step 2: Install Nginx

To install Nginx, use the following command:

sudo apt install nginx -y

After installation, start Nginx and enable it to run on boot:

sudo systemctl start nginx
sudo systemctl enable nginx

To verify that Nginx is running, open your web browser and navigate to your server's IP address.

Step 3: Install MariaDB

Next, install MariaDB, which will serve as your database management system:

sudo apt install mariadb-server -y

After the installation, secure your MariaDB installation:

sudo mysql_secure_installation

Follow the prompts to set a root password and secure your installation.

Step 4: Install PHP

Install PHP along with the necessary PHP extensions for Nginx and MariaDB:

sudo apt install php-fpm php-mysql -y

Step 5: Configure Nginx to Use PHP

Edit the default Nginx server block configuration:

sudo nano /etc/nginx/sites-available/default

Find the section that begins with server { and modify it to include the following lines to handle PHP files:

location ~ \.php$ {
    include snippets/fastcgi-php.conf;
    fastcgi_pass unix:/var/run/php/php7.4-fpm.sock; # Update PHP version if necessary
}

After making changes, test the Nginx configuration:

sudo nginx -t

If the configuration test is successful, restart Nginx:

sudo systemctl restart nginx

Step 6: Create a PHP Info File

To verify that PHP is working with Nginx, create a PHP info file:

echo "<?php phpinfo(); ?>" | sudo tee /var/www/html/info.php

Now, open your web browser and navigate to http://your_server_ip/info.php. You should see the PHP information page.

Step 7: Conclusion

You have successfully installed the LEMP stack (Nginx, PHP, and MariaDB) on Debian 12. This setup provides a powerful platform for hosting web applications. For those interested in enhanced performance and reliability, consider utilizing a Windows VPS. You can explore various options, such as VPS UK Windows, including Windows Virtual Private Server Hosting and Windows VPS Hosting UK for your server needs.

© 2024 LEMP Stack Installation Tutorial. All rights reserved.

  • 0 Utilisateurs l'ont trouvée utile
Cette réponse était-elle pertinente?

Articles connexes

Boost Your Ubuntu System's Performance with a Swap File: A Step-by-Step Guide

What is a Swap File? A swap file in Ubuntu serves as dedicated virtual memory on your hard...

How to Migrate ISPConfig 2, ISPConfig 3.x, Confixx, CPanel or Plesk to ISPConfig 3.2 (single server)

Introduction Migration from other control panels like ISPConfig 2, ISPConfig 3.x, Confixx,...

How to Install and Configure Zabbix Server and Client on Rocky Linux 9

Introduction Zabbix is an open-source monitoring solution that provides real-time...

How to Install CockroachDB Cluster on Debian 12

Introduction CockroachDB is a distributed SQL database built to handle large-scale,...

How to Install Joomla with Apache and Let's Encrypt SSL on AlmaLinux 9

Introduction Joomla is a popular open-source content management system (CMS) used to build...