Apache

The Apache HTTP server ist a free to use, open source webserver which has been published in 1995 and is currently the most used webserver (February 2020 – see “What is a webserver?“).

The installations process for the Apache webserver is mostly different on every linux distribution. In the following example I will show you how to install it on a Debian/Ubuntu based system.

sudo apt-get install apache2

After that you should be able to check the Apache2 version with:

apache2 -v

As usual in Debian based distributions the config files are located in /etc/apache2

In this folder we have the following files and folders:

  • apache2.conf
    • General Apache2 config file
  • conf-available
    • Contains additional config files which can be added to the default config
  • conf-enabled
    • Contains symbolic links to the “conf-available” which to show which configs should be enabled and which not.
  • envvars
    • Environment config for the Apache2
  • mods-available
    • same as conf-available just for Apache2 modules
  • mods-enabled
    • same as conf-enabled just for Apache2 modules
  • ports.conf
    • contains settings on which ports the server should listen
  • sites-available
    • same as conf-available just for vHost configs
  • sites-enabled
    • same as conf-available just for vHost configs
  • magic
    • Rules on which MIME-Types should be detected

Standard Apache vHost config

Folder: /etc/apache2/sites-available/<filename>

<VirtualHost *:80>
    ServerName www.domain.com
    ServerAlias domain.com
    DocumentRoot /var/www/html/docroot
</VirtualHost>

Explenation

  • VirtualHost *:80
    • Listen on the port 80
  • ServerName www.domain.com
    • Use this configuration if the hostname is “www.domain.com”
  • ServerAlias domain.com
    • Also use this configuration if the hostname is “domain.com”
  • DocumentRoot /var/www/html/docroot
    • Show the content of the folder “/var/www/html/docroot”

Activate a new vHost config

ln -s /etc/apache2/sites-available/<Dateiname> /etc/apache2/sites-enabled/<Dateiname>

Test the new Apache vHost config

apache2ctl configtest

Restart the Apache webserver

apache2ctl restart

Add a PHP-Handler

In Ubuntu/Debian based systems its pretty easy since its just a package which you can install via apt-get.

sudo apt-get install -y php7.2-curl php7.2-gd php7.2-json php7.2-mbstring php7.2-mcrypt libapache2-mod-php7.2

The most important package here is “libapache2-mod-php7.2” which connects the globally installed PHP and the Apache webserver. See mod_php for more details.

Instead of php7.2 you can of course use php7.3 or any other future PHP version.

If everything went well you can restart the webserver with apachectl restart and create a new file /var/www/html/info.php with the following content:

<?php phpinfo();

After that you can open your webbrowser and open the following URL

http://<Server-IP>/info.php

Now you should see a PHP-Info page.

Share this post

Leave a Reply

Your email address will not be published. Required fields are marked *

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

The reCAPTCHA verification period has expired. Please reload the page.