21 C
Texas
angeloma
Senior Writer and partner

Install Apache web server on Debian 11

Hello folks. With Debian 11 ready for download then the process of supporting it begins. So, in this short post, you will learn how to install Apache web server on Debian 11.

What is Apache web server?

The first thing to say is that when we talk about Apache web server, we are talking about httpd because that is what it is really called. What happens is that this project is sponsored and supported by the Apache Foundation that gives it the nickname.

You can also learn about the speed difference regarding Apache VS NGINX.

So, according to the official website of httpd we have the following definition.

The Apache HTTP Server Project is an effort to develop and maintain an open-source HTTP server for modern operating systems including UNIX and Windows. The goal of this project is to provide a secure, efficient, and extensible server that provides HTTP services in sync with the current HTTP standards.

So, it is one of the most widely used web servers in the world because it is secure, fast, and easy to administer. As expected, it is also compatible with many programming languages and therefore web applications.

- Advertisement -

The installation and administration of Apache are possible thanks to the powerful documentation that is available to everyone. I recommend you take a look at it

Install Apache web server on Debian 11

So, connect to your Debian 11 server and if you haven’t updated it, you can do it in the following way:

apt update
apt upgrade

You have to run these commands as the root user. In case you can use sudo then just use it before the commands I will show you

One of the best things about Apache is that we can find it in the official repositories of many distributions including Debian.

So, you can search the repositories as follows:

apt search apache2

And as result, you will see a lot of Apache-related packages.

To install Apache web server on Debian 11, just run the following command:

apt install apache2
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following additional packages will be installed:
  apache2-bin apache2-data apache2-utils libapr1 libaprutil1 libaprutil1-dbd-sqlite3 libaprutil1-ldap libgdbm-compat4 liblua5.3-0 libperl5.32 mailcap mime-support
  perl perl-modules-5.32
Suggested packages:
  apache2-doc apache2-suexec-pristine | apache2-suexec-custom www-browser perl-doc libterm-readline-gnu-perl | libterm-readline-perl-perl make
  libtap-harness-archive-perl
Recommended packages:
  ssl-cert
The following NEW packages will be installed:
  apache2 apache2-bin apache2-data apache2-utils libapr1 libaprutil1 libaprutil1-dbd-sqlite3 libaprutil1-ldap libgdbm-compat4 liblua5.3-0 libperl5.32 mailcap
  mime-support perl perl-modules-5.32
0 upgraded, 15 newly installed, 0 to remove and 0 not upgraded.
Need to get 9,725 kB of archives.
After this operation, 55.6 MB of additional disk space will be used.
Do you want to continue? [Y/n]

This way, after accepting the installation, it will start. As it is a lightweight web server, the process should not take too long.

Managing the Apache webserver service and testing the installation

By default, upon completion of the Apache installation, the service will be started and enabled. In any case, you can check the status of the service by running:

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-17 21:54:55 CEST; 22s ago
       Docs: https://httpd.apache.org/docs/2.4/
   Main PID: 1963 (apache2)
      Tasks: 55 (limit: 2277)
     Memory: 9.1M
        CPU: 44ms
     CGroup: /system.slice/apache2.service
             ├─1963 /usr/sbin/apache2 -k start
             ├─1965 /usr/sbin/apache2 -k start
             └─1966 /usr/sbin/apache2 -k start

Aug 17 21:54:55 osradar systemd[1]: Starting The Apache HTTP Server...
Aug 17 21:54:55 osradar apachectl[1962]: AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1. Set the 'ServerName'>ug 17 21:54:55 osradar systemd[1]: Started The Apache HTTP Server.

As you can see, the service is running correctly. If you want to stop it, run

systemctl stop apache2

And to start it:

systemctl start apache2

When making changes in the Apache configuration or some of its modules, you will have to restart the service to apply them. To do this, run

systemctl restart apache2

Now, we have to verify that the installation was successful and the best way is to use it.

So, the normal thing is that you are using a Firewall in Debian 11, in case you are, then make sure that the ports 80 and 443 are available.

In case you are using UFW then you can do it in the following way:

ufw allow 80
ufw allow 443

Now yes, you can open a web browser and visit http://your-server-ip and see the following screen

1.- Apache web server on Debian 11
1.- Apache web server on Debian 11

This way, the Apache web server is ready to use.

Install PHP with Apache web server on Debian 11

Apache’s utility is to serve websites. If these websites are static, that is, they are not created with a programming language, then there is no need to install anything else.

Realistically, however, the websites include functionality created in a programming language such as PHP. This language is one of the most popular and that is why it is convenient to install it together with Apache.

So, to install PHP and the add-on module with Apache, just run the following command

apt install php php-cli libapache2-mod-php
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following additional packages will be installed:
  libapache2-mod-php7.4 libsodium23 php-common php7.4 php7.4-cli php7.4-common php7.4-json php7.4-opcache php7.4-readline psmisc
Suggested packages:
  php-pear
The following NEW packages will be installed:
  libapache2-mod-php libapache2-mod-php7.4 libsodium23 php php-cli php-common php7.4 php7.4-cli php7.4-common php7.4-json php7.4-opcache php7.4-readline psmisc
0 upgraded, 13 newly installed, 0 to remove and 0 not upgraded.
Need to get 4,490 kB of archives.
After this operation, 19.3 MB of additional disk space will be used.
Do you want to continue? [Y/n]

For the Apache webserver to recognize the module that allows it to work with PHP, it is necessary to restart the service.

systemctl restart apache2

And now, Apache and PHP are installed and working perfectly. To check this, create a file with PHP extension in the Apache root directory which is /var/www/html/.

nano /var/www/html/test.php

Inside this file, add some PHP code such as the phpinfo() method.

<?php
phpinfo();
?>

Save the changes and close the editor.

Now try to open it from the web browser http://your-server-ip/test.php

2.- PHP working with Apache on Debian 11
2.- PHP working with Apache on Debian 11

So, the Apache web server is working correctly.

Conclusion

Apache web server is a very popular server whose installation allows novices to explore everything about this world. It can also be used in docker images for application deployment.

- Advertisement -
Everything Linux, A.I, IT News, DataOps, Open Source and more delivered right to you.
Subscribe
"The best Linux newsletter on the web"

LEAVE A REPLY

Please enter your comment!
Please enter your name here



Latest article