Skip to main content

Install, Configure, And Troubleshoot Linux Web Server (Apache).

There are more Linux web servers, but this list is the most used web servers. The most used web servers are Apache and Nginx.

About Apache Web server :

    It is stable.
    It is flexible.
    It is secure.


Install Apache Web server

You can install Apache server on Red Hat based distros using the following command:

$ dnf -y httpd

Or if you are using a Debian-based distro, you can install it like this:

$ apt-get -y install apache2

The Apache web server service is called httpd on Red Hat based distros like CentOS, while it is called apache2 in Debian based distros.
If you are using a firewall like iptables, you should add a rule for port 80.

$ iptables -I INPUT 1 -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT

Or if you are using firewalld, you can use the following command:

$ firewall-cmd --add-port=80/tcp

To start your service and enable it on boot:

$ systemctl start httpd

$ systemctl enable httpd

You can check if your service is running or not, using the following command:

$ systemctl status httpd

Now open your browser and visit http://localhost or http://[::1]/ if you are using IP v6 and if your installation goes well, you should see your HTML homepage.

Configuring Apache Web server

You can add files to Apache in the

/var/www/html

directory for top-level pages.
Just remember to make sure that any files or directories placed in that directory are world-readable. The default index page is index.html.
The Apache configuration files are in
/etc/httpd/conf/
 directory.
 On Debian based systems like Ubuntu, you may find it at

/etc/apache2/apache2.conf

file.
We can’t discuss every option for Apache on a single post, but we will discuss the most important options.
You call them options or directives.

ServerName Option
This option specifies the hostname of the web server that appears to the visitors.

ServerName FQDN

Troubleshooting Apache Web server

If you modify the httpd.conf file and restart or reload Apache web server and it did not work, then you have typed a wrong configuration, however, this is not the only case that you need to troubleshoot Apache, you may look at the apache logs to see how the service works so you can diagnose the problem and solve it.
The two main log files for apache are error_log and access_log files.
You can find these files in

/var/log/apache2/

 directory if you are using Debian based distros.
 The access_log file contains every request to Apache web server with the details about client   requested that resource.
 The error_log file contains errors of Apache web server.
 You can use tail command to watch the log file:

$ tail -f /var/log/httpd/error_log

Comments