Installing LAMP on Ubuntu 21.04

Here is a step by step guide for installing LAMP (Linux, Apache, MySQL, PHP) on Ubuntu 21.04 including common software, date/time sync, firewall and fail2ban.

Installing LAMP on Ubuntu 21.04

1. Update and Upgrade the Operating System

apt-get update
apt-get upgrade
apt-get dist-upgrade
apt-get autoremove
apt-get autoclean

2. Install Common Software

Install the software that you will need down the line

apt-get install landscape-common
apt-get install curl
apt-get install htop

3. Update Date and Time

Correct date and time is extremely important for keeping the operating system correctly updated. Even minor fluctuations may cause different weird looking errors to be displayed throughout the lifetime of the distribution. So best to keep date and time properly synced.

apt-get install ntpdate
ntpdate ntp.ubuntu.com
date
dpkg-reconfigure tzdata
reboot

4. Install the Apache Web Server

sudo apt-get install apache2
sudo a2enmod rewrite
sudo service apache2 restart

5. Install the MySQL Database Server

sudo apt-get install mysql-server
sudo mysql_secure_installation

# Import your SQL backup if you have one
sudo mysql -u root -p PASSWORD < 20210920_yourbackup.sql

Install Composer

php -r "readfile('https://getcomposer.org/installer');" > composer-setup.php
php composer-setup.php
php -r "unlink('composer-setup.php');"
mv composer.phar /usr/local/bin/composer

Add a Swap File to Increase Memory

free -m
/bin/dd if=/dev/zero of=/var/swap.1 bs=1M count=2048
chmod 600 /var/swap.1
/sbin/mkswap /var/swap.1
/sbin/swapon /var/swap.1
echo '/swapfile none swap sw 0 0' | tee -a /etc/fstab
swapon -s
reboot

Install Firewall

apt-get install ufw
ufw allow ssh
ufw allow http
ufw allow https
ufw enable

Install fail2ban

apt-get install fail2ban
cp /etc/fail2ban/fail2ban.conf /etc/fail2ban/fail2ban.local
cp /etc/fail2ban/jail.conf /etc/fail2ban/jail.local
fail2ban-client status
Previous
GoLang. Dealing with time.Time in a Database Agnostic Manner
Next
How to Install Podman on Ubuntu 20.04

Keep Reading

Explore more articles and insights

A Big, Opinionated List of PHP Libraries (2026 Edition)

A Big, Opinionated List of PHP Libraries (2026 Edition)

Read Article
Ork: SSH Server Automation in Go

Ork: SSH Server Automation in Go

Read Article
Deno Deploy Killed My Start Page

Deno Deploy Killed My Start Page

Read Article
View All Blog Posts