Skip to main contentSkip to navigation
[email protected]
Client AreaSupport
Hosting Mammoth
HostingMammothYour Data, Our Responsibility
Home
Solutions
Hosting Services
Store
Pricing
About
Blog
API
Contact

Stay Ahead of the Curve

Get the latest insights on cybersecurity, AI innovations, and enterprise data solutions delivered to your inbox.

Hosting Mammoth
HostingMammothEnterprise Solutions

Enterprise-grade data solutions. Hosting, recovery, cybersecurity, and AI-powered services for businesses worldwide.

[email protected]
Sun - Fri, 9:00am - 5:00pm

Services

  • Cloud Hosting
  • Data Recovery
  • Cybersecurity
  • Legal Support
  • MSP Services
  • Web Development
  • AI Services
  • Free Server Migration

Hosting

  • VPS Hosting (NVMe SSD)
  • VDS Hosting (NVMe)
  • Storage VPS (High SSD)
  • GPU Servers
  • Managed Services
  • Cloud Firewall
  • Load Balancer
  • One-Click Apps
  • n8n Hosting
  • Object Storage
  • FAQ

Company

  • Store
  • Pricing
  • About Us
  • Locations
  • Blog
  • Testimonials
  • Contact
  • Affiliate Program
  • White-Label
  • Terms of Service
  • Privacy Policy
  • Browser Cookies
  • SLA

Support

  • Client Area
  • Submit Ticket
  • Knowledge Base
  • Server Status
  • API Documentation

© 2026 Hosting Mammoth. All rights reserved.

Knowledge Base
Getting StartedAccount ManagementVPS HostingGPU ServersStorage VPSCloud FirewallLoad BalancerServer ManagementBilling & PaymentsSupport & TicketsAffiliate ProgramReseller ProgramMarketplace & Appsn8n HostingManaged ServicesServer MigrationAPI & DevelopersSecurityTroubleshootingGlossaryInstall Guides
  1. Home
  2. /
  3. Support
  4. /
  5. Server Management
  6. /
  7. Install Lamp Stack
GUIDEServer Management

Installing LAMP Stack on Your VPS

5 min read

The LAMP stack — Linux, Apache, MySQL, and PHP — is one of the most popular web server environments for hosting websites and web applications. Since your Data Mammoth VPS already runs Linux, this guide walks you through installing Apache, MySQL (or MariaDB), and PHP to complete the stack.

Prerequisites

  • A Data Mammoth VPS running Ubuntu 22.04/24.04, Debian 12, or CentOS/AlmaLinux.
  • SSH access with sudo privileges. See the initial setup guides for Ubuntu, Debian, or CentOS/AlmaLinux.
  • A domain name pointing to your server (optional but recommended).

Step 1 — Install Apache

Ubuntu / Debian

bash
sudo apt update
sudo apt install apache2 -y

CentOS / AlmaLinux

bash
sudo dnf install httpd -y
sudo systemctl start httpd
sudo systemctl enable httpd

Verify Apache Is Running

bash
sudo systemctl status apache2   # Ubuntu/Debian
sudo systemctl status httpd     # CentOS/AlmaLinux

Open your browser and navigate to http://203.0.113.10. You should see the default Apache welcome page.

Allow HTTP/HTTPS Through the Firewall

bash
# Ubuntu/Debian (UFW)
sudo ufw allow 'Apache Full'

CentOS/AlmaLinux (firewalld)

sudo firewall-cmd --permanent --add-service=http sudo firewall-cmd --permanent --add-service=https sudo firewall-cmd --reload

Step 2 — Install MySQL (or MariaDB)

Ubuntu / Debian

bash
sudo apt install mysql-server -y

Or install MariaDB (a drop-in MySQL replacement):

bash
sudo apt install mariadb-server -y

CentOS / AlmaLinux

bash
sudo dnf install mariadb-server -y
sudo systemctl start mariadb
sudo systemctl enable mariadb

Secure the Installation

Run the security script to set a root password and remove insecure defaults:

bash
sudo mysql_secure_installation

When prompted:

  • Set root password — Enter a strong password.
  • Remove anonymous users — Yes.
  • Disallow root login remotely — Yes.
  • Remove test database — Yes.
  • Reload privilege tables — Yes.
  • Verify MySQL/MariaDB

    bash
    sudo mysql -u root -p

    Enter your password. You should see the MySQL or MariaDB prompt. Type exit to leave.

    Step 3 — Install PHP

    Ubuntu / Debian

    bash
    sudo apt install php libapache2-mod-php php-mysql php-cli php-common php-mbstring php-xml php-curl php-zip php-gd -y

    CentOS / AlmaLinux

    bash
    sudo dnf install php php-mysqlnd php-cli php-common php-mbstring php-xml php-curl php-zip php-gd -y

    Verify PHP

    Create a test file:

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

    Visit http://203.0.113.10/info.php in your browser. You should see the PHP information page.

    Important: Remove this file after testing, as it exposes sensitive server information:

    bash
    sudo rm /var/www/html/info.php

    Step 4 — Configure Apache for PHP

    By default, Apache serves index.html before index.php. To prioritize PHP files, edit the directory index configuration:

    bash
    sudo nano /etc/apache2/mods-enabled/dir.conf   # Ubuntu/Debian

    Move index.php to the first position:

    text
    <IfModule mod_dir.c>
        DirectoryIndex index.php index.html index.cgi index.pl index.xhtml index.htm
    </IfModule>

    Restart Apache:

    bash
    sudo systemctl restart apache2   # Ubuntu/Debian
    sudo systemctl restart httpd     # CentOS/AlmaLinux

    Step 5 — Set Up a Virtual Host (Optional)

    To host a website on a custom domain, create a virtual host configuration:

    Ubuntu / Debian

    bash
    sudo mkdir -p /var/www/example.com/public_html
    sudo chown -R $USER:$USER /var/www/example.com
    sudo nano /etc/apache2/sites-available/example.com.conf

    Add the following:

    apache
    <VirtualHost *:80>
        ServerAdmin [email protected]
        ServerName example.com
        ServerAlias www.example.com
        DocumentRoot /var/www/example.com/public_html
        ErrorLog ${APACHE_LOG_DIR}/example.com-error.log
        CustomLog ${APACHE_LOG_DIR}/example.com-access.log combined
    </VirtualHost>

    Enable the site and disable the default:

    bash
    sudo a2ensite example.com.conf
    sudo a2dissite 000-default.conf
    sudo systemctl reload apache2

    CentOS / AlmaLinux

    bash
    sudo mkdir -p /var/www/example.com/public_html
    sudo nano /etc/httpd/conf.d/example.com.conf

    Add a similar <VirtualHost> block and restart:

    bash
    sudo systemctl restart httpd

    Step 6 — Create a Test Page

    Create a simple PHP file to verify the full stack:

    bash
    sudo nano /var/www/example.com/public_html/index.php
    php
    <!DOCTYPE html>
    <html>
    <head><title>LAMP Stack Test</title></head>
    <body>
    <h1>LAMP Stack is working</h1>
    <?php
    echo "<p>PHP Version: " . phpversion() . "</p>";

    $conn = new mysqli("localhost", "root", "your_password"); if ($conn->connect_error) { echo "<p>Database connection failed.</p>"; } else { echo "<p>Database connection successful.</p>"; } $conn->close(); ?> </body> </html>

    Visit your domain in a browser to verify everything works.

    Step 7 — Enable mod_rewrite

    Many PHP applications (like WordPress) require Apache's mod_rewrite module:

    bash
    # Ubuntu/Debian
    sudo a2enmod rewrite
    sudo systemctl restart apache2

    CentOS/AlmaLinux — mod_rewrite is enabled by default

    Ensure your virtual host allows .htaccess overrides:

    apache
    <Directory /var/www/example.com/public_html>
        AllowOverride All
    </Directory>

    Security Recommendations

    After installing the LAMP stack:

  • Install an SSL certificate — Use Let's Encrypt for free HTTPS. See SSL/TLS Certificates — Setup & Renewal.
  • Configure a firewall — Ensure only ports 80, 443, and 22 are open. See Server Firewall Hardening Guide.
  • Set strong database passwords — Never use default or weak credentials.
  • Keep software updated — Regularly run system updates.
  • Remove test files — Delete info.php and any test pages.
  • What to Do Next

    • SSL/TLS Certificates — Setup & Renewal — Secure your site with HTTPS.
    • Installing WordPress from the Marketplace — Deploy WordPress on your LAMP stack.
    • Server Firewall Hardening Guide — Lock down your server.
    • Backup Strategy — Snapshots, Offsite, Automated — Protect your data.

    Was this article helpful?

    ← Back to Server ManagementBrowse all categories →

    Still have questions?

    Contact Support →Submit a Ticket