How to Install LAMP Stack on Debian 11.4.0
To Setup Lamp Stack On Debian 11.4
Introduction:
Lamp stack is used for building and delivering web-based applications. Linux is an operating system used to run the rest of the components. Apache HTTP Server is a web server software used to serve static web pages. MySQL is a relational database management system used for creating and managing web databases, but also for data warehousing, application logging, e-commerce, etc. PHP, Perl, and Python are programming languages used to create web applications.
Installation Procedure:
Step 1: Check the OS Version by using the below command
root@debian:~# lsb_release -a
No LSB modules are available.
Distributor ID: Debian
Description: Debian GNU/Linux 11 (bullseye)
Release: 11
Codename: bullseye
Step 2: Install the Apache Webserver by using the below command
root@debian:~# apt install apache2 -y
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following NEW packages will be installed:
apache2
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 0 B/278 kB of archives.
After this operation, 641 kB of additional disk space will be used.
Selecting previously unselected package apache2.
(Reading database ... 155568 files and directories currently installed.)
Preparing to unpack .../apache2_2.4.56-1~deb11u2_amd64.deb ...
Unpacking apache2 (2.4.56-1~deb11u2) ...
Setting up apache2 (2.4.56-1~deb11u2) ...
apache-htcacheclean.service is a disabled or a static unit not running, not starting it.
Processing triggers for man-db (2.9.4-2) ...
Step 3: Start the Apache webserver by using the below command
root@debian:~# systemctl start apache2
Step 4: Check the Apache server status by using the below command
root@debian:~# 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 2023-06-16 14:33:58 CDT; 1min 25s ago
Docs: https://httpd.apache.org/docs/2.4/
Main PID: 54214 (apache2)
Tasks: 55 (limit: 4623)
Memory: 6.7M
CPU: 33ms
CGroup: /system.slice/apache2.service
├─54214 /usr/sbin/apache2 -k start
├─54216 /usr/sbin/apache2 -k start
└─54217 /usr/sbin/apache2 -k start
Jun 16 14:33:58 debian systemd[1]: Starting The Apache HTTP Server...
Jun 16 14:33:58 debian apachectl[54213]: AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 192.168.6.131. Set the 'ServerName' directive globally to suppress th>
Jun 16 14:33:58 debian systemd[1]: Started The Apache HTTP Server.
Step 5: Open a web browser, visit your server’s IP address as shown in the below image
Step 6: Install the MariaDB-server by using the below command
root@debian:~# apt install mariadb-server -y
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following additional packages will be installed:
galera-4 libaio1 libcgi-fast-perl libcgi-pm-perl libconfig-inifiles-perl
libdbd-mariadb-perl libdbi-perl libfcgi-bin libfcgi-perl libfcgi0ldbl
libhtml-template-perl libmariadb3 libterm-readkey-perl mariadb-client-10.5
mariadb-client-core-10.5 mariadb-common mariadb-server-10.5
mariadb-server-core-10.5 mysql-common rsync socat
Suggested packages:
libmldbm-perl libnet-daemon-perl libsql-statement-perl libipc-sharedcache-perl
mailx mariadb-test netcat-openbsd
The following NEW packages will be installed:
galera-4 libaio1 libcgi-fast-perl libcgi-pm-perl libconfig-inifiles-perl
libdbd-mariadb-perl libdbi-perl libfcgi-bin libfcgi-perl libfcgi0ldbl
libhtml-template-perl libmariadb3 libterm-readkey-perl mariadb-client-10.5
mariadb-client-core-10.5 mariadb-common mariadb-server mariadb-server-10.5
mariadb-server-core-10.5 mysql-common rsync socat
0 upgraded, 22 newly installed, 0 to remove and 0 not upgraded.
Need to get 16.6 MB of archives.
After this operation, 155 MB of additional disk space will be used.
Get:1 http://deb.debian.org/debian bullseye/main amd64 mysql-common all 5.8+1.0.7 [7,464 B]
Get:2 http://deb.debian.org/debian bullseye/main amd64 mariadb-common all 1:10.5.19-0+deb11u2 [37.0 kB]
Get:3 http://deb.debian.org/debian bullseye/main amd64 galera-4 amd64 26.4.11-0+deb11u1 [804 kB]
Get:4 http://deb.debian.org/debian bullseye/main amd64 libdbi-perl amd64 1.643-3+b1 [780 kB]
Get:5 http://deb.debian.org/debian bullseye/main amd64 libconfig-inifiles-perl all 3.000003-1 [52.1 kB]
Get:6 http://deb.debian.org/debian bullseye/main amd64 libmariadb3 amd64 1:10.5.19-0+deb11u2 [176 kB]
Get:7 http://deb.debian.org/debian bullseye/main amd64 mariadb-client-core-10.5 amd64 1:10.5.19-0+deb11u2 [783 kB]
Get:8 http://deb.debian.org/debian bullseye/main amd64 mariadb-client-10.5 amd64 1:10.5.19-0+deb11u2 [1,508 kB]
Get:9 http://deb.debian.org/debian bullseye/main amd64 libaio1 amd64 0.3.112-9 [12.5 kB]
Get:10 http://deb.debian.org/debian bullseye/main amd64 mariadb-server-core-10.5 amd64 1:10.5.19-0+deb11u2 [6,833 kB]
Get:11 http://deb.debian.org/debian bullseye/main amd64 rsync amd64 3.2.3-4+deb11u1 [396 kB]
Get:12 http://deb.debian.org/debian bullseye/main amd64 socat amd64 1.7.4.1-3 [370 kB]
Get:13 http://deb.debian.org/debian bullseye/main amd64 mariadb-server-10.5 amd64 1:10.5.19-0+deb11u2 [4,284 kB]
Get:14 http://deb.debian.org/debian bullseye/main amd64 libcgi-pm-perl all 4.51-1 [224 kB]
Get:15 http://deb.debian.org/debian bullseye/main amd64 libfcgi0ldbl amd64 2.4.2-2 [26.1 kB]
Get:16 http://deb.debian.org/debian bullseye/main amd64 libfcgi-perl amd64 0.79+ds-2 [27.6 kB]
Get:17 http://deb.debian.org/debian bullseye/main amd64 libcgi-fast-perl all 1:2.15-1 [12.1 kB]
Get:18 http://deb.debian.org/debian bullseye/main amd64 libdbd-mariadb-perl amd64 1.21-3 [110 kB]
Get:19 http://deb.debian.org/debian bullseye/main amd64 libfcgi-bin amd64 2.4.2-2 [12.9 kB]
Get:20 http://deb.debian.org/debian bullseye/main amd64 libhtml-template-perl all 2.97-1.1 [66.2 kB]
Get:21 http://deb.debian.org/debian bullseye/main amd64 libterm-readkey-perl amd64 2.38-1+b2 [27.8 kB]
Get:22 http://deb.debian.org/debian bullseye/main amd64 mariadb-server all 1:10.5.19-0+deb11u2 [35.5 kB]
Fetched 16.6 MB in 2s (9,491 kB/s)
Preconfiguring packages ...
Selecting previously unselected package mysql-common.
(Reading database ... 155616 files and directories currently installed.)
Preparing to unpack .../00-mysql-common_5.8+1.0.7_all.deb ...
Unpacking mysql-common (5.8+1.0.7) ...
Selecting previously unselected package mariadb-common.
Preparing to unpack .../01-mariadb-common_1%3a10.5.19-0+deb11u2_all.deb ...
Unpacking mariadb-common (1:10.5.19-0+deb11u2) ...
Selecting previously unselected package galera-4.
Preparing to unpack .../02-galera-4_26.4.11-0+deb11u1_amd64.deb ...
Unpacking galera-4 (26.4.11-0+deb11u1) ...
Selecting previously unselected package libdbi-perl:amd64.
Preparing to unpack .../03-libdbi-perl_1.643-3+b1_amd64.deb ...
Unpacking libdbi-perl:amd64 (1.643-3+b1) ...
Selecting previously unselected package libconfig-inifiles-perl.
Preparing to unpack .../04-libconfig-inifiles-perl_3.000003-1_all.deb ...
Unpacking libconfig-inifiles-perl (3.000003-1) ...
Selecting previously unselected package libmariadb3:amd64.
Preparing to unpack .../05-libmariadb3_1%3a10.5.19-0+deb11u2_amd64.deb ...
Unpacking libmariadb3:amd64 (1:10.5.19-0+deb11u2) ...
Selecting previously unselected package mariadb-client-core-10.5.
Preparing to unpack .../06-mariadb-client-core-10.5_1%3a10.5.19-0+deb11u2_amd64.deb ...
Unpacking mariadb-client-core-10.5 (1:10.5.19-0+deb11u2) ...
Selecting previously unselected package mariadb-client-10.5.
Preparing to unpack .../07-mariadb-client-10.5_1%3a10.5.19-0+deb11u2_amd64.deb ...
Unpacking mariadb-client-10.5 (1:10.5.19-0+deb11u2) ...
Selecting previously unselected package libaio1:amd64.
Preparing to unpack .../08-libaio1_0.3.112-9_amd64.deb ...
Unpacking libaio1:amd64 (0.3.112-9) ...
Selecting previously unselected package mariadb-server-core-10.5.
Preparing to unpack .../09-mariadb-server-core-10.5_1%3a10.5.19-0+deb11u2_amd64.deb ...
Unpacking mariadb-server-core-10.5 (1:10.5.19-0+deb11u2) ...
Selecting previously unselected package rsync.
Preparing to unpack .../10-rsync_3.2.3-4+deb11u1_amd64.deb ...
Unpacking rsync (3.2.3-4+deb11u1) ...
Selecting previously unselected package socat.
Preparing to unpack .../11-socat_1.7.4.1-3_amd64.deb ...
Unpacking socat (1.7.4.1-3) ...
Setting up mysql-common (5.8+1.0.7) ...
update-alternatives: using /etc/mysql/my.cnf.fallback to provide /etc/mysql/my.cnf (my.cnf) in auto mode
Setting up mariadb-common (1:10.5.19-0+deb11u2) ...
update-alternatives: using /etc/mysql/mariadb.cnf to provide /etc/mysql/my.cnf (my.cnf) in auto mode
Selecting previously unselected package mariadb-server-10.5.
(Reading database ... 156081 files and directories currently installed.)
Preparing to unpack .../0-mariadb-server-10.5_1%3a10.5.19-0+deb11u2_amd64.deb ...
/var/lib/mysql: found previous version 10.5
Unpacking mariadb-server-10.5 (1:10.5.19-0+deb11u2) ...
Selecting previously unselected package libcgi-pm-perl.
Preparing to unpack .../1-libcgi-pm-perl_4.51-1_all.deb ...
Unpacking libcgi-pm-perl (4.51-1) ...
Selecting previously unselected package libfcgi0ldbl:amd64.
Preparing to unpack .../2-libfcgi0ldbl_2.4.2-2_amd64.deb ...
Unpacking libfcgi0ldbl:amd64 (2.4.2-2) ...
Selecting previously unselected package libfcgi-perl:amd64.
Preparing to unpack .../3-libfcgi-perl_0.79+ds-2_amd64.deb ...
Unpacking libfcgi-perl:amd64 (0.79+ds-2) ...
Selecting previously unselected package libcgi-fast-perl.
Preparing to unpack .../4-libcgi-fast-perl_1%3a2.15-1_all.deb ...
Unpacking libcgi-fast-perl (1:2.15-1) ...
Selecting previously unselected package libdbd-mariadb-perl.
Preparing to unpack .../5-libdbd-mariadb-perl_1.21-3_amd64.deb ...
Unpacking libdbd-mariadb-perl (1.21-3) ...
Selecting previously unselected package libfcgi-bin.
Preparing to unpack .../6-libfcgi-bin_2.4.2-2_amd64.deb ...
Unpacking libfcgi-bin (2.4.2-2) ...
Selecting previously unselected package libhtml-template-perl.
Preparing to unpack .../7-libhtml-template-perl_2.97-1.1_all.deb ...
Unpacking libhtml-template-perl (2.97-1.1) ...
Selecting previously unselected package libterm-readkey-perl.
Preparing to unpack .../8-libterm-readkey-perl_2.38-1+b2_amd64.deb ...
Unpacking libterm-readkey-perl (2.38-1+b2) ...
Selecting previously unselected package mariadb-server.
Preparing to unpack .../9-mariadb-server_1%3a10.5.19-0+deb11u2_all.deb ...
Unpacking mariadb-server (1:10.5.19-0+deb11u2) ...
Setting up libconfig-inifiles-perl (3.000003-1) ...
Setting up galera-4 (26.4.11-0+deb11u1) ...
Setting up libfcgi0ldbl:amd64 (2.4.2-2) ...
Setting up libcgi-pm-perl (4.51-1) ...
Setting up libfcgi-bin (2.4.2-2) ...
Setting up libhtml-template-perl (2.97-1.1) ...
Setting up socat (1.7.4.1-3) ...
Setting up libmariadb3:amd64 (1:10.5.19-0+deb11u2) ...
Setting up libfcgi-perl:amd64 (0.79+ds-2) ...
Setting up libterm-readkey-perl (2.38-1+b2) ...
Setting up libaio1:amd64 (0.3.112-9) ...
Setting up libdbi-perl:amd64 (1.643-3+b1) ...
Setting up rsync (3.2.3-4+deb11u1) ...
Setting up mariadb-server-core-10.5 (1:10.5.19-0+deb11u2) ...
Setting up libcgi-fast-perl (1:2.15-1) ...
Setting up libdbd-mariadb-perl (1.21-3) ...
Setting up mariadb-client-core-10.5 (1:10.5.19-0+deb11u2) ...
Setting up mariadb-client-10.5 (1:10.5.19-0+deb11u2) ...
Setting up mariadb-server-10.5 (1:10.5.19-0+deb11u2) ...
Setting up mariadb-server (1:10.5.19-0+deb11u2) ...
Processing triggers for man-db (2.9.4-2) ...
Processing triggers for libc-bin (2.31-13+deb11u6) ...
Step 7: Check the MariaDB status by using the below command
root@debian:~# systemctl status mariadb
● mariadb.service - MariaDB 10.5.19 database server
Loaded: loaded (/lib/systemd/system/mariadb.service; enabled; vendor preset: ena>
Active: active (running) since Fri 2023-06-16 14:38:59 CDT; 2min 34s ago
Docs: man:mariadbd(8)
https://mariadb.com/kb/en/library/systemd/
Process: 54896 ExecStartPre=/usr/bin/install -m 755 -o mysql -g root -d /var/run/>
Process: 54897 ExecStartPre=/bin/sh -c systemctl unset-environment _WSREP_START_P>
Process: 54899 ExecStartPre=/bin/sh -c [ ! -e /usr/bin/galera_recovery ] && VAR= >
Process: 54960 ExecStartPost=/bin/sh -c systemctl unset-environment _WSREP_START_>
Process: 54962 ExecStartPost=/etc/mysql/debian-start (code=exited, status=0/SUCCE>
Main PID: 54946 (mariadbd)
Status: "Taking your SQL requests now..."
Tasks: 9 (limit: 4623)
Memory: 65.4M
CPU: 468ms
CGroup: /system.slice/mariadb.service
└─54946 /usr/sbin/mariadbd
Jun 16 14:38:59 debian mariadbd[54946]: Version: '10.5.19-MariaDB-0+deb11u2' socket:>
Jun 16 14:38:59 debian systemd[1]: Started MariaDB 10.5.19 database server.
Jun 16 14:38:59 debian /etc/mysql/debian-start[54964]: Upgrading MySQL tables if nece>
Jun 16 14:38:59 debian /etc/mysql/debian-start[54967]: Looking for 'mariadb' as: /usr>
Jun 16 14:38:59 debian /etc/mysql/debian-start[54967]: Looking for 'mariadb-check' as>
Jun 16 14:38:59 debian /etc/mysql/debian-start[54967]: This installation of MariaDB i>
Jun 16 14:38:59 debian /etc/mysql/debian-start[54967]: There is no need to run mysql_>
Jun 16 14:38:59 debian /etc/mysql/debian-start[54967]: You can use --force if you sti>
Jun 16 14:38:59 debian /etc/mysql/debian-start[54977]: Checking for insecure root acc>
Jun 16 14:38:59 debian /etc/mysql/debian-start[54981]: Triggering myisam-recover for >
Step 8: Enable the MariaDB by using the below command
root@debian:~# systemctl enable mariadb
Synchronizing state of mariadb.service with SysV service script with /lib/systemd/systemd-sysv-install.
Executing: /lib/systemd/systemd-sysv-install enable mariadb
Step 9: Install the MySQL secure installation and set the root passwd by using the below command.
root@debian:~# 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
haven't set the root password yet, you should just press enter here.
Enter current password for root (enter for none):
OK, successfully used password, moving on...
Setting the root password or using the unix_socket ensures that nobody
can log into the MariaDB root user without the proper authorisation.
You already have your root account protected, so you can safely answer 'n'.
Switch to unix_socket authentication [Y/n] Y
Enabled successfully!
Reloading privilege tables..
... Success!
You already have your root account protected, so you can safely answer 'n'.
Change the 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!
Step 10: Install the PHP by using the below command
root@debian:~# apt install php libapache2-mod-php php-zip php-cli php-common php-curl
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
libapache2-mod-php is already the newest version (2:7.4+76).
php-common is already the newest version (2:76).
php-common set to manually installed.
The following additional packages will be installed:
libzip4 php7.4 php7.4-curl php7.4-zip
The following NEW packages will be installed:
libzip4 php php-cli php-curl php-zip php7.4 php7.4-curl php7.4-zip
0 upgraded, 8 newly installed, 0 to remove and 0 not upgraded.
Need to get 184 kB of archives.
After this operation, 534 kB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 http://deb.debian.org/debian bullseye/main amd64 libzip4 amd64 1.7.3-1 [55.4 kB]
Get:2 http://security.debian.org/debian-security bullseye-security/main amd64 php7.4 all 7.4.33-1+deb11u4 [50.7 kB]
Get:3 http://deb.debian.org/debian bullseye/main amd64 php all 2:7.4+76 [6,340 B]
Get:4 http://deb.debian.org/debian bullseye/main amd64 php-cli all 2:7.4+76 [6,796 B]
Get:5 http://deb.debian.org/debian bullseye/main amd64 php-curl all 2:7.4+76 [6,364 B]
Get:6 http://deb.debian.org/debian bullseye/main amd64 php-zip all 2:7.4+76 [6,360 B]
Get:7 http://security.debian.org/debian-security bullseye-security/main amd64 php7.4-curl amd64 7.4.33-1+deb11u4 [31.1 kB]
Get:8 http://security.debian.org/debian-security bullseye-security/main amd64 php7.4-zip amd64 7.4.33-1+deb11u4 [21.4 kB]
Fetched 184 kB in 0s (694 kB/s)
Selecting previously unselected package libzip4:amd64.
(Reading database ... 156316 files and directories currently installed.)
Preparing to unpack .../0-libzip4_1.7.3-1_amd64.deb ...
Unpacking libzip4:amd64 (1.7.3-1) ...
Selecting previously unselected package php7.4.
Preparing to unpack .../1-php7.4_7.4.33-1+deb11u4_all.deb ...
Unpacking php7.4 (7.4.33-1+deb11u4) ...
Selecting previously unselected package php.
Preparing to unpack .../2-php_2%3a7.4+76_all.deb ...
Unpacking php (2:7.4+76) ...
Selecting previously unselected package php-cli.
Preparing to unpack .../3-php-cli_2%3a7.4+76_all.deb ...
Unpacking php-cli (2:7.4+76) ...
Selecting previously unselected package php7.4-curl.
Preparing to unpack .../4-php7.4-curl_7.4.33-1+deb11u4_amd64.deb ...
Unpacking php7.4-curl (7.4.33-1+deb11u4) ...
Selecting previously unselected package php-curl.
Preparing to unpack .../5-php-curl_2%3a7.4+76_all.deb ...
Unpacking php-curl (2:7.4+76) ...
Selecting previously unselected package php7.4-zip.
Preparing to unpack .../6-php7.4-zip_7.4.33-1+deb11u4_amd64.deb ...
Unpacking php7.4-zip (7.4.33-1+deb11u4) ...
Selecting previously unselected package php-zip.
Preparing to unpack .../7-php-zip_2%3a7.4+76_all.deb ...
Unpacking php-zip (2:7.4+76) ...
Setting up php7.4-curl (7.4.33-1+deb11u4) ...
Setting up libzip4:amd64 (1.7.3-1) ...
Setting up php7.4 (7.4.33-1+deb11u4) ...
Setting up php7.4-zip (7.4.33-1+deb11u4) ...
Setting up php-cli (2:7.4+76) ...
update-alternatives: using /usr/bin/php.default to provide /usr/bin/php (php) in auto mode
update-alternatives: using /usr/bin/phar.default to provide /usr/bin/phar (phar) in auto mode
update-alternatives: using /usr/bin/phar.phar.default to provide /usr/bin/phar.phar (phar.phar) in auto mode
Setting up php-zip (2:7.4+76) ...
Setting up php (2:7.4+76) ...
Setting up php-curl (2:7.4+76) ...
Processing triggers for man-db (2.9.4-2) ...
Processing triggers for libapache2-mod-php7.4 (7.4.33-1+deb11u4) ...
Processing triggers for libc-bin (2.31-13+deb11u6) ...
Processing triggers for php7.4-cli (7.4.33-1+deb11u4) ...
Step 11: Open vim Editor enter the PHP scripting by using the below command.
root@debian:~# vim /var/www/html/info.php
<?php
phpinfo ();
?>
Step 12: Finally restart the Apache webserver by using the below command.
root@debian:~# systemctl restart apache2
Step 13: Next go to the browser to browse the IP address and info.php html file as shown in the below image.
Conclusion:
We have reached the end of this article. In this guide, we have walked you through the steps required to Setup Lamp Stack on Debian 11.4. Your feedback is much welcome.