TemperStack
Intermediate12 min readUpdated Mar 13, 2026

How to deploy a LAMP stack on Contabo

Quick Answer

Contabo offers pre-configured LAMP instances for beginners, 90-second Cloud-Init automation for speed, or manual installation on Debian 11. Use apt to install Apache, add Sury PHP repo for PHP 8.1 extensions, and MariaDB with secure setup. Test with a simple PHP info page and configure firewall for HTTP/HTTPS.

Prerequisites

  1. Contabo VPS/VDS with Debian 11 or Ubuntu 20.04/22.04 and root SSH access
  2. SSH client like PuTTY or terminal
  3. Basic Linux command line knowledge
  4. At least 1GB RAM (Contabo's basic VPS works)
  5. Optional: Domain pointed to server IP
1

Log into Contabo Dashboard

Access your Contabo Dashboard using your email and password, then navigate to VPS/VDS management for new instance creation or reinstallation.
2

Choose Pre-Configured LAMP (Beginners)

During instance creation or in the reinstallation panel, select the LAMP stack as your pre-installed configuration to get Apache, PHP 8.1, and MariaDB ready instantly without manual steps.
Tip
Recommended for beginners; server is usable immediately after setup.
3

Update System Packages (Manual/Cloud-Init Base)

SSH into your Debian 11 server as root and run:

apt update && apt upgrade -y
This ensures latest packages before installing LAMP components.

4

Install Apache and Base Packages

Install Apache web server and dependencies:

apt-get install software-properties-common wget curl apache2 -y
Apache will start automatically; verify with your server IP in a browser showing the default page.

Tip
Check status with systemctl status apache2.
5

Add PHP 8.1 Repository

Add the Sury PHP repository (critical for PHP 8.1):

curl -sSL https://packages.sury.org/php/README.txt | sudo bash -x
This enables modern PHP versions beyond default apt repos.

Tip
Watch for GPG key warnings; they are normal.
6

Install PHP 8.1 and Extensions

Install PHP 8.1 with essential modules for web apps:

apt-get install php8.1 php8.1-cli php8.1-common php8.1-curl php8.1-gd php8.1-intl php8.1-mbstring php8.1-mysql php8.1-opcache php8.1-readline php8.1-xml php8.1-xsl php8.1-zip php8.1-bz2 libapache2-mod-php8.1 -y
Restart Apache: service apache2 restart.

Tip
Test PHP with php -v and create /var/www/html/info.php with <?php phpinfo(); ?>.
7

Install and Secure MariaDB

Install MariaDB server:

apt install mariadb-server mariadb-client -y && mysql_secure_installation
Set root password during prompts, remove anonymous users, and disallow remote root login for security. Reload grants: mysqladmin reload.

Tip
Access DB with mysql -u root -p using your set password.
8

Configure Firewall

Enable UFW if active and allow web traffic:

sudo ufw allow 80/tcp
sudo ufw allow 443/tcp
sudo ufw enable
This permits HTTP/HTTPS without exposing other ports.

9

Set Up Cloud-Init Automation (Advanced)

For 90-second deploys on new instances, create this config in Contabo Dashboard:

#cloud-config
package_update: true
package_upgrade: true
packages:
- software-properties-common
- wget
- curl
- apache2
runcmd:
- curl -sSL https://packages.sury.org/php/README.txt | sudo bash -x
- sudo apt-get install php8.1 php8.1-cli php8.1-common php8.1-curl php8.1-gd php8.1-intl php8.1-mbstring php8.1-mysql php8.1-opcache php8.1-readline php8.1-xml php8.1-xsl php8.1-zip php8.1-bz2 libapache2-mod-php8.1 -y
- service apache2 restart
- apt install mariadb-server mariadb-client -y
- pw=$(openssl rand -base64 18); mysqladmin -u root -h localhost password "$pw"; echo "mysql_password=$pw" >> /home/mysql_access.txt
- mysqladmin reload
Check /home/mysql_access.txt for auto-generated password.

Tip
Ideal for scaling multiple servers.
10

Create First Website Directory

Set up virtual host structure:

mkdir -p /var/www/example.com/public_html
mkdir /var/www/example.com/logs
Add a test index.html or PHP file to public_html and configure Apache sites-available/example.com.

Tip
Enable site with a2ensite example.com && service apache2 reload.

Troubleshooting

PHP repo addition fails or GPG errors
Rerun apt update after adding repo; temporarily disable strict key checks with apt-get install -o Acquire::Check-Valid-Until=false if needed, then retry.
Apache not starting or PHP not processing
Restart with service apache2 restart; check a2enmod php8.1 and error logs in /var/log/apache2/error.log.
MariaDB root password issues or access denied
Reset via mysql_secure_installation or check /home/mysql_access.txt from Cloud-Init; run mysqladmin reload after changes.
Firewall blocks web access
Verify UFW status with ufw status; allow ports 80/443 and reload: ufw reload. Test locally with curl localhost.
Outdated packages or dependency conflicts
Full upgrade apt update && apt full-upgrade -y && apt autoremove; reboot if services hang.

Related Guides

More Contabo Tutorials

Other Tool Tutorials

Ready to get started with Contabo?

Put this tutorial into practice. Visit Contabo and follow the steps above.

Visit Contabo