{"id":1018,"date":"2024-12-02T13:36:20","date_gmt":"2024-12-02T13:36:20","guid":{"rendered":"https:\/\/vpswebhostingindia.in\/blog\/?p=1018"},"modified":"2024-12-02T13:36:22","modified_gmt":"2024-12-02T13:36:22","slug":"how-to-install-and-configure-lamp-stack","status":"publish","type":"post","link":"https:\/\/vpswebhostingindia.in\/blog\/how-to-install-and-configure-lamp-stack\/","title":{"rendered":"How to Install and Configure a LAMP Stack on a VPS &#8211; Step by Step Guide"},"content":{"rendered":"\n<p>LAMP stack (Linux, Apache, MySQL, PHP) is one of the most popular web server setups used to host dynamic websites and web applications. In this guide, we\u2019ll walk you through the process of installing and configuring a LAMP stack on a VPS, step by step.<\/p>\n\n\n\n<div class=\"wp-block-rank-math-toc-block\" id=\"rank-math-toc\"><h2>Table of Contents<\/h2><nav><ul><li><a href=\"#what-is-a-lamp-stack\">What is a LAMP Stack?<\/a><\/li><li><a href=\"#prerequisites\">Prerequisites<\/a><\/li><li><a href=\"#step-by-step-to-install-and-configure-a-lamp-stack-on-a-vps\">Step by step to Install and Configure a LAMP Stack on a VPS<\/a><ul><li><a href=\"#step-1-update-your-server\">Step 1: Update Your Server<\/a><\/li><li><a href=\"#step-2-install-apache\">Step 2: Install Apache<\/a><\/li><li><a href=\"#step-3-install-my-sql\">Step 3: Install MySQL<\/a><\/li><li><a href=\"#secure-my-sql\">Secure MySQL<\/a><\/li><li><a href=\"#step-4-install-php\">Step 4: Install PHP<\/a><\/li><li><a href=\"#step-6-configure-firewall-optional\">Step 6: Configure Firewall (Optional)<\/a><\/li><\/ul><\/li><li><a href=\"#conclusion\">Conclusion<\/a><\/li><\/ul><\/nav><\/div>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"what-is-a-lamp-stack\">What is a LAMP Stack?<\/h2>\n\n\n\n<p>A LAMP stack is a collection of open-source software that works together to deliver web applications:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Linux<\/strong>: The operating system.<\/li>\n\n\n\n<li><strong>Apache<\/strong>: The web server that handles HTTP requests.<\/li>\n\n\n\n<li><strong>MySQL<\/strong>: The database management system to store and retrieve data.<\/li>\n\n\n\n<li><strong>PHP<\/strong>: The programming language that generates dynamic content.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"prerequisites\">Prerequisites<\/h2>\n\n\n\n<p>Before we begin, make sure:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>You have a <a href=\"https:\/\/vpswebhostingindia.in\/\">VPS<\/a> running a Linux distribution (Ubuntu, CentOS, Debian, etc.).<\/li>\n\n\n\n<li>You have SSH access to the VPS with a user that has <code>sudo<\/code> privileges.<\/li>\n\n\n\n<li>Your VPS has a domain name or IP address that you can use to access the server.<\/li>\n<\/ol>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"step-by-step-to-install-and-configure-a-lamp-stack-on-a-vps\">Step by step to Install and Configure a LAMP Stack on a VPS<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"step-1-update-your-server\">Step 1: Update Your Server<\/h3>\n\n\n\n<p>Before installing any packages, update the package index and upgrade the installed packages to the latest versions.<\/p>\n\n\n\n<p class=\"has-black-color has-cyan-bluish-gray-background-color has-text-color has-background has-link-color wp-elements-f41d68ea98faa8867e1299e1cba786cf\">sudo apt update &amp;&amp; sudo apt upgrade -y # For Ubuntu\/Debian<br>sudo yum update -y # For CentOS\/RHEL<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"912\" height=\"355\" src=\"https:\/\/vpswebhostingindia.in\/blog\/wp-content\/uploads\/2024\/12\/image-1.png\" alt=\"LAMP Stack\" class=\"wp-image-1019\" srcset=\"https:\/\/vpswebhostingindia.in\/blog\/wp-content\/uploads\/2024\/12\/image-1.png 912w, https:\/\/vpswebhostingindia.in\/blog\/wp-content\/uploads\/2024\/12\/image-1-300x117.png 300w, https:\/\/vpswebhostingindia.in\/blog\/wp-content\/uploads\/2024\/12\/image-1-768x299.png 768w\" sizes=\"auto, (max-width: 912px) 100vw, 912px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"648\" src=\"https:\/\/vpswebhostingindia.in\/blog\/wp-content\/uploads\/2024\/12\/image-3-1024x648.png\" alt=\"\" class=\"wp-image-1021\" srcset=\"https:\/\/vpswebhostingindia.in\/blog\/wp-content\/uploads\/2024\/12\/image-3-1024x648.png 1024w, https:\/\/vpswebhostingindia.in\/blog\/wp-content\/uploads\/2024\/12\/image-3-300x190.png 300w, https:\/\/vpswebhostingindia.in\/blog\/wp-content\/uploads\/2024\/12\/image-3-768x486.png 768w, https:\/\/vpswebhostingindia.in\/blog\/wp-content\/uploads\/2024\/12\/image-3.png 1155w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>Press &#8216;Y&#8217;<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"step-2-install-apache\">Step 2: Install Apache<\/h3>\n\n\n\n<p><a href=\"https:\/\/www.apache.org\/\" rel=\"nofollow noopener\" target=\"_blank\">Apache<\/a> is the web server that will serve your website\u2019s files to visitors.<\/p>\n\n\n\n<p class=\"has-black-color has-cyan-bluish-gray-background-color has-text-color has-background has-link-color wp-elements-9d23f1fac4d7d925537355c71829c563\">sudo apt install apache2 -y<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"317\" src=\"https:\/\/vpswebhostingindia.in\/blog\/wp-content\/uploads\/2024\/12\/image-5-1024x317.png\" alt=\"\" class=\"wp-image-1023\" srcset=\"https:\/\/vpswebhostingindia.in\/blog\/wp-content\/uploads\/2024\/12\/image-5-1024x317.png 1024w, https:\/\/vpswebhostingindia.in\/blog\/wp-content\/uploads\/2024\/12\/image-5-300x93.png 300w, https:\/\/vpswebhostingindia.in\/blog\/wp-content\/uploads\/2024\/12\/image-5-768x238.png 768w, https:\/\/vpswebhostingindia.in\/blog\/wp-content\/uploads\/2024\/12\/image-5.png 1227w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p><strong>Start and Enable Apache<\/strong>.<\/p>\n\n\n\n<p>Start the Apache service and enable it to start on boot.<\/p>\n\n\n\n<p class=\"has-black-color has-cyan-bluish-gray-background-color has-text-color has-background has-link-color wp-elements-f6f54cec08f5aaa260f68e0677ff1493\">sudo systemctl start apache2 # For Ubuntu\/Debian<br>sudo systemctl enable apache2<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"147\" src=\"https:\/\/vpswebhostingindia.in\/blog\/wp-content\/uploads\/2024\/12\/image-6-1024x147.png\" alt=\"\" class=\"wp-image-1024\" srcset=\"https:\/\/vpswebhostingindia.in\/blog\/wp-content\/uploads\/2024\/12\/image-6-1024x147.png 1024w, https:\/\/vpswebhostingindia.in\/blog\/wp-content\/uploads\/2024\/12\/image-6-300x43.png 300w, https:\/\/vpswebhostingindia.in\/blog\/wp-content\/uploads\/2024\/12\/image-6-768x110.png 768w, https:\/\/vpswebhostingindia.in\/blog\/wp-content\/uploads\/2024\/12\/image-6.png 1462w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p><strong>Verify Apache Installation<\/strong><\/p>\n\n\n\n<p>Visit your server\u2019s IP address in a web browser to check if Apache is running:<\/p>\n\n\n\n<p class=\"has-black-color has-cyan-bluish-gray-background-color has-text-color has-background has-link-color wp-elements-292dfe4c2ce1e9cd574f1370d79ef756\">http:\/\/your-server-ip<\/p>\n\n\n\n<p>You should see the Apache default welcome page.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"678\" src=\"https:\/\/vpswebhostingindia.in\/blog\/wp-content\/uploads\/2024\/12\/image-7-1024x678.png\" alt=\"\" class=\"wp-image-1026\" srcset=\"https:\/\/vpswebhostingindia.in\/blog\/wp-content\/uploads\/2024\/12\/image-7-1024x678.png 1024w, https:\/\/vpswebhostingindia.in\/blog\/wp-content\/uploads\/2024\/12\/image-7-300x199.png 300w, https:\/\/vpswebhostingindia.in\/blog\/wp-content\/uploads\/2024\/12\/image-7-768x509.png 768w, https:\/\/vpswebhostingindia.in\/blog\/wp-content\/uploads\/2024\/12\/image-7-1536x1018.png 1536w, https:\/\/vpswebhostingindia.in\/blog\/wp-content\/uploads\/2024\/12\/image-7.png 1553w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"step-3-install-my-sql\"><strong>Step 3: Install MySQL<\/strong><\/h3>\n\n\n\n<p><a href=\"https:\/\/www.mysql.com\/\" rel=\"nofollow noopener\" target=\"_blank\">MySQL<\/a> is the database system used to store and manage data.<\/p>\n\n\n\n<p class=\"has-black-color has-cyan-bluish-gray-background-color has-text-color has-background has-link-color wp-elements-dfd43f2ee871eaeae180d8d46700bce2\">sudo apt install mysql-server -y<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"656\" src=\"https:\/\/vpswebhostingindia.in\/blog\/wp-content\/uploads\/2024\/12\/image-8-1024x656.png\" alt=\"\" class=\"wp-image-1027\" srcset=\"https:\/\/vpswebhostingindia.in\/blog\/wp-content\/uploads\/2024\/12\/image-8-1024x656.png 1024w, https:\/\/vpswebhostingindia.in\/blog\/wp-content\/uploads\/2024\/12\/image-8-300x192.png 300w, https:\/\/vpswebhostingindia.in\/blog\/wp-content\/uploads\/2024\/12\/image-8-768x492.png 768w, https:\/\/vpswebhostingindia.in\/blog\/wp-content\/uploads\/2024\/12\/image-8.png 1248w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p><strong>Start and Enable MySQL<\/strong><\/p>\n\n\n\n<p>Start the MySQL service and enable it to start on boot.<\/p>\n\n\n\n<p class=\"has-black-color has-cyan-bluish-gray-background-color has-text-color has-background has-link-color wp-elements-fc3aa423a15b92dd19bb32ac5b8ad7f5\">sudo systemctl start mysql <br>sudo systemctl enable mysql<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"176\" src=\"https:\/\/vpswebhostingindia.in\/blog\/wp-content\/uploads\/2024\/12\/image-10-1024x176.png\" alt=\"\" class=\"wp-image-1029\" srcset=\"https:\/\/vpswebhostingindia.in\/blog\/wp-content\/uploads\/2024\/12\/image-10-1024x176.png 1024w, https:\/\/vpswebhostingindia.in\/blog\/wp-content\/uploads\/2024\/12\/image-10-300x52.png 300w, https:\/\/vpswebhostingindia.in\/blog\/wp-content\/uploads\/2024\/12\/image-10-768x132.png 768w, https:\/\/vpswebhostingindia.in\/blog\/wp-content\/uploads\/2024\/12\/image-10-1536x264.png 1536w, https:\/\/vpswebhostingindia.in\/blog\/wp-content\/uploads\/2024\/12\/image-10.png 1552w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"secure-my-sql\">Secure MySQL<\/h3>\n\n\n\n<p>Run the <code>mysql_secure_installation<\/code> script to secure your MySQL installation:<\/p>\n\n\n\n<p class=\"has-black-color has-cyan-bluish-gray-background-color has-text-color has-background has-link-color wp-elements-532122a97570126dd4eb6bfbea6e24d9\">sudo mysql_secure_installation<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"742\" height=\"249\" src=\"https:\/\/vpswebhostingindia.in\/blog\/wp-content\/uploads\/2024\/12\/image-11.png\" alt=\"\" class=\"wp-image-1030\" srcset=\"https:\/\/vpswebhostingindia.in\/blog\/wp-content\/uploads\/2024\/12\/image-11.png 742w, https:\/\/vpswebhostingindia.in\/blog\/wp-content\/uploads\/2024\/12\/image-11-300x101.png 300w\" sizes=\"auto, (max-width: 742px) 100vw, 742px\" \/><\/figure>\n\n\n\n<p>You will be prompted to:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Set a root password.<\/li>\n\n\n\n<li>Remove anonymous users.<\/li>\n\n\n\n<li>Disallow root login remotely.<\/li>\n\n\n\n<li>Remove the test database.<\/li>\n\n\n\n<li>Reload privilege tables.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"step-4-install-php\">Step 4: Install PHP<\/h3>\n\n\n\n<p><a href=\"https:\/\/www.php.net\/\" rel=\"nofollow noopener\" target=\"_blank\">PHP<\/a> is the programming language that generates dynamic content for your website.<\/p>\n\n\n\n<p class=\"has-black-color has-cyan-bluish-gray-background-color has-text-color has-background has-link-color wp-elements-6cbcd648c9f375e7a67a219f88011601\">sudo apt install php libapache2-mod-php php-mysql -y<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"971\" height=\"164\" src=\"https:\/\/vpswebhostingindia.in\/blog\/wp-content\/uploads\/2024\/12\/image-12.png\" alt=\"\" class=\"wp-image-1031\" srcset=\"https:\/\/vpswebhostingindia.in\/blog\/wp-content\/uploads\/2024\/12\/image-12.png 971w, https:\/\/vpswebhostingindia.in\/blog\/wp-content\/uploads\/2024\/12\/image-12-300x51.png 300w, https:\/\/vpswebhostingindia.in\/blog\/wp-content\/uploads\/2024\/12\/image-12-768x130.png 768w\" sizes=\"auto, (max-width: 971px) 100vw, 971px\" \/><\/figure>\n\n\n\n<p><strong>Restart Apache<\/strong><\/p>\n\n\n\n<p>Restart Apache to apply the changes.<\/p>\n\n\n\n<p class=\"has-black-color has-cyan-bluish-gray-background-color has-text-color has-background has-link-color wp-elements-94a38e313a48000d6e78dd470cd9f613\">sudo systemctl restart apache2<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"677\" height=\"130\" src=\"https:\/\/vpswebhostingindia.in\/blog\/wp-content\/uploads\/2024\/12\/image-13.png\" alt=\"\" class=\"wp-image-1032\" srcset=\"https:\/\/vpswebhostingindia.in\/blog\/wp-content\/uploads\/2024\/12\/image-13.png 677w, https:\/\/vpswebhostingindia.in\/blog\/wp-content\/uploads\/2024\/12\/image-13-300x58.png 300w\" sizes=\"auto, (max-width: 677px) 100vw, 677px\" \/><\/figure>\n\n\n\n<p><strong>Step 5: Test PHP<\/strong><\/p>\n\n\n\n<p>Create a PHP test file to verify that PHP is working correctly with Apache.<\/p>\n\n\n\n<p class=\"has-black-color has-cyan-bluish-gray-background-color has-text-color has-background has-link-color wp-elements-f59b5fe40b938e42ebddb3a08fee4083\">sudo nano \/var\/www\/html\/info.php<\/p>\n\n\n\n<p>Add the following code:<\/p>\n\n\n\n<p class=\"has-black-color has-cyan-bluish-gray-background-color has-text-color has-background has-link-color wp-elements-a2348300fbba26c40b5902547053ecf3\">&lt;?php<br>phpinfo():<br>?><\/p>\n\n\n\n<p>Save the file and exit.<\/p>\n\n\n\n<p>Visit the file in your web browser:<\/p>\n\n\n\n<p class=\"has-black-color has-cyan-bluish-gray-background-color has-text-color has-background has-link-color wp-elements-51a01e5a8db8e661ffdfb7bb3ca969da\">http:\/\/your-server-ip\/info.php<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"806\" height=\"481\" src=\"https:\/\/vpswebhostingindia.in\/blog\/wp-content\/uploads\/2024\/12\/image-14.png\" alt=\"\" class=\"wp-image-1034\" srcset=\"https:\/\/vpswebhostingindia.in\/blog\/wp-content\/uploads\/2024\/12\/image-14.png 806w, https:\/\/vpswebhostingindia.in\/blog\/wp-content\/uploads\/2024\/12\/image-14-300x179.png 300w, https:\/\/vpswebhostingindia.in\/blog\/wp-content\/uploads\/2024\/12\/image-14-768x458.png 768w\" sizes=\"auto, (max-width: 806px) 100vw, 806px\" \/><\/figure>\n\n\n\n<p>You should see a PHP information page displaying the PHP configuration.<\/p>\n\n\n\n<p><strong>Important:<\/strong> After testing, remove the <code>info.php<\/code> file to avoid exposing sensitive information.<\/p>\n\n\n\n<p class=\"has-black-color has-cyan-bluish-gray-background-color has-text-color has-background has-link-color wp-elements-d4be39f1a9a890e2b869f0b38c17c239\">sudo rm \/var\/www\/html\/info.php<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"step-6-configure-firewall-optional\">Step 6: Configure Firewall (Optional)<\/h3>\n\n\n\n<p>Ensure that HTTP and HTTPS traffic is allowed through the firewall.<\/p>\n\n\n\n<p class=\"has-black-color has-cyan-bluish-gray-background-color has-text-color has-background has-link-color wp-elements-9942d74050717e29ddef7b3ee905b18a\">sudo ufw allow &#8216;Apache Full&#8217;<br>sudo ufw enable<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"723\" src=\"https:\/\/vpswebhostingindia.in\/blog\/wp-content\/uploads\/2024\/12\/image-15-1024x723.png\" alt=\"\" class=\"wp-image-1035\" srcset=\"https:\/\/vpswebhostingindia.in\/blog\/wp-content\/uploads\/2024\/12\/image-15-1024x723.png 1024w, https:\/\/vpswebhostingindia.in\/blog\/wp-content\/uploads\/2024\/12\/image-15-300x212.png 300w, https:\/\/vpswebhostingindia.in\/blog\/wp-content\/uploads\/2024\/12\/image-15-768x543.png 768w, https:\/\/vpswebhostingindia.in\/blog\/wp-content\/uploads\/2024\/12\/image-15.png 1441w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"conclusion\">Conclusion<\/h2>\n\n\n\n<p>Congratulations! You have successfully installed and configured a LAMP stack on your VPS. With this setup, you can now host dynamic websites and web applications.<\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>LAMP stack (Linux, Apache, MySQL, PHP) is one of the most popular web server setups used to host dynamic websites and web applications. In this guide, we\u2019ll walk you through the process of installing and configuring a LAMP stack on a VPS, step by step. What is a LAMP Stack? A LAMP stack is a [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":1036,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"rank_math_lock_modified_date":false,"_eb_attr":"","footnotes":""},"categories":[17,37,33],"tags":[],"class_list":["post-1018","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-vps","category-linux","category-php"],"_links":{"self":[{"href":"https:\/\/vpswebhostingindia.in\/blog\/wp-json\/wp\/v2\/posts\/1018","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/vpswebhostingindia.in\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/vpswebhostingindia.in\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/vpswebhostingindia.in\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/vpswebhostingindia.in\/blog\/wp-json\/wp\/v2\/comments?post=1018"}],"version-history":[{"count":1,"href":"https:\/\/vpswebhostingindia.in\/blog\/wp-json\/wp\/v2\/posts\/1018\/revisions"}],"predecessor-version":[{"id":1037,"href":"https:\/\/vpswebhostingindia.in\/blog\/wp-json\/wp\/v2\/posts\/1018\/revisions\/1037"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/vpswebhostingindia.in\/blog\/wp-json\/wp\/v2\/media\/1036"}],"wp:attachment":[{"href":"https:\/\/vpswebhostingindia.in\/blog\/wp-json\/wp\/v2\/media?parent=1018"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/vpswebhostingindia.in\/blog\/wp-json\/wp\/v2\/categories?post=1018"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/vpswebhostingindia.in\/blog\/wp-json\/wp\/v2\/tags?post=1018"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}