DEV Community

CTCservers
CTCservers

Posted on

Step-by-Step Guide to Setting Up a LAMP Web Server on Ubuntu/Debian

Whether you are hosting a dynamic WordPress blog, a custom PHP application, or simply learning the ropes of server management, the LAMP stack remains the gold standard for web hosting.

LAMP stands for Linux, Apache, MariaDB, and PHP—a powerful suite of open-source software that powers a significant portion of the internet.

By combining the stability of Debian or Ubuntu with the robustness of the Apache web server, the data management of MySQL/MariaDB, and the scripting power of PHP, you create a flexible and secure environment ready to handle everything from small personal projects to enterprise-level traffic.

In this guide, I outline the logic behind installing, configuring, and securing your own LAMP server to give you full control over your web presence.

Prerequisites

Before diving into the installation, you will need:

Operating System: A running instance of Debian or Ubuntu (Desktop or Server edition).

User Privileges: A user account with sudo (root) privileges.

Internet Access: To download packages from repositories.

1. Updating the System

To ensure the most stable foundation for your web server and applications, it is highly recommended to begin with a pristine environment. The first step in any server setup is ensuring your package lists and installed software are up to date.

2. Installing Apache

Apache is the web server component of the stack. It listens for web requests and serves your website's files to the visitor. Once installed, you can verify it is working by accessing your server's IP address in a browser, which should display the default Debian/Ubuntu landing page.

3. Installing the Database and PHP

Next, you need the backend components. You will need to install MariaDB (the database server) and PHP (the scripting language), along with several PHP extensions that allow PHP to communicate with the database and handle common tasks like image processing and XML parsing.

4. Configuring the Database Server

Security is paramount when handling databases. After installation, it is crucial to run the secure installation script provided by MariaDB. This process helps you:

  • Set up authentication (unix_socket is recommended).
  • Remove anonymous users.
  • Disallow root login remotely.
  • Remove test databases. Once secured, you will need to create a specific database and a dedicated user for your web application.

5. Configuring the Firewall

Enhancing your server’s security is best achieved by configuring a firewall. On Ubuntu/Debian, UFW (Uncomplicated Firewall) is the standard tool. You will need to specifically allow traffic on Port 80 (HTTP) and Port 443 (HTTPS), as well as ensure your SSH port remains open so you don't lock yourself out.

6. DNS and SSL (Optional)

To make your server accessible via a domain name rather than an IP address, you will need to configure your DNS zone records. Additionally, for modern web standards, securing your site with HTTPS is a must. You can achieve this using tools like Certbot to fetch free certificates from Let’s Encrypt.

Get the Code

This post covers the architecture and steps required for the setup. To get the exact terminal commands, configuration scripts, and copy-paste code snippets to execute this installation, please visit the full tutorial on my website.

Read More: Full LAMP Setup Guide with Code Commands

Top comments (0)