Article Image
read

Based on the fact that I'm very interested in web development, I'm confronted with web servers and their configurations often. So maybe you would like to start programming a simple JavaScript application or start something bigger. In any case you need a web server on your side.

In this example I'll guide you through the first steps with your Apache web server on Debian/Linux. I choose this special Linux distribution because it is the most stable and common way to get professional servers online.

What is a web server?

A web server is a service, which provides a website or web services and answers HTTP-requests. For example a client, in most cases with a web browser, asks a server for an answer with the help of the HTTP-protocol. The server can now provide the data, answer through it, the client can see a website or even receive information to work with it.

For this kind of requests the client and also the server are using the default port 80 to communicate. In fact, the port 80 was only used for unencrypted communication. Since SSL/TLS encryption is a must-have for every website, it is also good to know, that port 443 is used for this encrypted communication.

What is Apache?

Apache is an open source project and is the most used web server on the Internet. This is based on the fact that Apache has a large community and that it can be used as a private server but also can handle huge amounts of requests, due to his stable architecture. There are also many modifications available, which you can use to configure your server after your preferences.

How to install it?

On Debian you can install the apache2-package which is served by the default repositories.

apt install apache2

In many other distributions of Linux you can find the package under the name httpd.

But not only for Debian/Linux you can install an Apache server. Just visit apache.org. There are good documentations for any kind of operating systems.

It works!

If you installed the apache2 server on your system, you can now open your web browser and visit localhost if the server is installed on your own computer or open http://[your ip / or domain].

The default-page comes up with the message: It works!

How to start?

The Apache server is now part of your system. It will automatically start with your OS. To get an overall-view, let's make some customizations.

Configuration

As you have already seen, the web server has a default configuration. Configurations are located in /etc/apache2/. Here the configuration files have two folders.

  • sites-available
  • sites-enabled

In the folder sites-available you can find all configurations on the server. These files are the base of all configurations. If you want to enable a configuration you can use the following command

# Enable a configuration
a2ensite your-configuration.conf

# Disable a configuration
a2dissite your-configuration.conf

Inside the .conf files

For a small explanation you can use this configuration snipped for a default page

<VirtualHost *:80>
    # ServerName your-domain.tld
    DocumentRoot /var/www/html>
    ErrorLog ${APACHE_LOG_DIR}/error.log
</VirtualHost>

VirtualHost-Tag

The VirtualHost-Tag is used to structure the configuration. As in HTML or XML there is an opening tag and a closing tag. In the opening tag you can also provide an IP or set a * for all. Also the port can be set in the opening tag.

ServerName

The ServerName is your domain you want the server to listen on. If you have installed the server on your computer you can delete this row.

DocumentRoot

The DocumentRoot is the path to your website. You should move your website documents here. If your files are in this directory the apache2-service needs access on this files. You can simple grant access to it with the following command for Debian/Linux.

chown -R www-data. /var/www/html

ErrorLog

If there are any errors on the apache2-service it will be logged to this file. The default path on Debian/Linux is /var/log/apache/error.log but you can change it as well. Keep an eye on the permissions of the folder.

Reload Configurations

If you want to enable the configurations you can reload the apache2-service to trigger a reload on the configuration files. In case you are not sure if your .conf are syntactically correct, you can use the systax check.

# Reload the apache-service
systemctl reload apache2.service

# Testing for syntactically errors
apachectl -t

Conclusion

This was my little post about the Apache web server on Debian/Linux. If you liked the post, don't forget to share it with your friends or colleges.

Blog Logo

Yanneck Meyer

Software engineer by heart and interested in webdevelopment and OOP.


Published

Image
Back to overview