{"id":2722,"date":"2025-01-29T23:53:20","date_gmt":"2024-11-17T11:43:10","guid":{"rendered":""},"modified":"2025-02-02T00:46:19","modified_gmt":"2025-02-01T23:46:19","slug":"how-to-install-lemp-stack-linux-nginx-php-mariadb-on-ubuntu-24-04","status":"publish","type":"post","link":"https:\/\/netcloud24.com\/knowledgebase\/how-to-install-lemp-stack-linux-nginx-php-mariadb-on-ubuntu-24-04\/","title":{"rendered":"Linux VPS &#038; VPS Windows Setup Guide | NetCloud24 LEMP Stack (Linux, Nginx, PHP, MariaDB) on Ubuntu 24.04"},"content":{"rendered":"<p>\u00a0<\/p>\n<\/p>\n<header>\n<h1>\u00a0<\/h1>\n<\/header>\n<article>\n<p>The <strong>LEMP stack<\/strong> (Linux, Nginx, MariaDB, PHP) is a popular stack for hosting web applications. It offers high performance and flexibility, making it a preferred choice for developers looking to build fast, scalable websites. In this guide, we\u2019ll show you how to install the LEMP stack on <strong>Ubuntu 24.04<\/strong>. For optimal performance and scalability, it\u2019s recommended to host your LEMP stack on a . Using a <strong>VPS server<\/strong> ensures you have dedicated resources to manage web traffic and provide a smooth user experience.<\/p>\n<h2>Step 1: Update Your VPS Server<\/h2>\n<p>Before starting the installation, make sure your <a href=\"https:\/\/ie.netcloud24.com\">VPS server<\/a> is updated with the latest packages. Run the following commands to update your system:<\/p>\n<pre><code>sudo apt update &amp;&amp; sudo apt upgrade -y<\/code><\/pre>\n<p>Using a <strong>Windows VPS<\/strong> ensures your LEMP stack runs in a high-performance environment with dedicated resources for maximum reliability and speed.<\/p>\n<h2>Step 2: Install Nginx<\/h2>\n<p><strong>Nginx<\/strong> is a high-performance web server that will handle HTTP requests and serve your website content. Install Nginx using the following command:<\/p>\n<pre><code>sudo apt install nginx -y<\/code><\/pre>\n<p>Once installed, start and enable Nginx to run at boot:<\/p>\n<pre><code>sudo systemctl enable nginx --now<\/code><\/pre>\n<p>To verify Nginx is working, open your browser and visit <code>http:\/\/your-server-ip<\/code>. You should see the default Nginx welcome page.<\/p>\n<h2>Step 3: Install MariaDB<\/h2>\n<p><strong>MariaDB<\/strong> is an open-source database management system that is a drop-in replacement for MySQL. Install MariaDB using the following command:<\/p>\n<pre><code>sudo apt install mariadb-server -y<\/code><\/pre>\n<p>After installation, secure MariaDB by running the following command:<\/p>\n<pre><code>sudo mysql_secure_installation<\/code><\/pre>\n<p>This script will guide you through setting up a root password, removing anonymous users, disabling remote root login, and other security measures. Follow the prompts to complete the setup.<\/p>\n<h2>Step 4: Install PHP<\/h2>\n<p><strong>PHP<\/strong> is a server-side scripting language that works with Nginx and MariaDB to serve dynamic web content. Install PHP and the necessary PHP extensions for LEMP:<\/p>\n<pre><code>\r\nsudo apt install php-fpm php-mysql php-cli php-xml php-mbstring php-json php-curl php-zip -y\r\n<\/code><\/pre>\n<p>PHP-FPM (FastCGI Process Manager) will be used to handle PHP requests in Nginx.<\/p>\n<h2>Step 5: Configure Nginx to Use PHP<\/h2>\n<p>Now that PHP is installed, configure Nginx to process PHP files. Open the default Nginx server block configuration file:<\/p>\n<pre><code>sudo nano \/etc\/nginx\/sites-available\/default<\/code><\/pre>\n<p>Find the section that starts with <code>location ~ \\.php$ {<\/code> and update it to look like this:<\/p>\n<pre><code>\r\nlocation ~ \\.php$ {\r\n    include snippets\/fastcgi-php.conf;\r\n    fastcgi_pass unix:\/var\/run\/php\/php-fpm.sock;\r\n    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;\r\n    include fastcgi_params;\r\n}\r\n<\/code><\/pre>\n<p>Also, ensure that the index directive includes <code>index.php<\/code> so Nginx prioritizes PHP files:<\/p>\n<pre><code>\r\nindex index.php index.html index.htm;\r\n<\/code><\/pre>\n<p>Save the file and exit the text editor. Now restart Nginx and PHP-FPM to apply the changes:<\/p>\n<pre><code>\r\nsudo systemctl restart nginx\r\nsudo systemctl restart php-fpm\r\n<\/code><\/pre>\n<h2>Step 6: Test PHP with Nginx<\/h2>\n<p>To confirm that PHP is working with Nginx, create a PHP test file. Navigate to the web root directory:<\/p>\n<pre><code>cd \/var\/www\/html<\/code><\/pre>\n<p>Create a file called <code>info.php<\/code>:<\/p>\n<pre><code>sudo nano info.php<\/code><\/pre>\n<p>Add the following code to the file:<\/p>\n<pre><code>\r\n&lt;?php\r\nphpinfo();\r\n?&gt;\r\n<\/code><\/pre>\n<p>Save and close the file. Now, open your web browser and navigate to <code>http:\/\/your-server-ip\/info.php<\/code>. You should see the PHP information page, which confirms that PHP is correctly configured.<\/p>\n<h2>Step 7: Secure MariaDB and Create a Database<\/h2>\n<p>Log in to the MariaDB shell to create a database and secure your installation:<\/p>\n<pre><code>sudo mysql -u root -p<\/code><\/pre>\n<p>After entering the MariaDB shell, create a new database for your website:<\/p>\n<pre><code>\r\nCREATE DATABASE lemp_db;\r\nCREATE USER 'lemp_user'@'localhost' IDENTIFIED BY 'your_password';\r\nGRANT ALL PRIVILEGES ON lemp_db.* TO 'lemp_user'@'localhost';\r\nFLUSH PRIVILEGES;\r\nEXIT;\r\n<\/code><\/pre>\n<p>Make sure to replace <code>your_password<\/code> with a strong password. This database will be used to store data for your web applications.<\/p>\n<h2>Step 8: Optimize Your VPS Server for LEMP<\/h2>\n<p>To get the most out of your LEMP stack, hosting it on a  is recommended. A <strong>VPS server<\/strong> provides dedicated resources, allowing you to handle high traffic, serve dynamic content, and ensure fast load times for your websites. A VPS gives you the control and flexibility needed to optimize your environment for maximum performance.<\/p>\n<h2>Conclusion<\/h2>\n<p>Installing the LEMP stack on Ubuntu 24.04 provides a powerful, high-performance platform for building and hosting websites. By hosting your LEMP stack on a , you can take advantage of better performance, scalability, and control, ensuring your server can handle increased traffic and provide a seamless experience for users.<\/p>\n<p>For more information on VPS hosting and optimizing your LEMP stack, visit  today.<\/p>\n<\/article>\n<footer>\n<p>\u00a9 2024 Windows VPS &#8211; All Rights Reserved<\/p>\n<\/footer>\n<div class=\"post-author-box\" style=\"border-top:1px solid #ddd;margin-top:20px;padding-top:15px;\">\n<p><strong>Author:<\/strong> \u0141ukasz Bodziony<\/p>\n<p><strong>Website:<\/strong> <a href=\"https:\/\/ca.netcloud24.com\" target=\"_blank\" rel=\"dofollow\">Windows VPS<\/a><\/p>\n<p><em>\u0141ukasz Bodziony is the CEO and founder of <a href=\"https:\/\/netcloud24.com\" target=\"_blank\" rel=\"dofollow\">NETCLOUD24<\/a>, a global VPS hosting brand proudly originating from Poland. With extensive experience in cloud computing, virtualization, and server management, he delivers high-performance <strong>Windows VPS<\/strong> and <strong>Remote Desktop Services (RDS)<\/strong> solutions to clients across Europe, North America, and beyond.<\/em><\/p>\n<p><em>His expertise covers a wide range of technologies, including <strong>Microsoft Azure<\/strong>, <strong>Proxmox VE<\/strong>, <strong>Amazon Web Services (AWS)<\/strong>, and numerous other virtualization and cloud platforms.<\/em><\/p>\n<p><em>Beyond running his hosting business, \u0141ukasz also provides <strong>professional paid server configuration and optimization services<\/strong> for companies and individuals. Outside of work, he is dedicated to caring for his children and building a secure future for them.<\/em><\/p>\n<p><em>If you are interested in working with him or need expert assistance with your hosting, cloud environment, or server setup, feel free to reach out via <a href=\"https:\/\/ca.netcloud24.com\" target=\"_blank\" rel=\"dofollow\">Windows VPS<\/a>.<\/em><\/p>\n<\/p><\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u00a0 \u00a0 The LEMP stack (Linux, Nginx, MariaDB, PHP) is a popular stack for hosting web applications. It offers high performance and flexibility, making it a preferred choice\u2026<\/p>\n","protected":false},"author":1,"featured_media":3421,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_seopress_robots_primary_cat":"","_seopress_titles_title":"","_seopress_titles_desc":"","_seopress_robots_index":"","footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[],"tags":[14,12,11,23,20,21,22,17,7,8,6,10,18,19,15,24,16,5,13,9],"class_list":["post-2722","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","tag-cheapvps","tag-cloudvps","tag-hostingvps","tag-rds","tag-rdscal","tag-remotedesktop","tag-remotedesktopvps","tag-servervps","tag-ukvps","tag-virtualserver","tag-vpshosting","tag-vpsserver","tag-vpssolutions","tag-vpswindows","tag-vpswithwindows","tag-windowsrds","tag-windowsserver","tag-windowsvps","tag-windowsvpshosting","tag-windowsvpsuk"],"jetpack_publicize_connections":[],"_links":{"self":[{"href":"https:\/\/netcloud24.com\/knowledgebase\/wp-json\/wp\/v2\/posts\/2722","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/netcloud24.com\/knowledgebase\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/netcloud24.com\/knowledgebase\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/netcloud24.com\/knowledgebase\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/netcloud24.com\/knowledgebase\/wp-json\/wp\/v2\/comments?post=2722"}],"version-history":[{"count":0,"href":"https:\/\/netcloud24.com\/knowledgebase\/wp-json\/wp\/v2\/posts\/2722\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/netcloud24.com\/knowledgebase\/wp-json\/wp\/v2\/media\/3421"}],"wp:attachment":[{"href":"https:\/\/netcloud24.com\/knowledgebase\/wp-json\/wp\/v2\/media?parent=2722"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/netcloud24.com\/knowledgebase\/wp-json\/wp\/v2\/categories?post=2722"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/netcloud24.com\/knowledgebase\/wp-json\/wp\/v2\/tags?post=2722"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}