Home/Docs/Linux

Linux

Installing a LAMP Stack on Debian 12

Installing a LAMP Stack on Debian 12 This guide will walk you through installing a LAMP stack on Debian 12. The LAMP stack—Linux, Apache, MariaDB, and PHP—is a popular setup for hosting websites on Linux. While MySQL...

Author
adminhowto.com Editorial
Updated
Nov 7, 2024
Estimated time
5 min read
Difficulty
Practical
Applies to
Common server environments
download (1)

Installing a LAMP Stack on Debian 12

This guide will walk you through installing a LAMP stack on Debian 12. The LAMP stack—Linux, Apache, MariaDB, and PHP—is a popular setup for hosting websites on Linux. While MySQL is commonly used in LAMP stacks, this guide opts for MariaDB, which offers improved speed, scalability, and features.


🛠 Getting Started

Note: This guide uses nano for editing text files, but feel free to use vim or any preferred text editor.

  1. Create a Non-Root User
  useradd websrv

Set a password for this user:

  passwd websrv

Grant sudo privileges:

  usermod -a -G sudo websrv

Log in as the new user:

  su websrv

Verify:

  whoami
  1. Update Repository List
  sudo apt update

📦 Installing MariaDB

  1. Install MariaDB
  sudo apt install mariadb-server mariadb-client -y
  1. Secure the Installation
  sudo mysql_secure_installation

Follow the prompts to configure security settings, choosing y or n as needed.


🌐 Installing Apache

  1. Install Apache
  sudo apt install apache2 apache2-doc -y
  1. Verify Installation
    Access your server’s IP in a browser to confirm the Apache landing page appears.

🔢 Installing PHP

  1. Install PHP
  sudo apt install php php-mysql -y
  1. Create a Test PHP Script
  sudo nano /var/www/html/test.php

Add:

  <?php phpinfo(); ?>

Navigate to http://<server-ip>/test.php in your browser to see PHP details.


🗄️ Installing phpMyAdmin

  1. Install phpMyAdmin
  sudo apt install phpmyadmin -y

Choose apache2 for configuration when prompted.

  1. Restart Apache
  sudo systemctl restart apache2

Access phpMyAdmin at http://<server-ip>/phpmyadmin.

  1. Create a New Database
  sudo mysql
  CREATE USER 'mywpsite'@'localhost' IDENTIFIED BY 'AstrongSecurepassword%$';  GRANT ALL PRIVILEGES ON *.* TO 'mywpsite'@'localhost';  FLUSH PRIVILEGES;  exit;

🌍 Adding Domains and Subdomains

  1. Create a Directory for the Website
  sudo mkdir /var/www/examplesite
  1. Create a Test Page
  sudo nano /var/www/examplesite/index.html

Add sample content like Hello World!

  1. Set Up Virtual Host Configuration
  sudo nano /etc/apache2/sites-available/examplesite.conf

Add:

  <VirtualHost *:80>  ServerName www.examplesite.com  ServerAlias example.com  DocumentRoot "/var/www/examplesite"  </VirtualHost>
  1. Enable Site and Reload Apache
  sudo a2ensite examplesite  sudo systemctl reload apache2
  1. Update DNS Records
    Set the domain’s A record to point to your server’s IP. Tools like WhatsMyDNS.net can help verify DNS propagation.

Following these steps, you’ll have a fully functional LAMP stack for website hosting on Debian 12. For scalable and flexible hosting, review our VPS packages.