๐Ÿ’ป Lemp Stack Installation

ยท

3 min read

๐Ÿ’ป Lemp Stack Installation

Installing a LEMP stack (Linux, Nginx, MySQL, PHP) is a common practice for setting up a robust web server environment. Below is a practical guide to walk you through the installation process on a Linux-based system, specifically using Ubuntu as an example. Adjust the commands as needed for your distribution.

Step 1 โ€“ Installing the Nginx Web Server

Step 2 โ€” Installing MySQL

Step 3 โ€“ Installing PHP
Step 4: Configuring Nginx to work with PHP-FPM

Step 1: Update Your System

Before installing any software, ensure your system is up-to-date:

sudo apt update
sudo apt upgrade

Step 2: Install Nginx

Nginx is a high-performance web server and reverse proxy. Install it using the following commands:

sudo apt install nginx

Start and enable Nginx to run on system boot:

sudo systemctl start nginx
sudo systemctl enable nginx

Step 3: Install MySQL (MariaDB)

MySQL is a popular relational database management system. For Ubuntu, you'll typically use MariaDB, a MySQL fork:

sudo apt install mariadb-server

Start and enable MariaDB:

sudo systemctl start mariadb
sudo systemctl enable mariadb

Run the MySQL secure installation script:

sudo mysql_secure_installation

Follow the on-screen prompts to set a root password and secure your MySQL installation.

Step 4: Install PHP

Install PHP and required extensions:

sudo apt install php-fpm php-mysql

Step 5: Configure Nginx to Use PHP

Edit the default Nginx server block configuration:

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

Find the location ~ \.php$ block and uncomment/modify the lines to look like this:

location ~ \.php$ {
    include snippets/fastcgi-php.conf;
    fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include fastcgi_params;
}

Save the file and exit.

Restart Nginx to apply the changes:

sudo systemctl restart nginx

Step 6: Test Your LEMP Stack

Create a PHP info page to verify that PHP is working correctly:

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

Visit your server's IP address or domain followed by /info.php in a web browser (e.g., http://your_server_ip/info.php). You should see the PHP information page.

Conclusion

Congratulations! You've successfully installed a LEMP stack on your Linux server. This setup provides a solid foundation for hosting web applications and websites. Remember to follow best practices for security, such as configuring firewalls, securing MySQL, and keeping software up-to-date, to ensure a secure and stable environment.

DO FOLLOW Kanishthika Singh

  • ๐Ÿ‘€ Iโ€™m interested in learning and working with community , open source contribution and give back to the community.

  • โ›ท๏ธ I'm currently working with Kubernetes, Docker, AWS, Jenkins, Terraform, CI/CD, Data science and analysis

  • ๐Ÿ’ž๏ธ Iโ€™m looking to collaborate on GitHub and open source projects related to cloud computing and Data and DEVOPS

  • ๐Ÿ’ฌ Ask me about DevOps, Linux-Ubuntu, Docker, DATA , AI , TECH.

  • ๐Ÿ“ซ Reach out to me at

ย