apt install apache2

How to install the Apache HTTP server on Debian and Ubuntu based systems.

95 views
d

By. Jacob

Jacob Kristensen (Turbulentarius) is a Web Developer based in Denmark. He is currently pursuing a Bachelor's degree in Web Development at Zealand, focusing on learning React and refining his existing skills.

Edited: 2024-03-12 18:48

Quick-reference:

sudo apt install apache2

Installing Apache on Ubuntu and Debian

The apt install apache2 command is used to install Apache2 on Debian and Ubuntu based systems, this is just a reminder on how to install the Apache HTTP web server.

You probably also need to enable dependencies after installing Apache. E.g. mod_rewrite.

To enable individual modules use a2enmod. E.g. To enable mod_rewrite use the following:

sudo a2enmod rewrite

To disable it again use a2dismod:

sudo a2dismod rewrite

You should also remember to reload or restart apache after making changes. E.g:

sudo systemctl reload apache2

Typical needed modules

If you use server-sided scripting (E.g. PHP or Python), you may also need to enable the FastCGI protocol; to do so, you need to enable both mod_proxy and mod_proxy_fcgi. E.g:

sudo a2enmod proxy_http
sudo a2enmod proxy_fcgi

Then, do not forget to add other relevant services to your server. E.g. Install PHP-FPM if you wish to run PHP code:

apt install php8.2-fpm

Finally, enabling relevant configuration to handle PHP scripts with PHP-FPM is equally straight forward:

sudo a2enconf php8.2-fpm

Tell us what you think:

  1. Apache removes the Content-Length header set by scripts, affecting response handling and performance.
  2. This article describes configuration issues caused by Apache mischievously picking a default VHOST without telling the user.
  3. In this Tutorial, it is shown how to redirect all HTTP requests to a index.php file using htaccess or Apache configuration files.
  4. How to enable Apache mod_php using a2enmod, and how to find out what the name of the module is.

More in: Apache