Tuesday, August 24, 2021

How To Install Apache, MariaDB, PHP (LAMP Stack) on Debian 11


LAMP Stack stands for Linux, Apache, MariaDB, and PHP stack. This stack is used by most web hosting companies to host websites, blogs and is also used in web developments. Due to free and open-source licensing, this stack is the best alternative to expensive stacks.

Install LAMP Stack

Install Linux

Follow the Step by Step installation of Debian 11 or Upgrade Debian 10 "Buster" to Debian 11 "Bullseye".

Now, we will proceed to install Apache v2.4.48, PHP v7.4, MariaDB v10.5 on Debian 11.

Install Apache

First, we will start with installing the Apache webserver.
sudo apt update sudo apt install -y apache2 apache2-utils

Check the status of the Apache server service post the installation.
sudo systemctl status apache2

Output:
● apache2.service - The Apache HTTP Server Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled) Active: active (running) since Tue 2021-08-24 09:20:01 CDT; 33s ago Docs: https://httpd.apache.org/docs/2.4/ Main PID: 1930 (apache2) Tasks: 55 (limit: 2321) Memory: 10.8M CPU: 58ms CGroup: /system.slice/apache2.service ├─1930 /usr/sbin/apache2 -k start ├─1932 /usr/sbin/apache2 -k start └─1933 /usr/sbin/apache2 -k start Aug 24 09:20:01 debian11.itzgeek.local systemd[1]: Starting The Apache HTTP Server... Aug 24 09:20:01 debian11.itzgeek.local systemd[1]: Started The Apache HTTP Server. 

We will now test the Apache webserver to check if it is working as we expect. So, open up a web browser and then go to the following URL.
http://localhost/
OR
http://your-ip-add-ress/
You will get the "Apache2 Debian Default Page". This page confirms that the Apache server is working fine.

Apache HTTP server's default document root is /var/www/html/ where you will place HTML files, and the main configuration file is /etc/apache2/apache2.conf. Additional configuration files are found in the /etc/apache2 directory.

Install MariaDB

MariaDB is the most popular database server, and it is the drop-in replacement of the MySQL server.

Install MariaDB server v10.5 from the Debian base repository.
At the time of writing this article, MariaDB v10.6 is available from the official MariaDB repository. If you want, you can install MariaDB v10.6 on Debian 11ORinstall MySQL 8.0 / 5.7 in place of MariaDB.
sudo apt install -y mariadb-server mariadb-client

Check the status of the MariaDB database service.
sudo systemctl status mariadb

Output:
● mariadb.service - MariaDB 10.5.11 database server Loaded: loaded (/lib/systemd/system/mariadb.service; enabled; vendor preset: enabled) Active: active (running) since Tue 2021-08-24 09:31:02 CDT; 2min 42s ago Docs: man:mariadbd(8) https://mariadb.com/kb/en/library/systemd/ Process: 2951 ExecStartPre=/usr/bin/install -m 755 -o mysql -g root -d /var/run/mysqld (code=exited, status=0/SUCCESS) Process: 2952 ExecStartPre=/bin/sh -c systemctl unset-environment _WSREP_START_POSITION (code=exited, status=0/SUCCESS) Process: 2954 ExecStartPre=/bin/sh -c [ ! -e /usr/bin/galera_recovery ] && VAR= ||   VAR=`cd /usr/bin/..; /usr/bin/galera_recovery`; [ $? -eq 0 ]   && systemctl se> Process: 3015 ExecStartPost=/bin/sh -c systemctl unset-environment _WSREP_START_POSITION (code=exited, status=0/SUCCESS) Process: 3017 ExecStartPost=/etc/mysql/debian-start (code=exited, status=0/SUCCESS) Main PID: 3001 (mariadbd) Status: "Taking your SQL requests now..." Tasks: 10 (limit: 2321) Memory: 80.5M CPU: 1.027s CGroup: /system.slice/mariadb.service └─3001 /usr/sbin/mariadbd Aug 24 09:31:04 debian11.itzgeek.local /etc/mysql/debian-start[3022]: information_schema Aug 24 09:31:04 debian11.itzgeek.local /etc/mysql/debian-start[3022]: MySQL 

Run the mysql_secure_installation command to improve the security of your MariaDB database installation.

sudo mysql_secure_installation

READ:How to Secure MariaDB installation using mysql_secure_installation

Install PHP

By default Apache server supports the .html files only, not PHP. To have the PHP support, we need to install PHP and the PHP extension package for MariaDB to connect with the database.
Debian 11 comes with PHP v7.4. But, you can install PHP 8.0 on Debian 11 from the SURY repository.
sudo apt install -y php php-mysql libapache2-mod-php

Restart the Apache server after the installation of the PHP packages.
sudo systemctl restart apache2

Test LAMP Stack

To test the LAMP stack, we will place a PHP file on the default document root of the Apache server.
echo "" | sudo tee /var/www/html/info.php

Now, open a web browser and go to the following URL.
http://localhost/info.php
OR
http://your-ip-add-ress/info.php
The page will look like below,

You can scroll further down to see PHP extension details such as MySQL, XML, and PHP variables.

Sumber: disini

0 comments:

Post a Comment