We are committed to provide service 24 X 7

Deals, Shopping, Training, Tools

26
2.115.920,95

Cart

Quantity 187,50
Quantity 3.900,00

Learn how to – How To Install LAMP Stack on Debian 11 / Debian 10

Learn how to – How To Install LAMP Stack on Debian 11 / Debian 10.

This guide will explain how to install Apache, MariaDB and PHP ( LAMP Stack) on Debian 11 / Debian 10 Linux system. LAMP is an acronym for – Linux, Apache, MySQL/MariaDB and PHP. LAMP Stack is not a single package but a set of open-source tools that are used to power web applications and websites. Each component can be used independently to serve an application.

Install LAMP Stack on Debian 11 / Debian 10

LAMP Stack comprises of the following open source software applications.

  • Linux – This is the operating system hosting the Applications.
  • Apache – Apache HTTP is a free and open-source cross-platform web server.
  • MySQL/MariaDB – Open Source relational database management system.
  • PHP – Programming/Scripting Language used for developing Web applications.

You can use a Virtual Machine on Premise, in the cloud or a dedicated server to install and configure LAMP Stack on Debian 10 operating system. A use account used in this setup needs sudo privileges to install software, edit configuration files, and manage services.

Step 1: Update Debian System

Before we can start installation of LAMP Stack packages on Debian 11 / Debian 10, it is recommended to keep the repository and packages up to date.

sudo apt update && sudo apt -y upgrade

Step 2: Install MariaDB Database Server

MariaDB is a relational database management system forked from MySQL. It is free and Open source. Install it by running the commands below.

sudo apt install -y mariadb-server mariadb-client

The version of MariaDB installed is 10.3.

# Debian 10
$ apt policy mariadb-server
mariadb-server:
  Installed: (none)
  Candidate: 1:10.3.29-0+deb10u1
  Version table:
     1:10.3.29-0+deb10u1 500
        500 http://deb.debian.org/debian buster/main amd64 Packages
     1:10.3.25-0+deb10u1 500
        500 http://security.debian.org/debian-security buster/updates/main amd64 Packages

# Debian 11
$ apt policy mariadb-server
mariadb-server:
  Installed: 1:10.5.15-0+deb11u1
  Candidate: 1:10.5.15-0+deb11u1
  Version table:
 *** 1:10.5.15-0+deb11u1 500
        500 http://deb.debian.org/debian bullseye/main amd64 Packages
        500 http://mirror.hetzner.com/debian/packages bullseye/main amd64 Packages
        100 /var/lib/dpkg/status

The service name for MariaDB Database server is mysql or mariadb.

$ systemctl status mariadb
 mariadb.service - MariaDB 10.5.15 database server
     Loaded: loaded (/lib/systemd/system/mariadb.service; enabled; vendor preset: enabled)
     Active: active (running) since Fri 2022-09-09 14:11:18 UTC; 32s ago
       Docs: man:mariadbd(8)
             https://mariadb.com/kb/en/library/systemd/
    Process: 1805 ExecStartPre=/usr/bin/install -m 755 -o mysql -g root -d /var/run/mysqld (code=exited, status=0/SUCCESS)
    Process: 1806 ExecStartPre=/bin/sh -c systemctl unset-environment _WSREP_START_POSITION (code=exited, status=0/SUCCESS)
    Process: 1808 ExecStartPre=/bin/sh -c [ ! -e /usr/bin/galera_recovery ] && VAR= ||   VAR=`cd /usr/bin/..; /usr/bin/galera_recovery`; [ $? -eq 0 ]   && systemctl set-environment _WSREP_START_POS>
    Process: 1871 ExecStartPost=/bin/sh -c systemctl unset-environment _WSREP_START_POSITION (code=exited, status=0/SUCCESS)
    Process: 1873 ExecStartPost=/etc/mysql/debian-start (code=exited, status=0/SUCCESS)
   Main PID: 1855 (mariadbd)
     Status: "Taking your SQL requests now..."
      Tasks: 16 (limit: 4556)
     Memory: 73.9M
        CPU: 682ms
     CGroup: /system.slice/mariadb.service
             └─1855 /usr/sbin/mariadbd

Sep 09 14:11:18 debian11 mariadbd[1855]: 2022-09-09 14:11:18 0 [Note] /usr/sbin/mariadbd: ready for connections.
Sep 09 14:11:18 debian11 mariadbd[1855]: Version: '10.5.15-MariaDB-0+deb11u1'  socket: '/run/mysqld/mysqld.sock'  port: 3306  Debian 11
Sep 09 14:11:18 debian11 systemd[1]: Started MariaDB 10.5.15 database server.
Sep 09 14:11:18 debian11 /etc/mysql/debian-start[1875]: Upgrading MySQL tables if necessary.
Sep 09 14:11:18 debian11 /etc/mysql/debian-start[1878]: Looking for 'mysql' as: /usr/bin/mysql
Sep 09 14:11:18 debian11 /etc/mysql/debian-start[1878]: Looking for 'mysqlcheck' as: /usr/bin/mysqlcheck
Sep 09 14:11:18 debian11 /etc/mysql/debian-start[1878]: This installation of MariaDB is already upgraded to 10.5.15-MariaDB.
Sep 09 14:11:18 debian11 /etc/mysql/debian-start[1878]: There is no need to run mysql_upgrade again for 10.5.15-MariaDB.
Sep 09 14:11:18 debian11 /etc/mysql/debian-start[1878]: You can use --force if you still want to run mysql_upgrade
Sep 09 14:11:18 debian11 /etc/mysql/debian-start[1886]: Checking for insecure root accounts.

The last step is securing the database server. This includes:

  • Setting strong root password
  • Removing anonymous users
  • Disabling remote login for root user.
  • Removing test database and access to it

Run the command below to secure your database server.

$ sudo mysql_secure_installation
 NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
       SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!
 In order to log into MariaDB to secure it, we'll need the current
 password for the root user.  If you've just installed MariaDB, and
 you haven't set the root password yet, the password will be blank,
 so you should just press enter here.
 Enter current password for root (enter for none): 
 OK, successfully used password, moving on…
 Setting the root password ensures that nobody can log into the MariaDB
 root user without the proper authorisation.
 Set root password? [Y/n] Y
 New password: 
 Re-enter new password: 
 Password updated successfully!
 Reloading privilege tables..
  … Success!
 By default, a MariaDB installation has an anonymous user, allowing anyone
 to log into MariaDB without having to have a user account created for
 them.  This is intended only for testing, and to make the installation
 go a bit smoother.  You should remove them before moving into a
 production environment.
 Remove anonymous users? [Y/n] Y
  … Success!
 Normally, root should only be allowed to connect from 'localhost'.  This
 ensures that someone cannot guess at the root password from the network.
 Disallow root login remotely? [Y/n] Y
  … Success!
 By default, MariaDB comes with a database named 'test' that anyone can
 access.  This is also intended only for testing, and should be removed
 before moving into a production environment.
 Remove test database and access to it? [Y/n] Y
 Dropping test database…
 … Success!
 Removing privileges on test database…
 … Success! 
 Reloading the privilege tables will ensure that all changes made so far
 will take effect immediately.
 Reload privilege tables now? [Y/n] Y
  … Success!
 Cleaning up…
 All done!  If you've completed all of the above steps, your MariaDB
 installation should now be secure.
 Thanks for using MariaDB!

Test MariaDB database installation.

$ mysql -u root -p
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or g.
Your MariaDB connection id is 64
Server version: 10.5.15-MariaDB-0+deb11u1 Debian 11

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.

MariaDB [(none)]>  SELECT VERSION();
+---------------------------+
| VERSION()                 |
+---------------------------+
| 10.5.15-MariaDB-0+deb11u1 |
+---------------------------+
1 row in set (0.000 sec)

MariaDB [(none)]>

Step 3: Install Apache Web Server

Apache Web server packages are available on Debian 10 / Debian 11 official repositories. All that’s needed is execution of install command with sudo.

sudo apt install -y apache2 apache2-utils

Confirm Apache build and version.

$ sudo apache2 -v
Server version: Apache/2.4.54 (Debian)
Server built:   2022-06-09T04:26:43

Service is started automatically after installation.

$ systemctl status apache2
 ● apache2.service - The Apache HTTP Server
    Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled)
    Active: active (running) since Fri 2022-09-09 10:56:09 UTC; 18s ago
      Docs: https://httpd.apache.org/docs/2.4/
  Main PID: 16696 (apache2)
     Tasks: 55 (limit: 1148)
    Memory: 9.0M
    CGroup: /system.slice/apache2.service
            ├─16696 /usr/sbin/apache2 -k start
            ├─16698 /usr/sbin/apache2 -k start
            └─16699 /usr/sbin/apache2 -k start

You can restart service or reload when a change is made by using systemctl command.

sudo systemctl reload apache2
sudo systemctl enable apache2

To enable the service to start at boot, use

sudo systemctl enable apache2

To view Apache server full status, use apache2ctl command.

sudo apt -y install elinks
sudo apache2ctl fullstatus 

Your output should be similar to below.

Open server IP address on your browser to see default Apache page.

Step 4: Install PHP on Debian 11 / Debian 10

Now that we have both Apache and MariaDB installed, the missing piece is PHP. We will install PHP and standard extensions which are commonly used. The version of PHP installed on Debian 10 is PHP 7.3 and PHP 7.4 on Debian 11.

sudo apt install php libapache2-mod-php php-cli php-fpm php-json php-pdo php-mysql php-zip php-gd  php-mbstring php-curl php-xml php-pear php-bcmath

Enable Apache module if not already enabled then restart the Web Server.

sudo a2enmod php7.* 

Confirm your PHP version.

# Debian 10
$ php -v
PHP 7.3.29-1~deb10u1 (cli) (built: Jul  2 2021 04:04:33) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.3.29, Copyright (c) 1998-2018 Zend Technologies
    with Zend OPcache v7.3.29-1~deb10u1, Copyright (c) 1999-2018, by Zend Technologies

# Debian 11
$ php -v
PHP 7.4.30 (cli) (built: Jul  7 2022 15:51:43) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
    with Zend OPcache v7.4.30, Copyright (c), by Zend Technologies

Create a php script to test your LAMP stack installation.

echo "<?php phpinfo(); ?>" | sudo tee /var/www/html/phpinfo.php

Open your Debian server IP and URL: http://[ServerIP/hostname]/phpinfo.php

This gives a detailed information about PHP and Apache web server. This marks the end our guide on how to Install LAMP Stack on Debian 11 / Debian 10 Linux system.

Other interesting guides:

How to Install phpMyAdmin with Apache on Debian

How to Monitor Apache Web Server with Prometheus and Grafana in 5 minutes

Monitoring MySQL / MariaDB with Prometheus in five minutes

26
2.115.920,95

Cart

Quantity 187,50
Quantity 3.900,00