Skip to main content

Before You Begin

info

While Apache is still actively maintained and widely used, many developers are switching to NGINX for its superior performance, scalability, reverse proxy capabilities, load balancing, efficient static file delivery, and cleaner configuration syntax.

That said, using Apache in a LAMP stack shouldn't cause any compatibility issues and remains a solid choice — especially for legacy apps or shared hosting environments.

Still, it may be worth checking out my tutorial on setting up a LEMP stack (Linux, NGINX, MySQL, PHP) to familiarize yourself with the software and stay current with modern web server trends.

note

Some steps in this guide reflect industry standards and best practices, but are not technically required to install a functioning LAMP server.

These steps will be marked as (Recommended) to help you distinguish between what's essential and what's considered good practice.

note

Words shown in brackets (e.g., [your-hostname]) are placeholders.
Replace them with your actual values when running commands.

Update your system

Keeping your system up to date ensures you're installing the latest stable packages.

sudo apt update && sudo apt upgrade -y
info

If you set your hostname when installing your operating system, you can disregard this step unless you would like to change your hostname to something else.

Set a meaningful hostname for easier identification and logging.

sudo hostnamectl set-hostname [your-hostname]

It is also recommended to replace localhost in your /etc/hosts file.

tip

You can edit files using the nano (or sudo nano for write-protected files) command or use an editor of your choice.

/etc/hosts
127.0.0.1       localhost
127.0.1.1 [your-hostname-fqdn] [your-hostname]
note

Hostname FQDN (Fully Qualified Domain Name) is recommended for environments using an internal network domain, but is not required.
An example of a FQDN is myserver.example.local where myserver is the hostname and example.local is the internal network domain.

Finally, restart your server:

sudo reboot

Having the correct timezone configured simplifies log tracking and scheduled tasks.

sudo timedatectl set-timezone [timezone]

These are useful tools for diagnostics, editing config files, managing files, and working with the web stack.

sudo apt install -y curl wget git ufw zip unzip
note

If you are currently using a non-root sudo user account, you can safely disregard this step unless you would like to run/manage the webserver from a different account.

Running everything as root isn't safe in production environments.

sudo adduser [username]
sudo usermod -aG sudo [username]

You can log in as your new user using:

su - [username]