Setting Up a LAMP Stack on Your VPS

Published on
June 1, 2024

Overview

A LAMP stack is a software stack that consists of Linux,Apache, MySQL, and PHP. It's a popular choice for hosting websites and web applicationsdue to its robustness and flexibility. This guide will show you how to set up aLAMP stack on your Virtual Private Server (VPS) provided by HSJ.HOST, enablingyou to deploy dynamic websites and web applications.


Prerequisites

  • A VPS account with HSJ.HOST.
  • SSH access to your server.
  • Basic knowledge of the Linux command line.


Procedure

1. Access Your VPS via SSH

  • Initiate an SSH connection to your server: ssh user@your_vps_ip, replacing user with your username and your_vps_ip with your server's IP address.
       
       

2. Update Your Server's Package List

  • Run sudo  apt update to ensure your package list is current, followed by sudo  apt upgrade to upgrade all your installed packages to their latest versions.
       
       

3. Install Apache

  • Install Apache2 web server:
       
       

code

sudo apt install apache2

  • Once installed, enable and start the Apache2 service:
       
       

bash code

sudo systemctl enable apache2 sudo systemctl start apache2

  • Verify that Apache2 is running by accessing your server's IP address in a web browser. You should see the Apache2 Ubuntu default page.
       
       

4. Install MySQL

  • Install MySQL server:
       
       

code

sudo apt install mysql-server

  • Secure your MySQL installation (it will prompt you to set a root password and make other security-related choices):
       
       

code

sudo mysql_secure_installation

  • Log  into the MySQL root administrative account:
       
       

css code

sudo mysql -u root -p

  • You can create a new database and user, and grant privileges as needed for your web applications.
       
       

5. Install PHP

  • Install     PHP and the PHP extension for MySQL:
       
       

code

sudo apt install php libapache2-mod-php php-mysql

  • To verify PHP is installed, you can check its version:
       
       

code

php -v

6. Configure Apache to Use PHP

  • By default, Apache should automatically handle PHP files using the libapache2-mod-php module. You can test this by creating a PHP file in the web root directory:
       
       

Php code

echo "<?php phpinfo(); ?>" | sudo tee/var/www/html/phpinfo.php

  • Navigate to http://your_vps_ip/phpinfo.php in a web browser. You should see a page displaying information about your PHP configuration.
       
       

7. Finalise the LAMP Stack Installation

  • Ensure all services are running and will start on boot:
       
       

bash code

sudo systemctl enable apache2 sudo systemctl enable mysql

  • Your LAMP stack is now fully operational. You can begin deploying your PHP applications and using MySQL databases.
       
       

Conclusion

You've successfully set up a LAMP stack on your VPS withHSJ.HOST. This setup forms the backbone for hosting a wide range of webapplications, from simple websites to complex web platforms. With Apacheserving your content, MySQL storing your data, and PHP providing server-sidescripting, you're well-equipped to start developing and deploying dynamic webapplications.

Join our newsletter

Unlock Exclusive Offers Subscribe to Our Newsletter!

Thank you! Your submission has been received!
Oops! Something went wrong while submitting the form.