Support Online
Skip to main content

LAMP Installation on Debian 10 (MariaDB, PHP)

You will step by step install all the components required to run dynamic websites and PHP applications on Debian 10. This guide has been made completely original with an SEO compatible and developer-friendly narrative.

What Will You Learn in This Guide?

In this document, you will learn the following operations:

  • Installing the Apache web server and setting the firewall configuration.
  • Setting up and securing the MariaDB database.
  • Installing PHP and necessary modules.
  • Configuring a custom VirtualHost on Apache.
  • Testing PHP & MariaDB connection.

1. Apache Installation

1.1 Update package list:

sudo apt update

1. Install Apache:


sudo apt install apache2
  • Allow HTTP/HTTPS traffic by turning on the WWW Full profile:

sudo ufw allow "WWW Full"

-When you go to your server IP from your browser, you should see the default Apache Debian page.


2. MariaDB Installation and Security

  1. Install MariaDB:

sudo apt install mariadb-server
  1. Run the security script:

sudo mysql_secure_installation
  • Root password is empty at first stage → ENTER

-Set root password? →N

  • All other options → Y
  1. Login to MariaDB console:

sudo mariadb

  1. Exit from console:

exit;

3. PHP Installation and Apache Integration


  1. Install PHP and required modules:

sudo apt install php libapache2-mod-php php-mysql
  1. Set Apache to prioritize PHP files:

sudo nano /etc/apache2/mods-enabled/dir.conf
  • Update as follows:

DirectoryIndex index.php index.html index.cgi index.pl index.xhtml index.htm

  1. Reinstall Apache:

sudo systemctl reload apache2

4. Creating a Virtual Host

  1. Create the web directory:

sudo mkdir /var/www/ornek.com

2. Change directory ownership:


sudo chown -R $USER:$USER /var/www/ornek.com
  1. Create the VirtualHost configuration file:

sudo nano /etc/apache2/sites-available/ornek.com.conf
  • Add the following settings:

<VirtualHost *:80>
ServerName ornek.com
ServerAlias www.ornek.com
DocumentRoot /var/www/ornek.com
ErrorLog $&#123;APACHE_LOG_DIR&#125;/error.log
CustomLog $&#123;APACHE_LOG_DIR&#125;/access.log combined
</VirtualHost>

  1. Activate the site:

sudo a2ensite ornek.com.conf
  1. Turn off the default site:

sudo a2dissite 000-default.conf
  1. Test the configuration:

sudo apache2ctl configtest

  1. Reinstall Apache.

sudo systemctl reload apache2

5. Testing PHP Working


  1. Create the info.php file:

nano /var/www/ornek.com/info.php
  • Content:

<?php phpinfo();
  • Open in browser:

http://ornek.com/info.php
  • Then delete the file for security:

sudo rm /var/www/ornek.com/info.php

6. PHP → MariaDB Connection Test (Optional)


  1. Database and user creation

sudo mariadb

CREATE DATABASE genixnode_db;
CREATE USER 'db_yonetici'@'%' IDENTIFIED BY 'GUCLU_PAROLA_123';
GRANT ALL ON genixnode_db.* TO 'db_yonetici'@'%';
FLUSH PRIVILEGES;
exit;

  1. Create PHP connection test file:

nano /var/www/ornek.com/db_test.php
  • Content:

<?php
$user = "db_yonetici";
$password = "GUCLU_PAROLA_123";
$database = "genixnode_db";

try {
$db = new PDO("mysql:host=localhost;dbname=$database", $user, $password);
echo "<h2>MariaDB Baglantisi Basarili!</h2>";

$db->exec("CREATE TABLE IF NOT EXISTS test_table (id INT AUTO_INCREMENT PRIMARY KEY, mesaj VARCHAR(255))");
echo "<p>Test tablosu olusturuldu veya mevcut.</p>";

} catch (PDOException $e) {
echo "Hata: " . $e->getMessage();
}
?>
  • Test in browser:

http://ornek.com/db_test.php

FAQ

  1. Is LAMP or LEMP faster? On static files Nginx is faster, but on PHP based dynamic projects the difference is minor.

  2. MariaDB or MySQL? MariaDB is the default on Debian and works fully compatible.

  3. How to set up HTTPS? Free SSL can be installed with Let's Encrypt (Certbot).

  4. How many sites can I host with VirtualHost?** It is unlimited, a separate VirtualHost is created for each website.

  5. Can PHP 8.x be installed? Yes, PHP 8.2 can be installed via the sury.org repository.


Result

With this guide, you have set up a complete LAMP (Apache + MariaDB + PHP) environment on Debian 10. Now a powerful server for dynamic applications, panels and PHP projects is ready.

You can scale and manage this setup much faster on the GenixNode platform.