How to deploy LAMP stack on Contabo

intermediate 12 min read Updated 2026-03-13
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

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

Step-by-Step Instructions

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.
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.

Check status with <code>systemctl status apache2</code>.
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.

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.

Test PHP with <code>php -v</code> and create /var/www/html/info.php with &lt;?php phpinfo(); ?&gt;.
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.

Access DB with <code>mysql -u root -p</code> 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.

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.

Enable site with <code>a2ensite example.com &amp;&amp; service apache2 reload</code>.

Common Issues & Troubleshooting

PHP repo addition fails or GPG errors

Rerun <code>apt update</code> after adding repo; temporarily disable strict key checks with <code>apt-get install -o Acquire::Check-Valid-Until=false</code> if needed, then retry.

Apache not starting or PHP not processing

Restart with <code>service apache2 restart</code>; check <code>a2enmod php8.1</code> and error logs in /var/log/apache2/error.log.

MariaDB root password issues or access denied

Reset via <code>mysql_secure_installation</code> or check /home/mysql_access.txt from Cloud-Init; run <code>mysqladmin reload</code> after changes.

Firewall blocks web access

Verify UFW status with <code>ufw status</code>; allow ports 80/443 and reload: <code>ufw reload</code>. Test locally with <code>curl localhost</code>.

Outdated packages or dependency conflicts

Full upgrade <code>apt update &amp;&amp; apt full-upgrade -y &amp;&amp; apt autoremove</code>; reboot if services hang.

Special Offer

Affiliate link. We may earn a commission at no extra cost to you.