Beginner
How to install a LAMP stack on Ubuntu with DigitalOcean
Quick Answer
Use DigitalOcean's LAMP 1-Click App on Ubuntu 20.04 for fastest setup, or manually install on a standard Ubuntu Droplet. Create Droplet, SSH in, verify with php -i, secure with sudo user and UFW. Test by visiting http://your_droplet_ip for Apache default page.
Prerequisites
- DigitalOcean account with billing enabled
- SSH client (terminal on Linux/Mac or PuTTY on Windows)
- Basic command line knowledge
- Domain name (optional for virtual hosts)
- SSH key pair (recommended for authentication)
1
Log in to DigitalOcean Control Panel
Navigate to
cloud.digitalocean.com and log in to your account. If you don't have an account, sign up first. This is the starting point for creating any Droplet.[1]2
Create a New Droplet
Click Create in the top-right corner, then select Droplets or go directly to the Create Droplets page. Choose Ubuntu 20.04 or 22.04 for manual install, or proceed to Marketplace for 1-Click.[1][2]
Tip
Select datacenter region closest to your users for lowest latency.
3
Select LAMP 1-Click App (Recommended)
In the Choose an image section, click the Marketplace tab. Search for or scroll to LAMP by DigitalOcean. Click the LAMP app tile to review details: Ubuntu 20.04 base, Apache, MySQL, PHP 8.1, Fail2ban, Postfix, Certbot pre-installed with UFW rules for ports 80, 443, 22.[1]
Tip
1-Click is fastest; includes security tools out-of-the-box.
4
Configure Droplet Settings
Set Hostname (e.g., 'lamp-droplet-1'), choose Datacenter region (nearest), VPC network (default), Plan (Basic {{price:digitalocean:Basic 2GB}}/mo: 2GB RAM, 1 vCPU, 50GB SSD), Authentication (SSH key recommended), enable backups/IPv6 if needed, set Quantity to 1.[1]
5
Create and Note Droplet IP
Scroll to bottom and click green Create Droplet button. Wait 1-2 minutes. On the Droplet details page, copy the IPv4 address displayed.[1]
Tip
Creation takes ~60 seconds; check status in control panel.
6
SSH into Droplet as Root
ssh root@your_droplet_ip Accept fingerprint, enter password if no SSH key. You're now logged in as root user.[1][2]Tip
Use SSH keys for passwordless, secure access.
7
Verify LAMP Installation
Run
php -i to confirm PHP 8.1 (cli/php.ini at /etc/php/8.1/cli), Apache, MySQL running. Defaults: HTTP port 80, HTTPS 443, SSH 22 open via UFW. For manual install, run sudo apt update && sudo apt install apache2 mysql-server php libapache2-mod-php php-mysql.[1][2][3]Tip
Check services:
sudo systemctl status apache2 mysql8
Secure Server with Sudo User
Create sudo user:
adduser sammy (set password), usermod -aG sudo sammy. Log out and SSH as sammy. Follow DigitalOcean's Initial Server Setup: configure sudo, UFW, SSH keys.[1][2]Tip
Never run production apps as root.
9
Test Web Server
Visit
http://your_droplet_ip in browser. Apache default page loads, confirming HTTP on port 80 works.[1][2]10
Optional: Enable SSL with Certbot
Run
certbot (pre-installed in 1-Click) for free Let's Encrypt HTTPS certificate on port 443.[1]Tip
Point domain A record to Droplet IP first.
Troubleshooting
SSH connection refused or timeout
Verify Droplet IP, ensure VPC firewall allows SSH (port 22), check UFW status with
sudo ufw status, allow if needed: sudo ufw allow OpenSSHApache default page not loading (connection refused)
Check Apache status:
sudo systemctl status apache2, restart if inactive: sudo systemctl restart apache2, verify UFW allows HTTP: sudo ufw allow 'Apache'PHP info shows wrong version or modules missing
For manual install, install PHP:
sudo apt install php libapache2-mod-php php-mysql, restart Apache: sudo systemctl restart apache2, verify: php -mMySQL not starting or access denied
Secure MySQL:
sudo mysql_secure_installation, set root password, remove anonymous usersPermission denied editing web files
For virtual host:
sudo mkdir -p /var/www/your_domain && sudo chown -R $USER:$USER /var/www/your_domainReady to get started with DigitalOcean?
Put this tutorial into practice. Visit DigitalOcean and follow the steps above.
Visit DigitalOcean →