How to deploy LAMP stack on Contabo
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
Log into Contabo Dashboard
Choose Pre-Configured LAMP (Beginners)
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.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.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.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.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.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.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.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.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 && apt full-upgrade -y && apt autoremove</code>; reboot if services hang.