How to Install and Configure a LAMP Stack on a VPS – Step by Step Guide

LAMP stack

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’ll 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 collection of open-source software that works together to deliver web applications:

  • Linux: The operating system.
  • Apache: The web server that handles HTTP requests.
  • MySQL: The database management system to store and retrieve data.
  • PHP: The programming language that generates dynamic content.

Prerequisites

Before we begin, make sure:

  1. You have a VPS running a Linux distribution (Ubuntu, CentOS, Debian, etc.).
  2. You have SSH access to the VPS with a user that has sudo privileges.
  3. Your VPS has a domain name or IP address that you can use to access the server.

Step by step to Install and Configure a LAMP Stack on a VPS

Step 1: Update Your Server

Before installing any packages, update the package index and upgrade the installed packages to the latest versions.

LAMP Stack

Press ‘Y’

Step 2: Install Apache

Apache is the web server that will serve your website’s files to visitors.

Start and Enable Apache.

Start the Apache service and enable it to start on boot.

Verify Apache Installation

Visit your server’s IP address in a web browser to check if Apache is running:

You should see the Apache default welcome page.

Step 3: Install MySQL

MySQL is the database system used to store and manage data.

Start and Enable MySQL

Start the MySQL service and enable it to start on boot.

Secure MySQL

Run the mysql_secure_installation script to secure your MySQL installation:

You will be prompted to:

  • Set a root password.
  • Remove anonymous users.
  • Disallow root login remotely.
  • Remove the test database.
  • Reload privilege tables.

Step 4: Install PHP

PHP is the programming language that generates dynamic content for your website.

Restart Apache

Restart Apache to apply the changes.

Step 5: Test PHP

Create a PHP test file to verify that PHP is working correctly with Apache.

Add the following code:

Save the file and exit.

Visit the file in your web browser:

You should see a PHP information page displaying the PHP configuration.

Important: After testing, remove the info.php file to avoid exposing sensitive information.

Step 6: Configure Firewall (Optional)

Ensure that HTTP and HTTPS traffic is allowed through the firewall.

Conclusion

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.

Leave a Reply

Your email address will not be published. Required fields are marked *