How to install LAMP stack on Ubuntu on DigitalOcean

beginner 8 min read Updated 2026-03-13
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)

Step-by-Step Instructions

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]
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]
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 $6/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]
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]
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]
Check services: <code>sudo systemctl status apache2 mysql</code>
8

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]
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]
Point domain A record to Droplet IP first.

Common Issues & Troubleshooting

SSH connection refused or timeout

Verify Droplet IP, ensure VPC firewall allows SSH (port 22), check UFW status with <code>sudo ufw status</code>, allow if needed: <code>sudo ufw allow OpenSSH</code>

Apache default page not loading (connection refused)

Check Apache status: <code>sudo systemctl status apache2</code>, restart if inactive: <code>sudo systemctl restart apache2</code>, verify UFW allows HTTP: <code>sudo ufw allow 'Apache'</code>

PHP info shows wrong version or modules missing

For manual install, install PHP: <code>sudo apt install php libapache2-mod-php php-mysql</code>, restart Apache: <code>sudo systemctl restart apache2</code>, verify: <code>php -m</code>

MySQL not starting or access denied

Secure MySQL: <code>sudo mysql_secure_installation</code>, set root password, remove anonymous users

Permission denied editing web files

For virtual host: <code>sudo mkdir -p /var/www/your_domain &amp;&amp; sudo chown -R $USER:$USER /var/www/your_domain</code>

Special Offer

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