{"id":1016,"date":"2025-11-14T15:49:48","date_gmt":"2025-11-14T15:49:48","guid":{"rendered":"https:\/\/gratisvps.net\/blog\/?p=1016"},"modified":"2025-11-14T15:49:48","modified_gmt":"2025-11-14T15:49:48","slug":"install-secure-the-lemp-stack-nginx-mysql-php-on-your-hardened-linux-vps","status":"publish","type":"post","link":"https:\/\/gratisvps.net\/blog\/install-secure-the-lemp-stack-nginx-mysql-php-on-your-hardened-linux-vps\/","title":{"rendered":"Install &#038; Secure the LEMP Stack (Nginx, MySQL, PHP) on Your Hardened Linux VPS"},"content":{"rendered":"<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_85 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\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/gratisvps.net\/blog\/install-secure-the-lemp-stack-nginx-mysql-php-on-your-hardened-linux-vps\/#Introduction_Why_LEMP_Over_LAMP\" >Introduction: Why LEMP Over LAMP?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/gratisvps.net\/blog\/install-secure-the-lemp-stack-nginx-mysql-php-on-your-hardened-linux-vps\/#Phase_1_Installing_Nginx_The_Web_Server\" >Phase 1: Installing Nginx (The Web Server)<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/gratisvps.net\/blog\/install-secure-the-lemp-stack-nginx-mysql-php-on-your-hardened-linux-vps\/#Step_11_Install_Nginx\" >Step 1.1: Install Nginx<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/gratisvps.net\/blog\/install-secure-the-lemp-stack-nginx-mysql-php-on-your-hardened-linux-vps\/#Step_12_Configure_Firewall_UFW\" >Step 1.2: Configure Firewall (UFW)<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/gratisvps.net\/blog\/install-secure-the-lemp-stack-nginx-mysql-php-on-your-hardened-linux-vps\/#Step_13_Test_Nginx_Installation\" >Step 1.3: Test Nginx Installation<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/gratisvps.net\/blog\/install-secure-the-lemp-stack-nginx-mysql-php-on-your-hardened-linux-vps\/#Phase_2_Installing_and_Securing_MariaDB_The_Database\" >Phase 2: Installing and Securing MariaDB (The Database)<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/gratisvps.net\/blog\/install-secure-the-lemp-stack-nginx-mysql-php-on-your-hardened-linux-vps\/#Step_21_Install_MariaDB_Server\" >Step 2.1: Install MariaDB Server<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/gratisvps.net\/blog\/install-secure-the-lemp-stack-nginx-mysql-php-on-your-hardened-linux-vps\/#Step_22_Run_the_Critical_Security_Script\" >Step 2.2: Run the Critical Security Script<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/gratisvps.net\/blog\/install-secure-the-lemp-stack-nginx-mysql-php-on-your-hardened-linux-vps\/#Step_23_Create_a_Database_and_User\" >Step 2.3: Create a 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-10\" href=\"https:\/\/gratisvps.net\/blog\/install-secure-the-lemp-stack-nginx-mysql-php-on-your-hardened-linux-vps\/#Phase_3_Installing_and_Configuring_PHP-FPM\" >Phase 3: Installing and Configuring PHP-FPM<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-11\" href=\"https:\/\/gratisvps.net\/blog\/install-secure-the-lemp-stack-nginx-mysql-php-on-your-hardened-linux-vps\/#Step_31_Install_PHP-FPM_and_Extensions\" >Step 3.1: Install PHP-FPM and Extensions<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-12\" href=\"https:\/\/gratisvps.net\/blog\/install-secure-the-lemp-stack-nginx-mysql-php-on-your-hardened-linux-vps\/#Step_32_Configure_PHP-FPM_for_Better_Security\" >Step 3.2: Configure PHP-FPM for Better Security<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-13\" href=\"https:\/\/gratisvps.net\/blog\/install-secure-the-lemp-stack-nginx-mysql-php-on-your-hardened-linux-vps\/#Step_33_Restart_PHP-FPM\" >Step 3.3: Restart PHP-FPM<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-14\" href=\"https:\/\/gratisvps.net\/blog\/install-secure-the-lemp-stack-nginx-mysql-php-on-your-hardened-linux-vps\/#Phase_4_Nginx_Server_Block_Configuration\" >Phase 4: Nginx Server Block Configuration<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-15\" href=\"https:\/\/gratisvps.net\/blog\/install-secure-the-lemp-stack-nginx-mysql-php-on-your-hardened-linux-vps\/#Step_41_Create_Web_Root_Directory\" >Step 4.1: Create Web Root Directory<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-16\" href=\"https:\/\/gratisvps.net\/blog\/install-secure-the-lemp-stack-nginx-mysql-php-on-your-hardened-linux-vps\/#Step_42_Create_the_Nginx_Server_Block\" >Step 4.2: Create the Nginx Server Block<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-17\" href=\"https:\/\/gratisvps.net\/blog\/install-secure-the-lemp-stack-nginx-mysql-php-on-your-hardened-linux-vps\/#Step_43_Enable_the_Server_Block_and_Restart_Nginx\" >Step 4.3: Enable the Server Block and Restart Nginx<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-18\" href=\"https:\/\/gratisvps.net\/blog\/install-secure-the-lemp-stack-nginx-mysql-php-on-your-hardened-linux-vps\/#Final_Test_The_PHP_Info_File\" >Final Test: The PHP Info File<\/a><\/li><\/ul><\/nav><\/div>\n<h2><span class=\"ez-toc-section\" id=\"Introduction_Why_LEMP_Over_LAMP\"><\/span>Introduction: Why LEMP Over LAMP?<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>&nbsp;<\/p>\n<p data-path-to-node=\"9\">For a low-resource or <b>free VPS hosting<\/b> environment, choosing the right software stack is critical. We recommend the <b>LEMP<\/b> stack (Linux, Nginx, MySQL\/MariaDB, PHP-FPM) because its web server, <b>Nginx<\/b> (pronounced &#8220;Engine-X&#8221;), uses an <b>event-driven architecture<\/b> that is significantly more efficient at handling concurrent connections and consumes <b>less memory<\/b> compared to Apache (used in the LAMP stack).<\/p>\n<p data-path-to-node=\"10\">This guide assumes you have completed the <b>[50-Point VPS Hardening Checklist]<\/b> (Internal Link) and are logged in as your non-root <code>sudo<\/code> user.<\/p>\n<p data-path-to-node=\"11\">\n<h2><span class=\"ez-toc-section\" id=\"Phase_1_Installing_Nginx_The_Web_Server\"><\/span>Phase 1: Installing Nginx (The Web Server)<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>&nbsp;<\/p>\n<p data-path-to-node=\"12\">Nginx will be the front-facing server that handles user requests, routing dynamic requests (like PHP) to the processor and serving static files directly.<\/p>\n<p data-path-to-node=\"13\">\n<h3><span class=\"ez-toc-section\" id=\"Step_11_Install_Nginx\"><\/span>Step 1.1: Install Nginx<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>&nbsp;<\/p>\n<p data-path-to-node=\"14\">Start by ensuring your system package list is up-to-date and installing Nginx:<\/p>\n<div class=\"code-block ng-tns-c4015166184-112 ng-animate-disabled ng-trigger ng-trigger-codeBlockRevealAnimation\" data-hveid=\"0\" data-ved=\"0CAAQhtANahgKEwiQwPrR-fGQAxUAAAAAHQAAAAAQ3AI\">\n<div class=\"code-block-decoration header-formatted gds-title-s ng-tns-c4015166184-112 ng-star-inserted\"><span class=\"ng-tns-c4015166184-112\">Bash<\/span><\/p>\n<div class=\"buttons ng-tns-c4015166184-112 ng-star-inserted\"><\/div>\n<\/div>\n<div class=\"formatted-code-block-internal-container ng-tns-c4015166184-112\">\n<div class=\"animated-opacity ng-tns-c4015166184-112\">\n<pre class=\"ng-tns-c4015166184-112\"><code class=\"code-container formatted ng-tns-c4015166184-112\" role=\"text\" data-test-id=\"code-content\">sudo apt update\r\nsudo apt install nginx -y\r\n<\/code><\/pre>\n<\/div>\n<\/div>\n<\/div>\n<p data-path-to-node=\"16\">\n<h3><span class=\"ez-toc-section\" id=\"Step_12_Configure_Firewall_UFW\"><\/span>Step 1.2: Configure Firewall (UFW)<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>&nbsp;<\/p>\n<p data-path-to-node=\"17\">Because you have previously enabled UFW, you must now explicitly allow the web server traffic. Nginx registers profiles with UFW for easy management.<\/p>\n<ol start=\"1\" data-path-to-node=\"18\">\n<li>\n<p data-path-to-node=\"18,0,0\"><b>Check available profiles:<\/b><\/p>\n<div class=\"code-block ng-tns-c4015166184-113 ng-animate-disabled ng-trigger ng-trigger-codeBlockRevealAnimation\" data-hveid=\"0\" data-ved=\"0CAAQhtANahgKEwiQwPrR-fGQAxUAAAAAHQAAAAAQ3QI\">\n<div class=\"code-block-decoration header-formatted gds-title-s ng-tns-c4015166184-113 ng-star-inserted\"><span class=\"ng-tns-c4015166184-113\">Bash<\/span><\/p>\n<div class=\"buttons ng-tns-c4015166184-113 ng-star-inserted\"><\/div>\n<\/div>\n<div class=\"formatted-code-block-internal-container ng-tns-c4015166184-113\">\n<div class=\"animated-opacity ng-tns-c4015166184-113\">\n<pre class=\"ng-tns-c4015166184-113\"><code class=\"code-container formatted ng-tns-c4015166184-113\" role=\"text\" data-test-id=\"code-content\">sudo ufw app list\r\n<\/code><\/pre>\n<\/div>\n<\/div>\n<\/div>\n<\/li>\n<li>\n<p data-path-to-node=\"18,1,0\"><b>Allow the Nginx Full profile<\/b> (covers both HTTP on port 80 and HTTPS on port 443):<\/p>\n<div class=\"code-block ng-tns-c4015166184-114 ng-animate-disabled ng-trigger ng-trigger-codeBlockRevealAnimation\" data-hveid=\"0\" data-ved=\"0CAAQhtANahgKEwiQwPrR-fGQAxUAAAAAHQAAAAAQ3gI\">\n<div class=\"code-block-decoration header-formatted gds-title-s ng-tns-c4015166184-114 ng-star-inserted\"><span class=\"ng-tns-c4015166184-114\">Bash<\/span><\/p>\n<div class=\"buttons ng-tns-c4015166184-114 ng-star-inserted\"><\/div>\n<\/div>\n<div class=\"formatted-code-block-internal-container ng-tns-c4015166184-114\">\n<div class=\"animated-opacity ng-tns-c4015166184-114\">\n<pre class=\"ng-tns-c4015166184-114\"><code class=\"code-container formatted ng-tns-c4015166184-114\" role=\"text\" data-test-id=\"code-content\">sudo ufw allow <span class=\"hljs-string\">'Nginx Full'<\/span>\r\n<\/code><\/pre>\n<\/div>\n<\/div>\n<\/div>\n<\/li>\n<li>\n<p data-path-to-node=\"18,2,0\"><b>Verify the new firewall status:<\/b><\/p>\n<div class=\"code-block ng-tns-c4015166184-115 ng-animate-disabled ng-trigger ng-trigger-codeBlockRevealAnimation\" data-hveid=\"0\" data-ved=\"0CAAQhtANahgKEwiQwPrR-fGQAxUAAAAAHQAAAAAQ3wI\">\n<div class=\"code-block-decoration header-formatted gds-title-s ng-tns-c4015166184-115 ng-star-inserted\"><span class=\"ng-tns-c4015166184-115\">Bash<\/span><\/p>\n<div class=\"buttons ng-tns-c4015166184-115 ng-star-inserted\"><\/div>\n<\/div>\n<div class=\"formatted-code-block-internal-container ng-tns-c4015166184-115\">\n<div class=\"animated-opacity ng-tns-c4015166184-115\">\n<pre class=\"ng-tns-c4015166184-115\"><code class=\"code-container formatted ng-tns-c4015166184-115\" role=\"text\" data-test-id=\"code-content\">sudo ufw status\r\n<\/code><\/pre>\n<\/div>\n<\/div>\n<\/div>\n<p data-path-to-node=\"18,2,2\">You should see your new SSH port, <code>Nginx Full<\/code> (or <code>80\/tcp<\/code> and <code>443\/tcp<\/code>), and the <code>OpenSSH<\/code> rule listed as allowed.<\/p>\n<\/li>\n<\/ol>\n<p data-path-to-node=\"19\">\n<h3><span class=\"ez-toc-section\" id=\"Step_13_Test_Nginx_Installation\"><\/span>Step 1.3: Test Nginx Installation<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>&nbsp;<\/p>\n<p data-path-to-node=\"20\">Verify Nginx is active and running, then check its default page.<\/p>\n<ol start=\"1\" data-path-to-node=\"21\">\n<li>\n<p data-path-to-node=\"21,0,0\"><b>Check Nginx service status:<\/b><\/p>\n<div class=\"code-block ng-tns-c4015166184-116 ng-animate-disabled ng-trigger ng-trigger-codeBlockRevealAnimation\" data-hveid=\"0\" data-ved=\"0CAAQhtANahgKEwiQwPrR-fGQAxUAAAAAHQAAAAAQ4AI\">\n<div class=\"code-block-decoration header-formatted gds-title-s ng-tns-c4015166184-116 ng-star-inserted\"><span class=\"ng-tns-c4015166184-116\">Bash<\/span><\/p>\n<div class=\"buttons ng-tns-c4015166184-116 ng-star-inserted\"><\/div>\n<\/div>\n<div class=\"formatted-code-block-internal-container ng-tns-c4015166184-116\">\n<div class=\"animated-opacity ng-tns-c4015166184-116\">\n<pre class=\"ng-tns-c4015166184-116\"><code class=\"code-container formatted ng-tns-c4015166184-116\" role=\"text\" data-test-id=\"code-content\">sudo systemctl status nginx\r\n<\/code><\/pre>\n<\/div>\n<\/div>\n<\/div>\n<p data-path-to-node=\"21,0,2\">The output should show <code>Active: active (running)<\/code>.<\/p>\n<\/li>\n<li>\n<p data-path-to-node=\"21,1,0\"><b>Access the server:<\/b> Open your web browser and navigate to <code>http:\/\/your_vps_ip_address<\/code>. You should see the default <b>&#8220;Welcome to nginx!&#8221;<\/b> page.<\/p>\n<\/li>\n<\/ol>\n<p data-path-to-node=\"22\">\n<h2><span class=\"ez-toc-section\" id=\"Phase_2_Installing_and_Securing_MariaDB_The_Database\"><\/span>Phase 2: Installing and Securing MariaDB (The Database)<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>&nbsp;<\/p>\n<p data-path-to-node=\"23\">MariaDB is a fast, community-developed fork of MySQL. We will install it and immediately run the critical security script.<\/p>\n<p data-path-to-node=\"24\">\n<h3><span class=\"ez-toc-section\" id=\"Step_21_Install_MariaDB_Server\"><\/span>Step 2.1: Install MariaDB Server<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>&nbsp;<\/p>\n<div class=\"code-block ng-tns-c4015166184-117 ng-animate-disabled ng-trigger ng-trigger-codeBlockRevealAnimation\" data-hveid=\"0\" data-ved=\"0CAAQhtANahgKEwiQwPrR-fGQAxUAAAAAHQAAAAAQ4QI\">\n<div class=\"code-block-decoration header-formatted gds-title-s ng-tns-c4015166184-117 ng-star-inserted\"><span class=\"ng-tns-c4015166184-117\">Bash<\/span><\/p>\n<div class=\"buttons ng-tns-c4015166184-117 ng-star-inserted\"><\/div>\n<\/div>\n<div class=\"formatted-code-block-internal-container ng-tns-c4015166184-117\">\n<div class=\"animated-opacity ng-tns-c4015166184-117\">\n<pre class=\"ng-tns-c4015166184-117\"><code class=\"code-container formatted ng-tns-c4015166184-117\" role=\"text\" data-test-id=\"code-content\">sudo apt install mariadb-server mariadb-client -y\r\n<\/code><\/pre>\n<\/div>\n<\/div>\n<\/div>\n<p data-path-to-node=\"26\">\n<h3><span class=\"ez-toc-section\" id=\"Step_22_Run_the_Critical_Security_Script\"><\/span>Step 2.2: Run the Critical Security Script<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>&nbsp;<\/p>\n<p data-path-to-node=\"27\">The default MariaDB installation is insecure. This script addresses common vulnerabilities like remote root login and anonymous users. <b>Do not skip this step.<\/b><\/p>\n<div class=\"code-block ng-tns-c4015166184-118 ng-animate-disabled ng-trigger ng-trigger-codeBlockRevealAnimation\" data-hveid=\"0\" data-ved=\"0CAAQhtANahgKEwiQwPrR-fGQAxUAAAAAHQAAAAAQ4gI\">\n<div class=\"code-block-decoration header-formatted gds-title-s ng-tns-c4015166184-118 ng-star-inserted\"><span class=\"ng-tns-c4015166184-118\">Bash<\/span><\/p>\n<div class=\"buttons ng-tns-c4015166184-118 ng-star-inserted\"><\/div>\n<\/div>\n<div class=\"formatted-code-block-internal-container ng-tns-c4015166184-118\">\n<div class=\"animated-opacity ng-tns-c4015166184-118\">\n<pre class=\"ng-tns-c4015166184-118\"><code class=\"code-container formatted ng-tns-c4015166184-118\" role=\"text\" data-test-id=\"code-content\">sudo mysql_secure_installation\r\n<\/code><\/pre>\n<\/div>\n<\/div>\n<\/div>\n<p data-path-to-node=\"29\">You will be prompted to make several crucial choices:<\/p>\n<ul data-path-to-node=\"30\">\n<li>\n<p data-path-to-node=\"30,0,0\"><b>Set root password?<\/b> Choose <b>Y<\/b> and create a <b>strong, unique password<\/b>. You will rarely use this, as application users are preferred.<\/p>\n<\/li>\n<li>\n<p data-path-to-node=\"30,1,0\"><b>Remove anonymous users?<\/b> Choose <b>Y<\/b>.<\/p>\n<\/li>\n<li>\n<p data-path-to-node=\"30,2,0\"><b>Disallow root login remotely?<\/b> Choose <b>Y<\/b>. This is essential, as it prevents external login to the database as the master root user.<\/p>\n<\/li>\n<li>\n<p data-path-to-node=\"30,3,0\"><b>Remove test database and access to it?<\/b> Choose <b>Y<\/b>.<\/p>\n<\/li>\n<li>\n<p data-path-to-node=\"30,4,0\"><b>Reload privilege tables now?<\/b> Choose <b>Y<\/b>.<\/p>\n<\/li>\n<\/ul>\n<p data-path-to-node=\"31\">\n<h3><span class=\"ez-toc-section\" id=\"Step_23_Create_a_Database_and_User\"><\/span>Step 2.3: Create a Database and User<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>&nbsp;<\/p>\n<p data-path-to-node=\"32\">You should <b>never<\/b> use the database root user for your application (e.g., WordPress). Create a dedicated database and user with minimal privileges.<\/p>\n<div class=\"code-block ng-tns-c4015166184-119 ng-animate-disabled ng-trigger ng-trigger-codeBlockRevealAnimation\" data-hveid=\"0\" data-ved=\"0CAAQhtANahgKEwiQwPrR-fGQAxUAAAAAHQAAAAAQ4wI\">\n<div class=\"code-block-decoration header-formatted gds-title-s ng-tns-c4015166184-119 ng-star-inserted\"><span class=\"ng-tns-c4015166184-119\">SQL<\/span><\/p>\n<div class=\"buttons ng-tns-c4015166184-119 ng-star-inserted\"><\/div>\n<\/div>\n<div class=\"formatted-code-block-internal-container ng-tns-c4015166184-119\">\n<div class=\"animated-opacity ng-tns-c4015166184-119\">\n<pre class=\"ng-tns-c4015166184-119\"><code class=\"code-container formatted ng-tns-c4015166184-119\" role=\"text\" data-test-id=\"code-content\">sudo mysql\r\n<\/code><\/pre>\n<\/div>\n<\/div>\n<\/div>\n<p data-path-to-node=\"34\">Inside the MariaDB shell, run the following commands, replacing the bold text:<\/p>\n<div class=\"code-block ng-tns-c4015166184-120 ng-animate-disabled ng-trigger ng-trigger-codeBlockRevealAnimation\" data-hveid=\"0\" data-ved=\"0CAAQhtANahgKEwiQwPrR-fGQAxUAAAAAHQAAAAAQ5AI\">\n<div class=\"code-block-decoration header-formatted gds-title-s ng-tns-c4015166184-120 ng-star-inserted\"><span class=\"ng-tns-c4015166184-120\">SQL<\/span><\/p>\n<div class=\"buttons ng-tns-c4015166184-120 ng-star-inserted\"><\/div>\n<\/div>\n<div class=\"formatted-code-block-internal-container ng-tns-c4015166184-120\">\n<div class=\"animated-opacity ng-tns-c4015166184-120\">\n<pre class=\"ng-tns-c4015166184-120\"><code class=\"code-container formatted ng-tns-c4015166184-120\" role=\"text\" data-test-id=\"code-content\"><span class=\"hljs-keyword\">CREATE<\/span> DATABASE your_app_db_name;\r\n<span class=\"hljs-keyword\">CREATE<\/span> <span class=\"hljs-keyword\">USER<\/span> <span class=\"hljs-string\">'your_app_user'<\/span>@<span class=\"hljs-string\">'localhost'<\/span> IDENTIFIED <span class=\"hljs-keyword\">BY<\/span> <span class=\"hljs-string\">'a_very_strong_password'<\/span>;\r\n<span class=\"hljs-keyword\">GRANT<\/span> <span class=\"hljs-keyword\">ALL<\/span> PRIVILEGES <span class=\"hljs-keyword\">ON<\/span> your_app_db_name.<span class=\"hljs-operator\">*<\/span> <span class=\"hljs-keyword\">TO<\/span> <span class=\"hljs-string\">'your_app_user'<\/span>@<span class=\"hljs-string\">'localhost'<\/span> IDENTIFIED <span class=\"hljs-keyword\">BY<\/span> <span class=\"hljs-string\">'a_very_strong_password'<\/span>;\r\nFLUSH PRIVILEGES;\r\nEXIT;\r\n<\/code><\/pre>\n<\/div>\n<\/div>\n<\/div>\n<p data-path-to-node=\"36\">\n<h2><span class=\"ez-toc-section\" id=\"Phase_3_Installing_and_Configuring_PHP-FPM\"><\/span>Phase 3: Installing and Configuring PHP-FPM<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>&nbsp;<\/p>\n<p data-path-to-node=\"37\">Nginx cannot process PHP files natively. It requires <b>PHP-FPM<\/b> (FastCGI Process Manager) to handle PHP requests and pass the final HTML back to Nginx.<\/p>\n<p data-path-to-node=\"38\">\n<h3><span class=\"ez-toc-section\" id=\"Step_31_Install_PHP-FPM_and_Extensions\"><\/span>Step 3.1: Install PHP-FPM and Extensions<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>&nbsp;<\/p>\n<p data-path-to-node=\"39\">Install the core PHP-FPM package and the necessary extension to communicate with MariaDB\/MySQL:<\/p>\n<div class=\"code-block ng-tns-c4015166184-121 ng-animate-disabled ng-trigger ng-trigger-codeBlockRevealAnimation\" data-hveid=\"0\" data-ved=\"0CAAQhtANahgKEwiQwPrR-fGQAxUAAAAAHQAAAAAQ5QI\">\n<div class=\"code-block-decoration header-formatted gds-title-s ng-tns-c4015166184-121 ng-star-inserted\"><span class=\"ng-tns-c4015166184-121\">Bash<\/span><\/p>\n<div class=\"buttons ng-tns-c4015166184-121 ng-star-inserted\"><\/div>\n<\/div>\n<div class=\"formatted-code-block-internal-container ng-tns-c4015166184-121\">\n<div class=\"animated-opacity ng-tns-c4015166184-121\">\n<pre class=\"ng-tns-c4015166184-121\"><code class=\"code-container formatted ng-tns-c4015166184-121\" role=\"text\" data-test-id=\"code-content\">sudo apt install php-fpm php-mysql -y\r\n<\/code><\/pre>\n<\/div>\n<\/div>\n<\/div>\n<p data-path-to-node=\"41\">\n<h3><span class=\"ez-toc-section\" id=\"Step_32_Configure_PHP-FPM_for_Better_Security\"><\/span>Step 3.2: Configure PHP-FPM for Better Security<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>&nbsp;<\/p>\n<p data-path-to-node=\"42\">The PHP-FPM default configuration has a security setting that should be disabled for multi-site hosting. Since you&#8217;re running a single VPS, setting this is a good practice.<\/p>\n<p data-path-to-node=\"43\">Open the configuration file (version may vary, check <code>\/etc\/php\/<\/code> for your version, e.g., <code>8.3<\/code>):<\/p>\n<div class=\"code-block ng-tns-c4015166184-122 ng-animate-disabled ng-trigger ng-trigger-codeBlockRevealAnimation\" data-hveid=\"0\" data-ved=\"0CAAQhtANahgKEwiQwPrR-fGQAxUAAAAAHQAAAAAQ5gI\">\n<div class=\"code-block-decoration header-formatted gds-title-s ng-tns-c4015166184-122 ng-star-inserted\"><span class=\"ng-tns-c4015166184-122\">Bash<\/span><\/p>\n<div class=\"buttons ng-tns-c4015166184-122 ng-star-inserted\"><\/div>\n<\/div>\n<div class=\"formatted-code-block-internal-container ng-tns-c4015166184-122\">\n<div class=\"animated-opacity ng-tns-c4015166184-122\">\n<pre class=\"ng-tns-c4015166184-122\"><code class=\"code-container formatted ng-tns-c4015166184-122\" role=\"text\" data-test-id=\"code-content\">sudo nano \/etc\/php\/8.3\/fpm\/php.ini\r\n<\/code><\/pre>\n<\/div>\n<\/div>\n<\/div>\n<p data-path-to-node=\"45\">Find the line <code>;cgi.fix_pathinfo=1<\/code> and change it to:<\/p>\n<div class=\"code-block ng-tns-c4015166184-123 ng-animate-disabled ng-trigger ng-trigger-codeBlockRevealAnimation\" data-hveid=\"0\" data-ved=\"0CAAQhtANahgKEwiQwPrR-fGQAxUAAAAAHQAAAAAQ5wI\">\n<div class=\"code-block-decoration header-formatted gds-title-s ng-tns-c4015166184-123 ng-star-inserted\"><span class=\"ng-tns-c4015166184-123\">Ini, TOML<\/span><\/p>\n<div class=\"buttons ng-tns-c4015166184-123 ng-star-inserted\"><\/div>\n<\/div>\n<div class=\"formatted-code-block-internal-container ng-tns-c4015166184-123\">\n<div class=\"animated-opacity ng-tns-c4015166184-123\">\n<pre class=\"ng-tns-c4015166184-123\"><code class=\"code-container formatted ng-tns-c4015166184-123\" role=\"text\" data-test-id=\"code-content\"><span class=\"hljs-attr\">cgi.fix_pathinfo<\/span>=<span class=\"hljs-number\">0<\/span>\r\n<\/code><\/pre>\n<\/div>\n<\/div>\n<\/div>\n<p data-path-to-node=\"47\"><b>Remove the semicolon (<code>;<\/code>)<\/b> to uncomment it. This prevents Nginx from executing scripts with names that closely match a file. Save and close the file (Ctrl+X, Y, Enter).<\/p>\n<p data-path-to-node=\"48\">\n<h3><span class=\"ez-toc-section\" id=\"Step_33_Restart_PHP-FPM\"><\/span>Step 3.3: Restart PHP-FPM<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>&nbsp;<\/p>\n<p data-path-to-node=\"49\">Apply the new setting:<\/p>\n<div class=\"code-block ng-tns-c4015166184-124 ng-animate-disabled ng-trigger ng-trigger-codeBlockRevealAnimation\" data-hveid=\"0\" data-ved=\"0CAAQhtANahgKEwiQwPrR-fGQAxUAAAAAHQAAAAAQ6AI\">\n<div class=\"code-block-decoration header-formatted gds-title-s ng-tns-c4015166184-124 ng-star-inserted\"><span class=\"ng-tns-c4015166184-124\">Bash<\/span><\/p>\n<div class=\"buttons ng-tns-c4015166184-124 ng-star-inserted\"><\/div>\n<\/div>\n<div class=\"formatted-code-block-internal-container ng-tns-c4015166184-124\">\n<div class=\"animated-opacity ng-tns-c4015166184-124\">\n<pre class=\"ng-tns-c4015166184-124\"><code class=\"code-container formatted ng-tns-c4015166184-124\" role=\"text\" data-test-id=\"code-content\">sudo systemctl restart php8.3-fpm\r\n<\/code><\/pre>\n<\/div>\n<\/div>\n<\/div>\n<p data-path-to-node=\"51\">\n<h2><span class=\"ez-toc-section\" id=\"Phase_4_Nginx_Server_Block_Configuration\"><\/span>Phase 4: Nginx Server Block Configuration<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>&nbsp;<\/p>\n<p data-path-to-node=\"52\">This step tells Nginx where your website files are located and how to process the PHP files using the PHP-FPM socket.<\/p>\n<p data-path-to-node=\"53\">\n<h3><span class=\"ez-toc-section\" id=\"Step_41_Create_Web_Root_Directory\"><\/span>Step 4.1: Create Web Root Directory<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>&nbsp;<\/p>\n<p data-path-to-node=\"54\">Create a directory for your domain, replacing <code>yourdomain.net<\/code>:<\/p>\n<div class=\"code-block ng-tns-c4015166184-125 ng-animate-disabled ng-trigger ng-trigger-codeBlockRevealAnimation\" data-hveid=\"0\" data-ved=\"0CAAQhtANahgKEwiQwPrR-fGQAxUAAAAAHQAAAAAQ6QI\">\n<div class=\"code-block-decoration header-formatted gds-title-s ng-tns-c4015166184-125 ng-star-inserted\"><span class=\"ng-tns-c4015166184-125\">Bash<\/span><\/p>\n<div class=\"buttons ng-tns-c4015166184-125 ng-star-inserted\"><\/div>\n<\/div>\n<div class=\"formatted-code-block-internal-container ng-tns-c4015166184-125\">\n<div class=\"animated-opacity ng-tns-c4015166184-125\">\n<pre class=\"ng-tns-c4015166184-125\"><code class=\"code-container formatted ng-tns-c4015166184-125\" role=\"text\" data-test-id=\"code-content\">sudo mkdir -p \/var\/www\/yourdomain.net\/html\r\n<\/code><\/pre>\n<\/div>\n<\/div>\n<\/div>\n<p data-path-to-node=\"56\">Set the ownership to your non-root user (using the <code>$USER<\/code> variable) so you can manage the files:<\/p>\n<div class=\"code-block ng-tns-c4015166184-126 ng-animate-disabled ng-trigger ng-trigger-codeBlockRevealAnimation\" data-hveid=\"0\" data-ved=\"0CAAQhtANahgKEwiQwPrR-fGQAxUAAAAAHQAAAAAQ6gI\">\n<div class=\"code-block-decoration header-formatted gds-title-s ng-tns-c4015166184-126 ng-star-inserted\"><span class=\"ng-tns-c4015166184-126\">Bash<\/span><\/p>\n<div class=\"buttons ng-tns-c4015166184-126 ng-star-inserted\"><\/div>\n<\/div>\n<div class=\"formatted-code-block-internal-container ng-tns-c4015166184-126\">\n<div class=\"animated-opacity ng-tns-c4015166184-126\">\n<pre class=\"ng-tns-c4015166184-126\"><code class=\"code-container formatted ng-tns-c4015166184-126\" role=\"text\" data-test-id=\"code-content\">sudo chown -R <span class=\"hljs-variable\">$USER<\/span>:<span class=\"hljs-variable\">$USER<\/span> \/var\/www\/yourdomain.net\/html\r\n<\/code><\/pre>\n<\/div>\n<\/div>\n<\/div>\n<p data-path-to-node=\"58\">\n<h3><span class=\"ez-toc-section\" id=\"Step_42_Create_the_Nginx_Server_Block\"><\/span>Step 4.2: Create the Nginx Server Block<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>&nbsp;<\/p>\n<p data-path-to-node=\"59\">Nginx uses <b>Server Blocks<\/b> (similar to Apache Virtual Hosts). Create a new configuration file in the <code>sites-available<\/code> directory:<\/p>\n<div class=\"code-block ng-tns-c4015166184-127 ng-animate-disabled ng-trigger ng-trigger-codeBlockRevealAnimation\" data-hveid=\"0\" data-ved=\"0CAAQhtANahgKEwiQwPrR-fGQAxUAAAAAHQAAAAAQ6wI\">\n<div class=\"code-block-decoration header-formatted gds-title-s ng-tns-c4015166184-127 ng-star-inserted\"><span class=\"ng-tns-c4015166184-127\">Bash<\/span><\/p>\n<div class=\"buttons ng-tns-c4015166184-127 ng-star-inserted\"><\/div>\n<\/div>\n<div class=\"formatted-code-block-internal-container ng-tns-c4015166184-127\">\n<div class=\"animated-opacity ng-tns-c4015166184-127\">\n<pre class=\"ng-tns-c4015166184-127\"><code class=\"code-container formatted ng-tns-c4015166184-127\" role=\"text\" data-test-id=\"code-content\">sudo nano \/etc\/nginx\/sites-available\/yourdomain.net\r\n<\/code><\/pre>\n<\/div>\n<\/div>\n<\/div>\n<p data-path-to-node=\"61\">Paste the following minimal, secure configuration (replace <code>yourdomain.net<\/code> everywhere):<\/p>\n<div class=\"code-block ng-tns-c4015166184-128 ng-animate-disabled ng-trigger ng-trigger-codeBlockRevealAnimation\" data-hveid=\"0\" data-ved=\"0CAAQhtANahgKEwiQwPrR-fGQAxUAAAAAHQAAAAAQ7AI\">\n<div class=\"code-block-decoration header-formatted gds-title-s ng-tns-c4015166184-128 ng-star-inserted\"><span class=\"ng-tns-c4015166184-128\">Nginx<\/span><\/p>\n<div class=\"buttons ng-tns-c4015166184-128 ng-star-inserted\"><\/div>\n<\/div>\n<div class=\"formatted-code-block-internal-container ng-tns-c4015166184-128\">\n<div class=\"animated-opacity ng-tns-c4015166184-128\">\n<pre class=\"ng-tns-c4015166184-128\"><code class=\"code-container formatted ng-tns-c4015166184-128\" role=\"text\" data-test-id=\"code-content\"><span class=\"hljs-section\">server<\/span> {\r\n    <span class=\"hljs-attribute\">listen<\/span> <span class=\"hljs-number\">80<\/span>;\r\n    <span class=\"hljs-attribute\">listen<\/span> [::]:<span class=\"hljs-number\">80<\/span>;\r\n    <span class=\"hljs-attribute\">root<\/span> \/var\/www\/yourdomain.net\/html;\r\n    <span class=\"hljs-attribute\">index<\/span> index.php index.html index.htm;\r\n    <span class=\"hljs-attribute\">server_name<\/span> yourdomain.net www.yourdomain.net;\r\n\r\n    <span class=\"hljs-attribute\">location<\/span> \/ {\r\n        <span class=\"hljs-attribute\">try_files<\/span> $uri $uri\/ =<span class=\"hljs-number\">404<\/span>;\r\n    }\r\n\r\n    <span class=\"hljs-attribute\">location<\/span> <span class=\"hljs-regexp\">~ \\.php$<\/span> {\r\n        <span class=\"hljs-attribute\">include<\/span> snippets\/fastcgi-php.conf;\r\n        <span class=\"hljs-attribute\">fastcgi_pass<\/span> unix:\/var\/run\/php\/php8.3-fpm.sock; <span class=\"hljs-comment\"># Check your PHP version!<\/span>\r\n        <span class=\"hljs-attribute\">fastcgi_param<\/span> SCRIPT_FILENAME $document_root$fastcgi_script_name;\r\n        <span class=\"hljs-attribute\">include<\/span> fastcgi_params;\r\n    }\r\n\r\n    <span class=\"hljs-comment\"># Hide sensitive files from public access<\/span>\r\n    <span class=\"hljs-attribute\">location<\/span> <span class=\"hljs-regexp\">~ \/\\.ht<\/span> {\r\n        <span class=\"hljs-attribute\">deny<\/span> all;\r\n    }\r\n}\r\n<\/code><\/pre>\n<\/div>\n<\/div>\n<\/div>\n<p data-path-to-node=\"63\">\n<h3><span class=\"ez-toc-section\" id=\"Step_43_Enable_the_Server_Block_and_Restart_Nginx\"><\/span>Step 4.3: Enable the Server Block and Restart Nginx<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>&nbsp;<\/p>\n<ol start=\"1\" data-path-to-node=\"64\">\n<li>\n<p data-path-to-node=\"64,0,0\"><b>Create a symbolic link<\/b> to enable the site, and <b>unlink the default<\/b> config:<\/p>\n<div class=\"code-block ng-tns-c4015166184-129 ng-animate-disabled ng-trigger ng-trigger-codeBlockRevealAnimation\" data-hveid=\"0\" data-ved=\"0CAAQhtANahgKEwiQwPrR-fGQAxUAAAAAHQAAAAAQ7QI\">\n<div class=\"code-block-decoration header-formatted gds-title-s ng-tns-c4015166184-129 ng-star-inserted\"><span class=\"ng-tns-c4015166184-129\">Bash<\/span><\/p>\n<div class=\"buttons ng-tns-c4015166184-129 ng-star-inserted\"><\/div>\n<\/div>\n<div class=\"formatted-code-block-internal-container ng-tns-c4015166184-129\">\n<div class=\"animated-opacity ng-tns-c4015166184-129\">\n<pre class=\"ng-tns-c4015166184-129\"><code class=\"code-container formatted ng-tns-c4015166184-129\" role=\"text\" data-test-id=\"code-content\">sudo ln -s \/etc\/nginx\/sites-available\/yourdomain.net \/etc\/nginx\/sites-enabled\/\r\nsudo unlink \/etc\/nginx\/sites-enabled\/default\r\n<\/code><\/pre>\n<\/div>\n<\/div>\n<\/div>\n<\/li>\n<li>\n<p data-path-to-node=\"64,1,0\"><b>Test the Nginx configuration for syntax errors:<\/b><\/p>\n<div class=\"code-block ng-tns-c4015166184-130 ng-animate-disabled ng-trigger ng-trigger-codeBlockRevealAnimation\" data-hveid=\"0\" data-ved=\"0CAAQhtANahgKEwiQwPrR-fGQAxUAAAAAHQAAAAAQ7gI\">\n<div class=\"code-block-decoration header-formatted gds-title-s ng-tns-c4015166184-130 ng-star-inserted\"><span class=\"ng-tns-c4015166184-130\">Bash<\/span><\/p>\n<div class=\"buttons ng-tns-c4015166184-130 ng-star-inserted\"><\/div>\n<\/div>\n<div class=\"formatted-code-block-internal-container ng-tns-c4015166184-130\">\n<div class=\"animated-opacity ng-tns-c4015166184-130\">\n<pre class=\"ng-tns-c4015166184-130\"><code class=\"code-container formatted ng-tns-c4015166184-130\" role=\"text\" data-test-id=\"code-content\">sudo nginx -t\r\n<\/code><\/pre>\n<\/div>\n<\/div>\n<\/div>\n<p data-path-to-node=\"64,1,2\">You should see: <code>nginx: configuration file \/etc\/nginx\/nginx.conf test is successful<\/code>.<\/p>\n<\/li>\n<li>\n<p data-path-to-node=\"64,2,0\"><b>Reload Nginx<\/b> to apply the changes:<\/p>\n<div class=\"code-block ng-tns-c4015166184-131 ng-animate-disabled ng-trigger ng-trigger-codeBlockRevealAnimation\" data-hveid=\"0\" data-ved=\"0CAAQhtANahgKEwiQwPrR-fGQAxUAAAAAHQAAAAAQ7wI\">\n<div class=\"code-block-decoration header-formatted gds-title-s ng-tns-c4015166184-131 ng-star-inserted\"><span class=\"ng-tns-c4015166184-131\">Bash<\/span><\/p>\n<div class=\"buttons ng-tns-c4015166184-131 ng-star-inserted\"><\/div>\n<\/div>\n<div class=\"formatted-code-block-internal-container ng-tns-c4015166184-131\">\n<div class=\"animated-opacity ng-tns-c4015166184-131\">\n<pre class=\"ng-tns-c4015166184-131\"><code class=\"code-container formatted ng-tns-c4015166184-131\" role=\"text\" data-test-id=\"code-content\">sudo systemctl reload nginx\r\n<\/code><\/pre>\n<\/div>\n<\/div>\n<\/div>\n<\/li>\n<\/ol>\n<p data-path-to-node=\"65\">\n<h2><span class=\"ez-toc-section\" id=\"Final_Test_The_PHP_Info_File\"><\/span>Final Test: The PHP Info File<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>&nbsp;<\/p>\n<p data-path-to-node=\"66\">Create a temporary <code>info.php<\/code> file in your web root to confirm PHP is working through Nginx:<\/p>\n<div class=\"code-block ng-tns-c4015166184-132 ng-animate-disabled ng-trigger ng-trigger-codeBlockRevealAnimation\" data-hveid=\"0\" data-ved=\"0CAAQhtANahgKEwiQwPrR-fGQAxUAAAAAHQAAAAAQ8AI\">\n<div class=\"code-block-decoration header-formatted gds-title-s ng-tns-c4015166184-132 ng-star-inserted\"><span class=\"ng-tns-c4015166184-132\">Bash<\/span><\/p>\n<div class=\"buttons ng-tns-c4015166184-132 ng-star-inserted\"><\/div>\n<\/div>\n<div class=\"formatted-code-block-internal-container ng-tns-c4015166184-132\">\n<div class=\"animated-opacity ng-tns-c4015166184-132\">\n<pre class=\"ng-tns-c4015166184-132\"><code class=\"code-container formatted ng-tns-c4015166184-132\" role=\"text\" data-test-id=\"code-content\"><span class=\"hljs-built_in\">echo<\/span> <span class=\"hljs-string\">\"&lt;?php phpinfo(); ?&gt;\"<\/span> | sudo tee \/var\/www\/yourdomain.net\/html\/info.php\r\n<\/code><\/pre>\n<\/div>\n<\/div>\n<\/div>\n<p data-path-to-node=\"68\">Now, navigate to <code>http:\/\/yourdomain.net\/info.php<\/code> in your browser. If you see the detailed <b>PHP information page<\/b>, your LEMP stack is fully functional and securely configured!<\/p>\n<p data-path-to-node=\"69\"><b>Security Cleanup:<\/b> <b>Remember to immediately delete the <code>info.php<\/code> file when done testing!<\/b><\/p>\n<div class=\"code-block ng-tns-c4015166184-133 ng-animate-disabled ng-trigger ng-trigger-codeBlockRevealAnimation\" data-hveid=\"0\" data-ved=\"0CAAQhtANahgKEwiQwPrR-fGQAxUAAAAAHQAAAAAQ8QI\">\n<div class=\"code-block-decoration header-formatted gds-title-s ng-tns-c4015166184-133 ng-star-inserted\"><span class=\"ng-tns-c4015166184-133\">Bash<\/span><\/p>\n<div class=\"buttons ng-tns-c4015166184-133 ng-star-inserted\"><\/div>\n<\/div>\n<div class=\"formatted-code-block-internal-container ng-tns-c4015166184-133\">\n<div class=\"animated-opacity ng-tns-c4015166184-133\">\n<pre class=\"ng-tns-c4015166184-133\"><code class=\"code-container formatted ng-tns-c4015166184-133\" role=\"text\" data-test-id=\"code-content\">sudo rm \/var\/www\/yourdomain.net\/html\/info.php\r\n<\/code><\/pre>\n<\/div>\n<\/div>\n<\/div>\n<p data-path-to-node=\"71\">You have successfully installed and secured a high-performance LEMP stack.<\/p>\n<p>More: <a href=\"https:\/\/gratisvps.net\/blog\/the-essential-50-point-checklist-for-a-hardened-free-vps-installation\/\">https:\/\/gratisvps.net\/blog\/the-essential-50-point-checklist-for-a-hardened-free-vps-installation\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Introduction: Why LEMP Over LAMP? &nbsp; For a low-resource or free VPS hosting environment, choosing the right software stack is [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":1017,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[378,379],"tags":[387,380,382,381,383,386,385,384],"class_list":["post-1016","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-lemp","category-stack","tag-free-vps-configuration","tag-lemp-stack","tag-mariadb-install","tag-nginx-tutorial","tag-php-fpm-setup","tag-secure-database","tag-server-stack","tag-vps-hosting-tutorial"],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v27.4 (Yoast SEO v27.9) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>Install &amp; Secure the LEMP Stack (Nginx, MySQL, PHP) on Your Hardened Linux VPS<\/title>\n<meta name=\"description\" content=\"Deploy the high-performance LEMP stack on your free VPS. Follow our step-by-step guide to install Nginx, secure MariaDB with the installation script, and configure PHP-FPM for optimal speed and security.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/gratisvps.net\/blog\/install-secure-the-lemp-stack-nginx-mysql-php-on-your-hardened-linux-vps\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Install &amp; Secure the LEMP Stack (Nginx, MySQL, PHP) on Your Hardened Linux VPS\" \/>\n<meta property=\"og:description\" content=\"Deploy the high-performance LEMP stack on your free VPS. Follow our step-by-step guide to install Nginx, secure MariaDB with the installation script, and configure PHP-FPM for optimal speed and security.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/gratisvps.net\/blog\/install-secure-the-lemp-stack-nginx-mysql-php-on-your-hardened-linux-vps\/\" \/>\n<meta property=\"og:site_name\" content=\"Free VPS Hosting Guides\" \/>\n<meta property=\"article:published_time\" content=\"2025-11-14T15:49:48+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/gratisvps.net\/blog\/wp-content\/uploads\/2025\/11\/lemp-stack.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"628\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"ariete\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"ariete\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/gratisvps.net\\\/blog\\\/install-secure-the-lemp-stack-nginx-mysql-php-on-your-hardened-linux-vps\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/gratisvps.net\\\/blog\\\/install-secure-the-lemp-stack-nginx-mysql-php-on-your-hardened-linux-vps\\\/\"},\"author\":{\"name\":\"ariete\",\"@id\":\"https:\\\/\\\/gratisvps.net\\\/blog\\\/#\\\/schema\\\/person\\\/cddcf8cb5192d0713c19b79425c77fc4\"},\"headline\":\"Install &#038; Secure the LEMP Stack (Nginx, MySQL, PHP) on Your Hardened Linux VPS\",\"datePublished\":\"2025-11-14T15:49:48+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/gratisvps.net\\\/blog\\\/install-secure-the-lemp-stack-nginx-mysql-php-on-your-hardened-linux-vps\\\/\"},\"wordCount\":790,\"publisher\":{\"@id\":\"https:\\\/\\\/gratisvps.net\\\/blog\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/gratisvps.net\\\/blog\\\/install-secure-the-lemp-stack-nginx-mysql-php-on-your-hardened-linux-vps\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/gratisvps.net\\\/blog\\\/wp-content\\\/uploads\\\/2025\\\/11\\\/lemp-stack.png\",\"keywords\":[\"free VPS configuration\",\"LEMP stack\",\"MariaDB install\",\"Nginx tutorial\",\"PHP-FPM setup\",\"secure database\",\"server stack\",\"VPS hosting tutorial\"],\"articleSection\":[\"LEMP\",\"Stack\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/gratisvps.net\\\/blog\\\/install-secure-the-lemp-stack-nginx-mysql-php-on-your-hardened-linux-vps\\\/\",\"url\":\"https:\\\/\\\/gratisvps.net\\\/blog\\\/install-secure-the-lemp-stack-nginx-mysql-php-on-your-hardened-linux-vps\\\/\",\"name\":\"Install & Secure the LEMP Stack (Nginx, MySQL, PHP) on Your Hardened Linux VPS\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/gratisvps.net\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/gratisvps.net\\\/blog\\\/install-secure-the-lemp-stack-nginx-mysql-php-on-your-hardened-linux-vps\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/gratisvps.net\\\/blog\\\/install-secure-the-lemp-stack-nginx-mysql-php-on-your-hardened-linux-vps\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/gratisvps.net\\\/blog\\\/wp-content\\\/uploads\\\/2025\\\/11\\\/lemp-stack.png\",\"datePublished\":\"2025-11-14T15:49:48+00:00\",\"description\":\"Deploy the high-performance LEMP stack on your free VPS. Follow our step-by-step guide to install Nginx, secure MariaDB with the installation script, and configure PHP-FPM for optimal speed and security.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/gratisvps.net\\\/blog\\\/install-secure-the-lemp-stack-nginx-mysql-php-on-your-hardened-linux-vps\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/gratisvps.net\\\/blog\\\/install-secure-the-lemp-stack-nginx-mysql-php-on-your-hardened-linux-vps\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/gratisvps.net\\\/blog\\\/install-secure-the-lemp-stack-nginx-mysql-php-on-your-hardened-linux-vps\\\/#primaryimage\",\"url\":\"https:\\\/\\\/gratisvps.net\\\/blog\\\/wp-content\\\/uploads\\\/2025\\\/11\\\/lemp-stack.png\",\"contentUrl\":\"https:\\\/\\\/gratisvps.net\\\/blog\\\/wp-content\\\/uploads\\\/2025\\\/11\\\/lemp-stack.png\",\"width\":1200,\"height\":628,\"caption\":\"LEMP Stack\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/gratisvps.net\\\/blog\\\/install-secure-the-lemp-stack-nginx-mysql-php-on-your-hardened-linux-vps\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/gratisvps.net\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Install &#038; Secure the LEMP Stack (Nginx, MySQL, PHP) on Your Hardened Linux VPS\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/gratisvps.net\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/gratisvps.net\\\/blog\\\/\",\"name\":\"Gratisvps.net | Blog Daily Tech Info\",\"description\":\"GratisVPS.NET\",\"publisher\":{\"@id\":\"https:\\\/\\\/gratisvps.net\\\/blog\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/gratisvps.net\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/gratisvps.net\\\/blog\\\/#organization\",\"name\":\"Gratisvps.net | Blog Daily Tech Info\",\"url\":\"https:\\\/\\\/gratisvps.net\\\/blog\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/gratisvps.net\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/gratisvps.net\\\/blog\\\/wp-content\\\/uploads\\\/2024\\\/10\\\/logo.png\",\"contentUrl\":\"https:\\\/\\\/gratisvps.net\\\/blog\\\/wp-content\\\/uploads\\\/2024\\\/10\\\/logo.png\",\"width\":250,\"height\":67,\"caption\":\"Gratisvps.net | Blog Daily Tech Info\"},\"image\":{\"@id\":\"https:\\\/\\\/gratisvps.net\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/gratisvps.net\\\/blog\\\/#\\\/schema\\\/person\\\/cddcf8cb5192d0713c19b79425c77fc4\",\"name\":\"ariete\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/b93881052caa63fd6b2fb5468a80afcf9f985a165c6d4de11a72cc4c0775f74a?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/b93881052caa63fd6b2fb5468a80afcf9f985a165c6d4de11a72cc4c0775f74a?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/b93881052caa63fd6b2fb5468a80afcf9f985a165c6d4de11a72cc4c0775f74a?s=96&d=mm&r=g\",\"caption\":\"ariete\"},\"sameAs\":[\"https:\\\/\\\/gratisvps.net\\\/blog\"],\"url\":\"https:\\\/\\\/gratisvps.net\\\/blog\\\/author\\\/ariete\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Install & Secure the LEMP Stack (Nginx, MySQL, PHP) on Your Hardened Linux VPS","description":"Deploy the high-performance LEMP stack on your free VPS. Follow our step-by-step guide to install Nginx, secure MariaDB with the installation script, and configure PHP-FPM for optimal speed and security.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/gratisvps.net\/blog\/install-secure-the-lemp-stack-nginx-mysql-php-on-your-hardened-linux-vps\/","og_locale":"en_US","og_type":"article","og_title":"Install & Secure the LEMP Stack (Nginx, MySQL, PHP) on Your Hardened Linux VPS","og_description":"Deploy the high-performance LEMP stack on your free VPS. Follow our step-by-step guide to install Nginx, secure MariaDB with the installation script, and configure PHP-FPM for optimal speed and security.","og_url":"https:\/\/gratisvps.net\/blog\/install-secure-the-lemp-stack-nginx-mysql-php-on-your-hardened-linux-vps\/","og_site_name":"Free VPS Hosting Guides","article_published_time":"2025-11-14T15:49:48+00:00","og_image":[{"width":1200,"height":628,"url":"https:\/\/gratisvps.net\/blog\/wp-content\/uploads\/2025\/11\/lemp-stack.png","type":"image\/png"}],"author":"ariete","twitter_card":"summary_large_image","twitter_misc":{"Written by":"ariete","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/gratisvps.net\/blog\/install-secure-the-lemp-stack-nginx-mysql-php-on-your-hardened-linux-vps\/#article","isPartOf":{"@id":"https:\/\/gratisvps.net\/blog\/install-secure-the-lemp-stack-nginx-mysql-php-on-your-hardened-linux-vps\/"},"author":{"name":"ariete","@id":"https:\/\/gratisvps.net\/blog\/#\/schema\/person\/cddcf8cb5192d0713c19b79425c77fc4"},"headline":"Install &#038; Secure the LEMP Stack (Nginx, MySQL, PHP) on Your Hardened Linux VPS","datePublished":"2025-11-14T15:49:48+00:00","mainEntityOfPage":{"@id":"https:\/\/gratisvps.net\/blog\/install-secure-the-lemp-stack-nginx-mysql-php-on-your-hardened-linux-vps\/"},"wordCount":790,"publisher":{"@id":"https:\/\/gratisvps.net\/blog\/#organization"},"image":{"@id":"https:\/\/gratisvps.net\/blog\/install-secure-the-lemp-stack-nginx-mysql-php-on-your-hardened-linux-vps\/#primaryimage"},"thumbnailUrl":"https:\/\/gratisvps.net\/blog\/wp-content\/uploads\/2025\/11\/lemp-stack.png","keywords":["free VPS configuration","LEMP stack","MariaDB install","Nginx tutorial","PHP-FPM setup","secure database","server stack","VPS hosting tutorial"],"articleSection":["LEMP","Stack"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/gratisvps.net\/blog\/install-secure-the-lemp-stack-nginx-mysql-php-on-your-hardened-linux-vps\/","url":"https:\/\/gratisvps.net\/blog\/install-secure-the-lemp-stack-nginx-mysql-php-on-your-hardened-linux-vps\/","name":"Install & Secure the LEMP Stack (Nginx, MySQL, PHP) on Your Hardened Linux VPS","isPartOf":{"@id":"https:\/\/gratisvps.net\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/gratisvps.net\/blog\/install-secure-the-lemp-stack-nginx-mysql-php-on-your-hardened-linux-vps\/#primaryimage"},"image":{"@id":"https:\/\/gratisvps.net\/blog\/install-secure-the-lemp-stack-nginx-mysql-php-on-your-hardened-linux-vps\/#primaryimage"},"thumbnailUrl":"https:\/\/gratisvps.net\/blog\/wp-content\/uploads\/2025\/11\/lemp-stack.png","datePublished":"2025-11-14T15:49:48+00:00","description":"Deploy the high-performance LEMP stack on your free VPS. Follow our step-by-step guide to install Nginx, secure MariaDB with the installation script, and configure PHP-FPM for optimal speed and security.","breadcrumb":{"@id":"https:\/\/gratisvps.net\/blog\/install-secure-the-lemp-stack-nginx-mysql-php-on-your-hardened-linux-vps\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/gratisvps.net\/blog\/install-secure-the-lemp-stack-nginx-mysql-php-on-your-hardened-linux-vps\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/gratisvps.net\/blog\/install-secure-the-lemp-stack-nginx-mysql-php-on-your-hardened-linux-vps\/#primaryimage","url":"https:\/\/gratisvps.net\/blog\/wp-content\/uploads\/2025\/11\/lemp-stack.png","contentUrl":"https:\/\/gratisvps.net\/blog\/wp-content\/uploads\/2025\/11\/lemp-stack.png","width":1200,"height":628,"caption":"LEMP Stack"},{"@type":"BreadcrumbList","@id":"https:\/\/gratisvps.net\/blog\/install-secure-the-lemp-stack-nginx-mysql-php-on-your-hardened-linux-vps\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/gratisvps.net\/blog\/"},{"@type":"ListItem","position":2,"name":"Install &#038; Secure the LEMP Stack (Nginx, MySQL, PHP) on Your Hardened Linux VPS"}]},{"@type":"WebSite","@id":"https:\/\/gratisvps.net\/blog\/#website","url":"https:\/\/gratisvps.net\/blog\/","name":"Gratisvps.net | Blog Daily Tech Info","description":"GratisVPS.NET","publisher":{"@id":"https:\/\/gratisvps.net\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/gratisvps.net\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/gratisvps.net\/blog\/#organization","name":"Gratisvps.net | Blog Daily Tech Info","url":"https:\/\/gratisvps.net\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/gratisvps.net\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/gratisvps.net\/blog\/wp-content\/uploads\/2024\/10\/logo.png","contentUrl":"https:\/\/gratisvps.net\/blog\/wp-content\/uploads\/2024\/10\/logo.png","width":250,"height":67,"caption":"Gratisvps.net | Blog Daily Tech Info"},"image":{"@id":"https:\/\/gratisvps.net\/blog\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/gratisvps.net\/blog\/#\/schema\/person\/cddcf8cb5192d0713c19b79425c77fc4","name":"ariete","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/b93881052caa63fd6b2fb5468a80afcf9f985a165c6d4de11a72cc4c0775f74a?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/b93881052caa63fd6b2fb5468a80afcf9f985a165c6d4de11a72cc4c0775f74a?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/b93881052caa63fd6b2fb5468a80afcf9f985a165c6d4de11a72cc4c0775f74a?s=96&d=mm&r=g","caption":"ariete"},"sameAs":["https:\/\/gratisvps.net\/blog"],"url":"https:\/\/gratisvps.net\/blog\/author\/ariete\/"}]}},"_links":{"self":[{"href":"https:\/\/gratisvps.net\/blog\/wp-json\/wp\/v2\/posts\/1016","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/gratisvps.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/gratisvps.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/gratisvps.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/gratisvps.net\/blog\/wp-json\/wp\/v2\/comments?post=1016"}],"version-history":[{"count":1,"href":"https:\/\/gratisvps.net\/blog\/wp-json\/wp\/v2\/posts\/1016\/revisions"}],"predecessor-version":[{"id":1018,"href":"https:\/\/gratisvps.net\/blog\/wp-json\/wp\/v2\/posts\/1016\/revisions\/1018"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/gratisvps.net\/blog\/wp-json\/wp\/v2\/media\/1017"}],"wp:attachment":[{"href":"https:\/\/gratisvps.net\/blog\/wp-json\/wp\/v2\/media?parent=1016"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/gratisvps.net\/blog\/wp-json\/wp\/v2\/categories?post=1016"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/gratisvps.net\/blog\/wp-json\/wp\/v2\/tags?post=1016"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}