How to Install LAMP Stack on Debian 11 bullseye
A LAMP stack is a group of open-source software that is typically installed together to enable a server to host dynamic websites and web apps. This term is actually an acronym which represents the Linux operating system, with the Apache web server. The site data is stored in a MariaDB database, and dynamic content is processed by PHP.
Update Debian 11 Bullseye
apt update && apt -y upgrade
Install MariaDB database server.
To get started with MariaDB installation, follow the below steps:
apt install -y mariadb-server mariadb-client
Check the status of mariaDB database server
systemctl status mariadb
Output:
root@server:~# systemctl status mariadb
● 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-03 19:42:28 IST; 36min ago
Docs: man:mariadbd(8)
Run the command below to secure your database server,
mysql_secure_installation
Using the above command, you can do the following,
-
Set root password.
-
Remove anonymous users.
-
Disable remote login for root user.
- Remove test database and access to it.
You can log in as your root user and set up a regular user and a database.
mysql -u root -p
Output:
root@server:~# mysql -u root -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 52
Server version: 10.5.11-MariaDB-1 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)]>
Install Apache Web Server
Apache is one of the most commonly used web server. You can install by running the below command,
apt install -y apache2 apache2-utils
Output:
root@server:~# apt install -y apache2 apache2-utils
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
apache2-utils is already the newest version (2.4.48-3.1).
Suggested packages: apache2-doc apache2-suexec-pristine | apache2-suexec-custom www-browser
Check apache build and version
apache2 -v
Output:
root@server:~# apache2 -v
Server version: Apache/2.4.41 (Debian)
Server built: 2021-07-05T07:16:56
root@server:~#
Check service status.
systemctl status apache2
Output:
root@server:~# systemctl status apache2
● apache2.service - The Apache HTTP Server
Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled)
Active: active (running) since Tue 2021-08-03 20:22:39 IST; 8min ago
Docs: https://httpd.apache.org/docs/2.4/
Main PID: 20302 (apache2)
Enable http and https ( 80/443 ):
To enable http and https connection through firewall, follow the commads:
sudo ufw allow 80/tcp
sudo ufw allow 443/tcp
Restart service when a change is made && enable the service to start at boot.
systemctl reload apache2
systemctl enable apache2
Open server IP address on your browser(http://
Example
Install PHP
Follow the below steps to install PHP on the server,
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
Output:
root@server:~# 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-cmath
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
Note, selecting 'php7.4-common' instead of 'php-pdo'
The following additional packages will be installed:libapache2-mod-php7.4 php-common php7.4 php7.4-bcmath php7.4-cli php7.4-curl php7.4-fpm php7.4-gd 7.4-json php7.4-mbstring php7.4-mysql php7.4-opcache php7.4-readline php7.4-xml php7.4-zip
Enable Apache module if not already enabled then restart the Web Server.
a2enmod php7.4
Confirm the PHP version
php -v
Output:
root@server:~# php -v
PHP 7.4.21 (cli) (built: Jul 2 2021 03:59:48) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
with Zend OPcache v7.4.21, Copyright (c), by Zend Technologies
In order to test the PHP is working on the server, we will create a small file that will list out all the PHP information available.
Run the below command which will create a file,
echo "<?php phpinfo(); ?>" > /var/www/html/info.php
To view the PHP info on your browser, http://IP_address/info.php
Example.
Once you confirmed that the PHP has been installed and working, remove the info.php for security reasons.
rm /var/www/html/info.php
CrownCloud - Get a SSD powered KVM VPS at $4.5/month!
Use the code WELCOME
for 10% off!
1 GB RAM / 25 GB SSD / 1 CPU Core / 1 TB Bandwidth per month
Available Locations: LAX | MIA | ATL | FRA | AMS