How to Install a LAMP Stack on Your VPS (2025 Guide)

How to Install a LAMP Stack on Your VPS (2025 Guide)

A LAMP stack is a group of open-source software typically used to get web servers up and running. The acronym stands for Linux, Apache, MySQL, and PHP. Here is a step-by-step guide to installing a LAMP stack on your Virtual Private Server (VPS) as of 2025:

Step 1: Access Your VPS

  • SSH into Your VPS: Use an SSH client to connect to your VPS. You will need your server’s IP address, SSH port, and root credentials.
    ssh root@your_server_ip
    

Step 2: Update Your System

  • Update Package Lists: Before installing any software, it’s a good practice to update your package lists.
    sudo apt update
    
  • Upgrade Packages: Optionally, you can upgrade all your system software to the latest versions.
    sudo apt upgrade
    

Step 3: Install Apache

  • Install Apache2: Apache is the most widely used web server software.
    sudo apt install apache2
    
  • Adjust Firewall: Ensure that your firewall allows HTTP and HTTPS traffic.
    sudo ufw allow in "Apache Full"
    

Step 4: Install MySQL (MariaDB)

  • Install MySQL: As of 2025, MariaDB is often preferred over MySQL due to its open-source nature, but both function similarly.
    sudo apt install mariadb-server
    
  • Secure MySQL: Run the mysql_secure_installation script to secure your database server.
    sudo mysql_secure_installation
    

    Follow the prompts to set a root password, remove anonymous users, restrict root user access to the local machine, and remove the test database.

Step 5: Install PHP

  • Install PHP: PHP is a server-side scripting language designed for web development.
    sudo apt install php libapache2-mod-php php-mysql
    
  • PHP Modules: Install additional PHP modules based on your needs.
    sudo apt install php-cli php-fpm php-json php-common php-mysql php-zip php-gd php-mbstring php-curl php-xml php-pear php-bcmath
    

Step 6: Test Apache

  • Check Apache: Ensure Apache is running.
    sudo systemctl status apache2
    
  • Access Default Page: Open your web browser and navigate to http://your_server_ip/. You should see the default Apache2 Ubuntu Default Page.

Step 7: Test PHP

  • Create PHP File: Create a simple PHP file to test PHP processing on your Apache server.
    echo "<?php phpinfo(); ?>" | sudo tee /var/www/html/info.php
    
  • Access PHP Page: In your web browser, go to http://your_server_ip/info.php. You should see a page displaying information about your PHP configuration.

Step 8: Configure MySQL (MariaDB)

  • Login to MySQL: Log into the MySQL shell.
    sudo mysql
    
  • Create Database and User: Optionally, you can create a database and a user for your applications.
    CREATE DATABASE exampledb;
    CREATE USER 'exampleuser'@'localhost' IDENTIFIED BY 'password';
    GRANT ALL PRIVILEGES ON exampledb.* TO 'exampleuser'@'localhost';
    FLUSH PRIVILEGES;
    EXIT;
    

Step 9: Secure Your System

  • Regular Updates: Keep your system secure by regularly updating all software.
  • Backup Configurations: Regularly back up your configurations and databases.

Step 10: Additional Configurations

  • Tune Apache and PHP: Adjust configurations in Apache and PHP to optimize performance and security based on your specific needs.

Installing a LAMP stack on your VPS equips you with the essential software needed to host dynamic websites and web applications. This setup forms the backbone for many popular CMSes like WordPress, Drupal, and Joomla, and is known for its robustness, flexibility, and customization capabilities.

Hot this week

From $200 to $199: How Tremhost Beats Cloudflare’s Own Pricing Model

Cloudflare’s Business Plan is legendary. It includes enterprise-grade features...

Cheaper Than Cloudflare Itself? How Tremhost Bundles World-Class Security for Less

When it comes to website performance and protection, Cloudflare...

The World’s Cheapest Fully Managed Cloudflare Security—And Why Competitors Don’t Want You to Know

Let’s be real: big hosting providers make their money...

Africa’s Best-Kept Secret: Tremhost + Cloudflare = World-Class Security at Local Prices

Across Africa, businesses face the same cyber threats as...

From Downtime to Peace of Mind: Affordable Cloudflare DDoS Protection with Tremhost

Every minute your website is down costs money. Whether...

Topics

From $200 to $199: How Tremhost Beats Cloudflare’s Own Pricing Model

Cloudflare’s Business Plan is legendary. It includes enterprise-grade features...

Cheaper Than Cloudflare Itself? How Tremhost Bundles World-Class Security for Less

When it comes to website performance and protection, Cloudflare...

From Downtime to Peace of Mind: Affordable Cloudflare DDoS Protection with Tremhost

Every minute your website is down costs money. Whether...

The World’s Cheapest Managed Cloudflare Hosting? Tremhost Just Did It

Cloudflare is the name everyone trusts for DDoS protection,...

Cloudflare Protection Without the Global Price Tag: Tremhost Shows How

Cloudflare is known worldwide for delivering enterprise-grade website security...

How Tremhost Makes Enterprise-Grade Cloudflare Protection Affordable for Startups

Every startup has the same dream—scale fast, win customers,...
spot_img

Related Articles

Popular Categories

spot_imgspot_img