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
sudo apt update
sudo apt install apache2 -yCentOS / AlmaLinux
sudo dnf install httpd -y
sudo systemctl start httpd
sudo systemctl enable httpdVerify Apache Is Running
sudo systemctl status apache2 # Ubuntu/Debian
sudo systemctl status httpd # CentOS/AlmaLinuxOpen your browser and navigate to http://203.0.113.10. You should see the default Apache welcome page.
Allow HTTP/HTTPS Through the Firewall
# 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 --reloadStep 2 — Install MySQL (or MariaDB)
Ubuntu / Debian
sudo apt install mysql-server -yOr install MariaDB (a drop-in MySQL replacement):
sudo apt install mariadb-server -yCentOS / AlmaLinux
sudo dnf install mariadb-server -y
sudo systemctl start mariadb
sudo systemctl enable mariadbSecure the Installation
Run the security script to set a root password and remove insecure defaults:
sudo mysql_secure_installationWhen prompted:
Verify MySQL/MariaDB
sudo mysql -u root -pEnter your password. You should see the MySQL or MariaDB prompt. Type exit to leave.
Step 3 — Install PHP
Ubuntu / Debian
sudo apt install php libapache2-mod-php php-mysql php-cli php-common php-mbstring php-xml php-curl php-zip php-gd -yCentOS / AlmaLinux
sudo dnf install php php-mysqlnd php-cli php-common php-mbstring php-xml php-curl php-zip php-gd -yVerify PHP
Create a test file:
echo "<?php phpinfo(); ?>" | sudo tee /var/www/html/info.phpVisit 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:
sudo rm /var/www/html/info.phpStep 4 — Configure Apache for PHP
By default, Apache serves index.html before index.php. To prioritize PHP files, edit the directory index configuration:
sudo nano /etc/apache2/mods-enabled/dir.conf # Ubuntu/DebianMove index.php to the first position:
<IfModule mod_dir.c>
DirectoryIndex index.php index.html index.cgi index.pl index.xhtml index.htm
</IfModule>Restart Apache:
sudo systemctl restart apache2 # Ubuntu/Debian
sudo systemctl restart httpd # CentOS/AlmaLinuxStep 5 — Set Up a Virtual Host (Optional)
To host a website on a custom domain, create a virtual host configuration:
Ubuntu / Debian
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.confAdd the following:
<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:
sudo a2ensite example.com.conf
sudo a2dissite 000-default.conf
sudo systemctl reload apache2CentOS / AlmaLinux
sudo mkdir -p /var/www/example.com/public_html
sudo nano /etc/httpd/conf.d/example.com.confAdd a similar <VirtualHost> block and restart:
sudo systemctl restart httpdStep 6 — Create a Test Page
Create a simple PHP file to verify the full stack:
sudo nano /var/www/example.com/public_html/index.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:
# Ubuntu/Debian sudo a2enmod rewrite sudo systemctl restart apache2
CentOS/AlmaLinux — mod_rewrite is enabled by default
Ensure your virtual host allows .htaccess overrides:
<Directory /var/www/example.com/public_html>
AllowOverride All
</Directory>Security Recommendations
After installing the LAMP stack:
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.