DebianDebian Based

How To Install LAMP on Debian 12

Install LAMP on Debian 12

In this tutorial, we will show you how to install LAMP on Debian 12. The LAMP stack is a fundamental building block for web applications and websites. It combines the power of Linux, the Apache web server, the MySQL database system, and PHP for server-side scripting. However, in today’s digital landscape, it’s crucial to go beyond a basic setup and secure your web server with HTTPS for data encryption and a firewall for access control.

This article assumes you have at least basic knowledge of Linux, know how to use the shell, and most importantly, you host your site on your own VPS. The installation is quite simple and assumes you are running in the root account, if not you may need to add ‘sudo‘ to the commands to get root privileges. I will show you the step-by-step installation of the LAMP Stack on a Debian 12 (Bookworm).

Prerequisites

  • A server running one of the following operating systems: Debian 12 (Bookworm).
  • It’s recommended that you use a fresh OS install to prevent any potential issues.
  • SSH access to the server (or just open Terminal if you’re on a desktop).
  • An active internet connection. You’ll need an internet connection to download the necessary packages and dependencies for LAMP.
  • A non-root sudo user or access to the root user. We recommend acting as a non-root sudo user, however, as you can harm your system if you’re not careful when acting as the root.

Install LAMP on Debian 12 Bookworm

Step 1. Before we install any software, it’s important to make sure your system is up to date by running the following apt commands in the terminal:

sudo apt update

This will refresh the package list and upgrade the existing packages to their latest versions, ensuring that you have the most recent security updates.

Step 2. Installing Apache.

Apache is a widely used web server. Install it with:

sudo apt install apache2

After the installation, Apache should be automatically started. To confirm that it’s running, use the following command:

systemctl status apache2

To maximize Apache’s capabilities, you can enable some useful modules:

sudo a2enmod rewrite
sudo a2enmod ssl

Step 3. Installing MySQL.

MySQL is a powerful relational database management system. Install it with:

sudo apt install mysql-server

During the installation, you’ll be prompted to set a root password for MySQL. Make sure to choose a strong password and remember it.

To enhance security, run the MySQL Secure Installation script:

sudo mysql_secure_installation

This script will guide you through several security-related questions and prompts. Follow the on-screen instructions to secure your MySQL installation.

Step 4. Installing PHP.

PHP is a popular scripting language for web development. Install PHP 8.2 and the Apache PHP module:

sudo apt install php8.2
sudo apt install libapache2-mod-php8.2

To configure PHP for optimal performance and compatibility with your web applications, you can edit its settings in the php.ini file. You can find the php.ini file for PHP 8.2 in the /etc/php/8.2/apache2 directory:

sudo nano /etc/php/8.2/apache2/php.ini

Make any necessary adjustments to settings like max_execution_time, memory_limit, and upload_max_filesize to match your application’s requirements. Save the file and exit the text editor.

Step 5. Installing Certbot.

Certbot is a tool for obtaining and renewing SSL/TLS certificates. To install it for Apache:

sudo apt install certbot python3-certbot-apache

Now, let’s obtain an SSL/TLS certificate for your domain using Certbot. Replace example.com with your actual domain name:

sudo certbot --apache -d example.com

Certbot will guide you through the certificate issuance process. It will ask for your email address and require you to accept the terms of service. After that, Certbot will prompt you to choose which domains to include in the certificate. Ensure that your domain is selected and follow the prompts to complete the certificate issuance process.

After configuring Certbot, it’s essential to verify that your website is accessible over HTTPS. Open your web browser and enter your domain with “https://” (e.g., https://example.com). You should see a secure connection icon in your browser’s address bar, indicating that your website is protected with SSL/TLS.

Step 6. Firewall Configuration.

The Uncomplicated Firewall (UFW) is a user-friendly interface for managing iptables, which is the default firewall management tool in Debian. We’ll use UFW to secure your server.

  • Configuring UFW for LAMP Stack

To allow HTTP (port 80) and HTTPS (port 443) traffic, use these commands:

sudo ufw allow 80/tcp
sudo ufw allow 443/tcp

If you need SSH access to your server, allow it with:

sudo ufw allow OpenSSH

Now, enable UFW to enforce the rules you’ve set:

sudo ufw enable

You can check the status of UFW anytime to ensure it’s active and configured correctly:

sudo ufw status

This command will display a list of rules and their status. Confirm that the rules you’ve set are listed as “ALLOW.”

Congratulations! You have successfully installed LAMP. Thanks for using this tutorial to install the latest version of the LAMP Stack on Debian 12 Bookworm. For additional help or useful information, we recommend you check the official LAMP website.

VPS Manage Service Offer
If you don’t have time to do all of this stuff, or if this is not your area of expertise, we offer a service to do “VPS Manage Service Offer”, starting from $10 (Paypal payment). Please contact us to get the best deal!

r00t

r00t is a seasoned Linux system administrator with a wealth of experience in the field. Known for his contributions to idroot.us, r00t has authored numerous tutorials and guides, helping users navigate the complexities of Linux systems. His expertise spans across various Linux distributions, including Ubuntu, CentOS, and Debian. r00t's work is characterized by his ability to simplify complex concepts, making Linux more accessible to users of all skill levels. His dedication to the Linux community and his commitment to sharing knowledge makes him a respected figure in the field.
Back to top button