Install LAMP Stack on Debian 12 Bookworm

In this guide, we want to teach you to Install Apache, MySQL or MariaDB, and PHP known as LAMP Stack on Debian 12 Bookworm.

LAMP Stack is a popular and open-source app that is used for web development. It is used Apache as the web server, MySQL or MariaDB as its database management system, and PHP programming languages are used to create web applications.

Learn To Install LAMP Stack on Debian 12 Bookworm

To set up the LAMP stack on Debian 12, you must have access to your server as a root or non-root user with sudo privileges and set up a basic firewall. To do this, you can visit this guide on Initial Server Setup with Debian 12 Bookworm.

Now follow the steps below to complete this guide.

Step 1 – How To Install Apache on Debian 12?

First, you must update your local package index by using the command below:

sudo apt update

Then, run the following command in your Debian 12 terminal to install Apache:

sudo apt install apache2

By default, Apache should be started during the installation. You can verify it by using the following command:

sudo systemctl status apache2
Output
● apache2.service - The Apache HTTP Server
     Loaded: loaded (/lib/systemd/system/apache2.service; enabled; preset: enab>
     Active: active (running) since Wed 2023-06-14 10:46:44 EDT; 20s ago
       Docs: https://httpd.apache.org/docs/2.4/
   Main PID: 5653 (apache2)
      Tasks: 55 (limit: 4653)
     Memory: 21.2M
        CPU: 148ms
     CGroup: /system.slice/apache2.service
...

Step 2 – Configure Firewall for Apache on Debian 12

Here we assumed that you have enabled the UFW firewall. Now you can list UFW available applications with the following command:

sudo ufw app list

In your output, you should see something similar to this:

Output
Available applications
...
 WWW
  WWW Cache
  WWW Full
  WWW Secure
...

To enable HTTP and HTTPS ports 80 and 443, you can use the “WWW Full” option. See the option information with the command below:

sudo ufw app info "WWW Full"
Output
Profile: WWW Full
Title: Web Server (HTTP,HTTPS)
Description: Web Server (HTTP,HTTPS)

Ports:
  80,443/tcp

Then, allow the ports by using the command below:

sudo ufw allow in "WWW Full"

Reload the firewall to apply the changes:

sudo ufw reload

To get more information about UFW firewall, you can visit this guide on Configure Firewall with UFW on Debian 12 Bookworm.

Step 3 –  Access Apache Debian 12 Default Page

At this point, you can test your Apache installation on Debian 12 by accessing the default page. To do this, type your server’s IP address in your web browser:

http://your-server-ip

Note: If you don’t have your IP address you can use the following command to get it:

hostname -I

You should see the following page:

Apache installation on Debian 12

If you see this page, means that your Apache web server from LAMP Stack is up and running on Debian 12.

Step 4 – How To Install MariaDB on Debian 12?

At this point, we will use MariaDB as our database management system in the LAMP stack. Debian 12 ships with the latest stable version of MariaDB which is MariaDB 10.11.

To install MariaDB, you can use the following command:

sudo apt install mariadb-server -y

When your installation is completed, verify your MariaDB service is active and running on your server with the command below:

sudo systemctl status mariadb
Output
● mariadb.service - MariaDB 10.11.3 database server
     Loaded: loaded (/lib/systemd/system/mariadb.service; enabled; preset: enab>
     Active: active (running) since Wed 2023-06-14 11:00:01 EDT; 21s ago
       Docs: man:mariadbd(8)
             https://mariadb.com/kb/en/library/systemd/
   Main PID: 7100 (mariadbd)
     Status: "Taking your SQL requests now..."
      Tasks: 15 (limit: 4653)
     Memory: 202.0M
        CPU: 851ms
     CGroup: /system.slice/mariadb.service
...

Then, you must run the security script for your MariaDB. To do this, run the command below:

sudo mysql_secure_installation

You will be asked some questions, answer them as shown below and change your MariaDB root password with a strong password:

Enter current password for root (enter for none):
OK, successfully used password, moving on...
Switch to unix_socket authentication [Y/n] n
Change the root password? [Y/n] y
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
 ... Success!

Remove anonymous users? [Y/n] y
 ... Success!

Disallow root login remotely? [Y/n] y
 ... Success!

Remove test database and access to it? [Y/n] y
 - Dropping test database...
 ... Success!
 - Removing privileges on test database...
 ... Success!

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!

At this point, you can access your MariaDB shell by using the command below:

sudo mariadb -u root -p

Enter your password and you should access your shell as shown below:

Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 39
Server version: 10.11.3-MariaDB-1 Debian 12

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)]>

YOu can exit from your MariaDB shell with the command below:

MariaDB [(none)]> EXIT;

Step 5 – How To Install PHP on Debian 12 Bookworm?

By default, Debian 12 ships with PHP 8.2. You can install it on your server by using the command below:

Also, you’ll need php-mysql, a PHP module that allows PHP to communicate with MySQL-based databases. You’ll also need libapache2-mod-php to enable Apache to handle PHP files. Core PHP packages will automatically be installed as dependencies.

sudo apt install php libapache2-mod-php php-mysql

Verify your PHP installation by checking its version:

php -v
Output
PHP 8.2.7 (cli) (built: Jun  9 2023 19:37:27) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.2.7, Copyright (c) Zend Technologies
    with Zend OPcache v8.2.7, Copyright (c), by Zend Technologies

Now you can create a PHP test script to confirm that Apache is able to handle and process requests for PHP files on Debian 12:

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

Then, type your server’s IP address in your web browser followed by info.php:

http://server-ip-address/info.php

Here is an example of the default PHP web page:

default PHP web page Debian 12

After checking the information about your PHP server through that page, it’s best to remove the file you created as it contains sensitive information about your PHP environment and your Debian 12 server. To do this, you can run the command below:

sudo rm /var/www/html/info.php

You can always recreate this page if you need to access the information again later.

Conclusion

At this point, you have learned to Install Apache, MySQL or MariaDB, and PHP known as LAMP Stack on Debian 12 Bookworm. The lamp stack is used for web development. You can easily install it on your Debian 12 and develop your web.

Hope you enjoy it. You may be interested in these articles:

Install LAMP Stack on Debian 11

Install LAMP Stack on Ubuntu 22.04

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles

POPULAR TAGS

Most Popular