How to Install and Configure LAMP on Debian 11 (Bullseye)

It is important to set up a Linux server for the purpose of deploying websites. According to NetCraft.com’s February 2022 surveyYou can find the 1Millions of websites are the busiest in the world, approximately 23.44%Many of them continue to run. Apache.

This tutorial will show you how to install and configure a Linux server. Debian 11 Bullseye) to function as a LAMP server.

What is LAMP Server?

In the computing industry LAMP acronym for Linux(Here to use) Debian 11), Apache, MySQL,And PHP (LAMP). LAMPIt is used commonly to refer to software stacks (specifically). MySQLAnd PHP) on a web server.

Before you dive into the configuration aspects, it’s important to understand the Apache webserver.

What is Apache Web Server?

Apache was one of the “Original” web servers and traces its beginnings back to 1995. Apache is still widely used today. It has a long history, high levels of documentation, and tons of modules that allow for flexibility.

Installing MySQLPHP in Debian 11

1.This is the first section of Debian’s description. MySQL, PHP server. The Linux segment of the LAMPIt is important to do this before installing. Debian 11The following article is about TecMint

Once Debian is ready, now it’s time to install the necessary software using the ‘apt‘ meta-packager.

$ sudo apt install mariadb-server php libapache2-mod-php php-zip php-mbstring php-cli php-common php-curl php-xml php-mysql
Install MySQL and PHP in Debian
Debian installs MySQL and PHP

2.After MySQLAnd PHPIt is recommended that you secure your MySQL installation after the installation is completed. mysql_secure_installationThe utility.

The below command will ask the user to change the root password, remove anonymous users, test databases and remove remote root user logins to the SQL database.

$ sudo mysql_secure_installation
Secure MySQL in Debian
Secure MySQL in Debian

3.This is it! MySQL is configured, let’s move ahead to make some PHP basic settings for this particular server. There are many settings you can configure for PHP. We will only focus on the most basic ones that are usually required.

You can open the php configuration file at /etc/php/7.4/apache2/php.ini.

$ sudo vi /etc/php/7.4/apache2/php.ini

Now search for the string “memory_limit” and increase the limit as per your application needs.

Another important setting to check is the “max_execution_time” and again by default, it will be set to 30. This setting can be modified if an application needs more.

This is the end. MySQLAnd PHP5Now you are ready to start hosting websites. Now it is time for Apache2 to be configured.

Apache2 Installation and Configuration

4. Now it’s time to configure Apache 2to complete the configuration LAMP server. Apache2 configuration begins with installing the software using the apt meta-packager.

$ sudo apt-install apache2

This will install Apache2 and all its dependencies.

Install Apache in Debian
Debian: Install Apache

Once the Apache webserver is installed, it will be available and serving a default page. There are many ways you can confirm that the Apache Webserver is running. The easiest method is to use this lsof utility:

$ sudo lsof -i :80
Check Apache Running Status
Check Apache Running Status

You can also navigate to the IP address for the webserver. Assuming a default Debian install, the system will likely be set to use DHCP automatically to get an IP address.

To determine the IP address of the serverOne of the two utilities can be used. In this case, either utility will work.

$ ip show addition			[Shown below in red]
$ ifconfig			[Shown below in green]
Check IP Address
Check IP Address

The IP address can be used regardless of the utility. It can be entered into a web browser from the same network computer to confirm that Apache is showing the default page.

http://IP-Address
Debian 8: Apache2 Default Page
Debian 8 – Apache2 Default Page

Apache is now up. Although the default Debian page is quite flashy, most users will want to host their own website. The next step will be to set up Apache 2 to host another website.

Apache in Debian: Hosting Multiple Websites

5.Debian has many useful utilities that can be used to manage both sites and modules. Before we can explain how to use these utilities it is important to understand their functions.

  • a2ensiteAfter the appropriate configuration file is created, this utility is used to activate a website.
  • a2dissite: This utility is used to disable a website by specifying the website’s configuration file.
  • a2enmodThis utility is used for additional Apache2 modules.
  • a2dismod: This utility can be used to disable additional Apache2 modules.
  • a2queryThis utility can be used for gathering information about sites that are currently available.

First of let’s gather some experience with the first two. Since Apache 2 is currently hosting the ‘Homepage default‘ let’s go ahead and disable it with a2dissite.

$ sudo a2dissite 000-default.conf
Disable Default Apache Page
Disable Default Apache Page

This command will disable default apache website as seen in the above screenshot. To make any changes, the Apache 2 configuration needs to be reloaded.

$ sudo systemctl reload apache2

This command will instruct Apache 2 that it should update the disabled and enabled sites it is currently hosting. This can be confirmed by attempting to connect to the web server’s IP address again and noticing that nothing is displayed (some computers will cache information, if the machine still shows the default website after the previous two commands are run, try clearing out the web-browsers cache). You can also use the following command to confirm that the site has been disabled. a2query utility.

$ sudo a2query -s
Check Apache Sites Enable/Disable Status
Check Apache Sites Enable/Disable Status

There is a lot going on in this screen-shot so let’s break things down.

  • The green box is the one above. a2query -sThis instructs Apache 2 how to list the sites currently being served.
  • The yellow box is a2dissite 000-default.confNext, follow service apache2 refresh. These two commands instruct Apache 2 that it disables the default site and then reloads the active/inactive websites.
  • The red box is a2query -sNotice that Apache replies that Apache is not being served.

Let’s walk through creating a non-default site now. Switching to the Apache 2 configuration directory is the first step. /etc/apache2Use the cd utility.

$ cd /etc/apache2

There are several important files and directories in this directory, however, for brevity’s sake, only the necessities will be covered here.

The first thing to do when setting up a new site is to create a new configuration file in the ‘sites-available‘ directory. Change directories into the ‘sites-available‘ directory and then create a new configuration file.

$ CD sites-available
$ sudo cp 000-default.conf tecmint-test-site.conf

This will copy the configuration of the default site to the new site configuration file. Open the new site configuration page using a text editor.

$ sudo vi tecmint-test-site.conf

Within this file there is one very important line for getting a website hosted, that line is the ‘DocumentRoot‘ line. This line tells Apache which web files it should serve for requests that request particular resources.

For now, this line will be set to a directory that doesn’t exist but will shortly and will contain a simple website for this Debian server to display.

DocumentRoot /var/www/tecmint
Apache New Site Configuration
Apache New Site Configuration

Save the changes to the file and exit the text editor.

Now, the directory that Apache 2 was instructed to serve files from must be created and populated. While this article will work HTML files, there isn’t possibly enough time to walk through how to create a full functioning website and leaves that process to the reader.

So let’s create the directory for apache to serve and add a basic html webpage to it called ‘index.html‘.

$ sudo mkdir /var/www/tecmint
$ touch /var/www/tecmint/index.html
$ echo “It's ALIVE!” >> /var/www/tecmint/index.html

The above commands will create a new directory called ‘tecmint‘ as well as a new file called ‘index.html‘ in the tecmint directory.

The echo commandYou will insert some text into the file to make sure that the website is displayed in the browser when Apache renders it.

Notification: The page created by the author for this tutorial will display differently! Apache must be instructed to serve the new html document using the commands we have discussed.

$ sudo a2ensite tecmint-test-site.conf
$ sudo systemctl reload apache2
$ sudo a2query -s tecmint-test-site.conf

The last command above will confirm that Apache2 has indeed created the website. At this point, navigate a web browser to the server’s IP address again and see if the newly created website is being displayed (again computers like to cache data and as such, several refreshes may be necessary to get the new webpage).

New Apache Site
New Apache Site

If the newly created “It’s ALIVE!!!” site is showing up, then Apache 2 has been successfully configured and is displaying the website.

Congratulations! This is a very simple setup that prepares you to be successful. Linux LAMPserver to host your site. There are more complicated things you can do and the configuration will depend on what end goal you have.

Leave a Reply

Your email address will not be published.