{"id":16074,"date":"2026-09-21T19:57:26","date_gmt":"2026-09-21T18:57:26","guid":{"rendered":"https:\/\/da-manager.com\/blog\/how-to-set-up-lemp-stack-on-your-vps\/"},"modified":"2026-09-21T19:57:26","modified_gmt":"2026-09-21T18:57:26","slug":"how-to-set-up-lemp-stack-on-your-vps","status":"publish","type":"post","link":"https:\/\/da-manager.com\/blog\/how-to-set-up-lemp-stack-on-your-vps\/","title":{"rendered":"How to Set Up LEMP Stack on Your VPS"},"content":{"rendered":"<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_87 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<span class=\"ez-toc-title-toggle\"><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-1'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/da-manager.com\/blog\/how-to-set-up-lemp-stack-on-your-vps\/#How_to_Set_Up_LEMP_Stack_on_Your_VPS_A_Complete_Step-by-Step_Guide\" >How to Set Up LEMP Stack on Your VPS: A Complete Step-by-Step Guide<\/a><ul class='ez-toc-list-level-2' ><li class='ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/da-manager.com\/blog\/how-to-set-up-lemp-stack-on-your-vps\/#What_Is_a_LEMP_Stack_and_Why_Use_It_on_a_VPS\" >What Is a LEMP Stack and Why Use It on a VPS?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/da-manager.com\/blog\/how-to-set-up-lemp-stack-on-your-vps\/#Prerequisites_Before_You_Begin\" >Prerequisites Before You Begin<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/da-manager.com\/blog\/how-to-set-up-lemp-stack-on-your-vps\/#Step_1_Update_Your_Server\" >Step 1: Update Your Server<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/da-manager.com\/blog\/how-to-set-up-lemp-stack-on-your-vps\/#Step_2_Install_Nginx\" >Step 2: Install Nginx<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/da-manager.com\/blog\/how-to-set-up-lemp-stack-on-your-vps\/#Configuring_the_Firewall_for_Nginx\" >Configuring the Firewall for Nginx<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/da-manager.com\/blog\/how-to-set-up-lemp-stack-on-your-vps\/#Step_3_Install_MySQL\" >Step 3: Install MySQL<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/da-manager.com\/blog\/how-to-set-up-lemp-stack-on-your-vps\/#Creating_a_New_Database_and_User\" >Creating a New Database and User<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/da-manager.com\/blog\/how-to-set-up-lemp-stack-on-your-vps\/#Step_4_Install_PHP\" >Step 4: Install PHP<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-10\" href=\"https:\/\/da-manager.com\/blog\/how-to-set-up-lemp-stack-on-your-vps\/#Step_5_Configure_Nginx_to_Use_PHP-FPM\" >Step 5: Configure Nginx to Use PHP-FPM<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-11\" href=\"https:\/\/da-manager.com\/blog\/how-to-set-up-lemp-stack-on-your-vps\/#Step_6_Create_a_Web_Root_Directory_and_Test_PHP\" >Step 6: Create a Web Root Directory and Test PHP<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-12\" href=\"https:\/\/da-manager.com\/blog\/how-to-set-up-lemp-stack-on-your-vps\/#Final_Tips_for_Securing_and_Optimising_Your_LEMP_Stack_VPS\" >Final Tips for Securing and Optimising Your LEMP Stack VPS<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-13\" href=\"https:\/\/da-manager.com\/blog\/how-to-set-up-lemp-stack-on-your-vps\/#Conclusion\" >Conclusion<\/a><\/li><\/ul><\/li><\/ul><\/nav><\/div>\n<p><html><br \/>\n<head><br \/>\n<title>How to Set Up LEMP Stack on Your VPS<\/title><br \/>\n<\/head><br \/>\n<body><\/p>\n<h1><span class=\"ez-toc-section\" id=\"How_to_Set_Up_LEMP_Stack_on_Your_VPS_A_Complete_Step-by-Step_Guide\"><\/span>How to Set Up LEMP Stack on Your VPS: A Complete Step-by-Step Guide<span class=\"ez-toc-section-end\"><\/span><\/h1>\n<p>If you are looking to host high-performance web applications on a virtual private server, configuring a LEMP stack VPS is one of the smartest decisions you can make. LEMP stands for Linux, Nginx, MySQL, and PHP \u2014 a powerful combination of open-source technologies that work seamlessly together to deliver fast, reliable, and scalable web hosting environments. In this guide, we will walk you through every step of the setup process, from updating your server to testing your configuration.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"What_Is_a_LEMP_Stack_and_Why_Use_It_on_a_VPS\"><\/span>What Is a LEMP Stack and Why Use It on a VPS?<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Before diving into the technical steps, it is worth understanding what a LEMP stack actually is and why so many developers and system administrators prefer it over alternatives like LAMP (which uses Apache instead of Nginx).<\/p>\n<p>The LEMP stack consists of four core components:<\/p>\n<ul>\n<li><strong>Linux<\/strong> \u2014 The operating system that forms the foundation of your server environment<\/li>\n<li><strong>Nginx<\/strong> \u2014 A lightweight, high-performance web server and reverse proxy<\/li>\n<li><strong>MySQL<\/strong> \u2014 A widely used relational database management system (MariaDB is often used as a drop-in replacement)<\/li>\n<li><strong>PHP<\/strong> \u2014 The server-side scripting language that powers countless web applications<\/li>\n<\/ul>\n<p>Nginx is particularly well-suited for handling large volumes of concurrent connections with minimal resource usage, making a LEMP stack VPS an excellent choice for high-traffic websites, WordPress installations, and custom web applications.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Prerequisites_Before_You_Begin\"><\/span>Prerequisites Before You Begin<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>To follow this guide, you will need the following:<\/p>\n<ul>\n<li>A VPS running Ubuntu 22.04 LTS (though the steps are similar for Debian-based distributions)<\/li>\n<li>Root or sudo access to your server<\/li>\n<li>Basic familiarity with the Linux command line<\/li>\n<li>An SSH client such as PuTTY or a terminal application<\/li>\n<\/ul>\n<p>If you are new to managing virtual private servers and want to learn more about server administration best practices, the <a href=\"https:\/\/da-manager.com\/blog\" target=\"_blank\">DA Manager blog<\/a> offers a wealth of helpful resources to get you started.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Step_1_Update_Your_Server\"><\/span>Step 1: Update Your Server<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>The very first thing you should do after logging into your VPS is update all existing packages. This ensures you are working with the latest security patches and software versions.<\/p>\n<p>Run the following commands:<\/p>\n<pre>\nsudo apt update\nsudo apt upgrade -y\n<\/pre>\n<p>Once the update process is complete, you may be prompted to restart your server. It is good practice to do so before proceeding.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Step_2_Install_Nginx\"><\/span>Step 2: Install Nginx<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Nginx is the web server component of your LEMP stack VPS. It is available directly from Ubuntu&#8217;s default repositories, making installation straightforward.<\/p>\n<pre>\nsudo apt install nginx -y\n<\/pre>\n<p>Once installed, start and enable the Nginx service so that it launches automatically on system reboot:<\/p>\n<pre>\nsudo systemctl start nginx\nsudo systemctl enable nginx\n<\/pre>\n<p>You can verify that Nginx is running correctly by visiting your server&#8217;s IP address in a web browser. You should see the default Nginx welcome page.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Configuring_the_Firewall_for_Nginx\"><\/span>Configuring the Firewall for Nginx<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>If you have UFW (Uncomplicated Firewall) enabled, you will need to allow HTTP and HTTPS traffic:<\/p>\n<pre>\nsudo ufw allow 'Nginx Full'\n<\/pre>\n<h2><span class=\"ez-toc-section\" id=\"Step_3_Install_MySQL\"><\/span>Step 3: Install MySQL<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Next, you will install MySQL to handle your database management needs. Run the following command:<\/p>\n<pre>\nsudo apt install mysql-server -y\n<\/pre>\n<p>Once the installation is complete, it is strongly recommended that you run the built-in security script to remove default settings that could pose a security risk:<\/p>\n<pre>\nsudo mysql_secure_installation\n<\/pre>\n<p>This script will prompt you to set a root password, remove anonymous users, disallow remote root login, and remove the test database. Answer yes to all prompts to ensure your database is properly secured.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Creating_a_New_Database_and_User\"><\/span>Creating a New Database and User<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>For best practice, avoid using the root MySQL account for your web applications. Instead, create a dedicated database and user:<\/p>\n<pre>\nsudo mysql\nCREATE DATABASE mywebsite_db;\nCREATE USER 'webuser'@'localhost' IDENTIFIED BY 'StrongPassword123!';\nGRANT ALL PRIVILEGES ON mywebsite_db.* TO 'webuser'@'localhost';\nFLUSH PRIVILEGES;\nEXIT;\n<\/pre>\n<h2><span class=\"ez-toc-section\" id=\"Step_4_Install_PHP\"><\/span>Step 4: Install PHP<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>PHP is the final major component of your LEMP stack VPS. Unlike Apache, Nginx does not process PHP natively, so you will need to install PHP-FPM (FastCGI Process Manager) to handle PHP processing.<\/p>\n<pre>\nsudo apt install php-fpm php-mysql -y\n<\/pre>\n<p>You may also wish to install additional PHP extensions depending on your application&#8217;s requirements:<\/p>\n<pre>\nsudo apt install php-curl php-gd php-mbstring php-xml php-xmlrpc php-zip -y\n<\/pre>\n<h2><span class=\"ez-toc-section\" id=\"Step_5_Configure_Nginx_to_Use_PHP-FPM\"><\/span>Step 5: Configure Nginx to Use PHP-FPM<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Now that all components are installed, you need to configure Nginx to pass PHP requests to PHP-FPM. Create a new server block configuration file for your website:<\/p>\n<pre>\nsudo nano \/etc\/nginx\/sites-available\/mywebsite\n<\/pre>\n<p>Add the following configuration, replacing <em>your_domain_or_IP<\/em> with your actual domain name or server IP address:<\/p>\n<pre>\nserver {\n    listen 80;\n    server_name your_domain_or_IP;\n    root \/var\/www\/mywebsite;\n    index index.php index.html index.htm;\n\n    location \/ {\n        try_files $uri $uri\/ =404;\n    }\n\n    location ~ \\.php$ {\n        include snippets\/fastcgi-php.conf;\n        fastcgi_pass unix:\/var\/run\/php\/php8.1-fpm.sock;\n    }\n\n    location ~ \/\\.ht {\n        deny all;\n    }\n}\n<\/pre>\n<p>Save and close the file, then enable the configuration by creating a symbolic link:<\/p>\n<pre>\nsudo ln -s \/etc\/nginx\/sites-available\/mywebsite \/etc\/nginx\/sites-enabled\/\n<\/pre>\n<p>Test the Nginx configuration for syntax errors and reload the service:<\/p>\n<pre>\nsudo nginx -t\nsudo systemctl reload nginx\n<\/pre>\n<h2><span class=\"ez-toc-section\" id=\"Step_6_Create_a_Web_Root_Directory_and_Test_PHP\"><\/span>Step 6: Create a Web Root Directory and Test PHP<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Create the document root directory and a test PHP file to confirm everything is working correctly:<\/p>\n<pre>\nsudo mkdir -p \/var\/www\/mywebsite\nsudo nano \/var\/www\/mywebsite\/info.php\n<\/pre>\n<p>Add the following content to the file:<\/p>\n<pre>\n&lt;?php\nphpinfo();\n?&gt;\n<\/pre>\n<p>Visit <em>http:\/\/your_domain_or_IP\/info.php<\/em> in your browser. If you see the PHP information page, your LEMP stack VPS is working correctly. Be sure to delete this file after testing, as it exposes sensitive server information:<\/p>\n<pre>\nsudo rm \/var\/www\/mywebsite\/info.php\n<\/pre>\n<h2><span class=\"ez-toc-section\" id=\"Final_Tips_for_Securing_and_Optimising_Your_LEMP_Stack_VPS\"><\/span>Final Tips for Securing and Optimising Your LEMP Stack VPS<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Now that your LEMP stack is up and running, there are several additional steps you should consider to keep your server secure and performing at its best:<\/p>\n<ul>\n<li><strong>Install an SSL certificate<\/strong> \u2014 Use Let&#8217;s Encrypt and Certbot to enable HTTPS on your domain at no cost<\/li>\n<li><strong>Enable Nginx caching<\/strong> \u2014 Configure FastCGI caching to reduce server load for dynamic content<\/li>\n<li><strong>Set up regular backups<\/strong> \u2014 Automate database and file backups to protect your data<\/li>\n<li><strong>Monitor server resources<\/strong> \u2014 Use tools such as htop or netdata to keep an eye on CPU, memory, and disk usage<\/li>\n<li><strong>Keep software updated<\/strong> \u2014 Regularly apply security patches to all components of your stack<\/li>\n<\/ul>\n<h2><span class=\"ez-toc-section\" id=\"Conclusion\"><\/span>Conclusion<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Setting up a LEMP stack VPS may seem daunting at first, but by following these steps methodically, you can have a fully functional and secure web server environment running in under an hour. The combination of Nginx&#8217;s speed, MySQL&#8217;s reliability, and PHP&#8217;s flexibility makes the LEMP stack one of the most popular choices for hosting modern web applications. Whether you are deploying a WordPress site, a Laravel application, or a custom web project, a properly configured LEMP stack VPS will give you the performance and control you need to succeed.<\/p>\n<p><\/body><br \/>\n<\/html><\/p>\n","protected":false},"excerpt":{"rendered":"<p>How to Set Up LEMP Stack on Your VPS<\/p>\n<p>How to Set Up LEMP Stack on Your VPS: A Complete Step-by-Step Guide<\/p>\n<p>If you are looking to host high-performance web applications on a virtual private server, configuring a LEMP stack VPS is one of the smartest decisions you can make. LEMP stands for Linux, <\/p>\n","protected":false},"author":16,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_mbp_gutenberg_autopost":false,"footnotes":""},"categories":[147],"tags":[],"class_list":["post-16074","post","type-post","status-publish","format-standard","category-general"],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/da-manager.com\/blog\/wp-json\/wp\/v2\/posts\/16074","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/da-manager.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/da-manager.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/da-manager.com\/blog\/wp-json\/wp\/v2\/users\/16"}],"replies":[{"embeddable":true,"href":"https:\/\/da-manager.com\/blog\/wp-json\/wp\/v2\/comments?post=16074"}],"version-history":[{"count":0,"href":"https:\/\/da-manager.com\/blog\/wp-json\/wp\/v2\/posts\/16074\/revisions"}],"wp:attachment":[{"href":"https:\/\/da-manager.com\/blog\/wp-json\/wp\/v2\/media?parent=16074"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/da-manager.com\/blog\/wp-json\/wp\/v2\/categories?post=16074"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/da-manager.com\/blog\/wp-json\/wp\/v2\/tags?post=16074"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}