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...
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
nanofor editing text files, but feel free to usevimor any preferred text editor.
- 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 - Update Repository List
sudo apt update 📦 Installing MariaDB
- Install MariaDB
sudo apt install mariadb-server mariadb-client -y - Secure the Installation
sudo mysql_secure_installation Follow the prompts to configure security settings, choosing y or n as needed.
🌐 Installing Apache
- Install Apache
sudo apt install apache2 apache2-doc -y - Verify Installation
Access your server’s IP in a browser to confirm the Apache landing page appears.
🔢 Installing PHP
- Install PHP
sudo apt install php php-mysql -y - 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
- Install phpMyAdmin
sudo apt install phpmyadmin -y Choose apache2 for configuration when prompted.
- Restart Apache
sudo systemctl restart apache2 Access phpMyAdmin at http://<server-ip>/phpmyadmin.
- 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
- Create a Directory for the Website
sudo mkdir /var/www/examplesite - Create a Test Page
sudo nano /var/www/examplesite/index.html Add sample content like Hello World!
- 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> - Enable Site and Reload Apache
sudo a2ensite examplesite sudo systemctl reload apache2 - 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.