{"id":684,"date":"2016-02-08T17:11:36","date_gmt":"2016-02-08T15:11:36","guid":{"rendered":"http:\/\/www.systemcodegeeks.com\/?p=684"},"modified":"2018-08-29T11:59:21","modified_gmt":"2018-08-29T08:59:21","slug":"apache-configuration-tutorial","status":"publish","type":"post","link":"https:\/\/www.systemcodegeeks.com\/web-servers\/apache\/apache-configuration-tutorial\/","title":{"rendered":"Apache Configuration Tutorial (CentOS \/ Ubuntu Linux)"},"content":{"rendered":"<p><em>In this post, we feature a comprehensive Apache Configuration Tutorial. This article is part of our Academy Course titled <a href=\"https:\/\/www.systemcodegeeks.com\/web-servers\/apache\/apache-http-server-tutorial\/\">Apache HTTP Server Tutorial<\/a>.<\/em><\/p>\n<p>In this\u00a0Apache Configuration Tutorial course, we provide a compilation of Apache HTTP Server tutorials that will help you get started with this web server. We cover a wide range of topics, from installing the server and performing a basic configuration, to configuring Virtual Hosts and SSL support. With our straightforward tutorials, you will be able to get your own projects up and running in minimum time. Check it out <a href=\"https:\/\/www.systemcodegeeks.com\/web-servers\/apache\/apache-http-server-tutorial\/\">here<\/a>!<\/p>\n<p>In the <a href=\"http:\/\/www.systemcodegeeks.com\/web-servers\/apache\/how-to-install-the-apache-web-server\/\">first article of this series<\/a> we introduced you to Apache. If you took the time to read the introduction, you will have noticed that it is the number one server powering websites and Internet-facing computers &#8211; and there are plenty of good reasons for that.<\/p>\n<p>In this guide we will discuss one of those reasons: its easiness of configuration and seamless integration with server-side scripting languages such as PHP in the context of a standalone web server. In this type of setup, Apache is used to serve a single domain or application, as opposed to running several sites off a single system (also known as <strong>virtual hosting<\/strong>, the topic of our next tutorial).<br \/>\n[ulp id=&#8217;euI76dOod8fb2P3K&#8217;]<br \/>\n&nbsp;<br \/>\n<strong>Note:<\/strong> The configuration syntax and directives of Apache have changed a bit from version 2.2 to 2.4. In addition, some well-known directives in version 2.2 have been deprecated in 2.4. If you followed the steps in the previous tutorial, you should have installed the latest version of the web server (2.4 at the time of this writing).<\/p>\n<p>As you can see in Fig. 1, you can verify the Apache version in CentOS with<\/p>\n<pre class=\"brush:bash\">httpd -v<\/pre>\n<p>and in Ubuntu using<\/p>\n<pre class=\"brush:bash\">apache2 -v<\/pre>\n<figure id=\"attachment_752\" aria-describedby=\"caption-attachment-752\" style=\"width: 431px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/02\/01part2.jpg\" rel=\"attachment wp-att-752\"><img decoding=\"async\" class=\"wp-image-752 size-full\" src=\"http:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/02\/01part2.jpg\" alt=\"Figure 1: Apache Configuration Tutorial: Viewing the installed Apache version\" width=\"431\" height=\"244\" srcset=\"https:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/02\/01part2.jpg 431w, https:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/02\/01part2-300x170.jpg 300w\" sizes=\"(max-width: 431px) 100vw, 431px\" \/><\/a><figcaption id=\"caption-attachment-752\" class=\"wp-caption-text\">Figure 1: Viewing the installed Apache version<\/figcaption><\/figure>\n<h2>1. Inspecting the Apache configuration file<\/h2>\n<p>As you can already tell based on the first article, the only difference between the Apache installations in CentOS and Ubuntu is the package name. Thus, it is to be expected that the main configuration file be named differently (<strong>httpd.conf<\/strong> in CentOS and <strong>apache2.conf<\/strong> in Ubuntu) and located in a different place in each distribution (<strong>\/etc\/httpd\/conf\/<\/strong> and <strong>\/etc\/apache2\/<\/strong>, respectively).<\/p>\n<p>Regardless of the distribution, the main configuration file contains the configuration directives that give the server its instructions. You will use this file to configure system-wide settings for the web server, and additional files to set up virtual hosts (but again, we will expand more on that last topic in the next guide).<\/p>\n<p>It is important to note that you should understand and familiarize yourself with the directives in the configuration file before making changes that can potentially affect the operation of the web server.<\/p>\n<h2>2. Apache modules<\/h2>\n<p>You can easily extend the web server&#8217;s operation by using independent, separate pieces of software called <strong>modules <\/strong>that provide specific functionality. Some modules come built-in with Apache, while others can be installed using your distribution&#8217;s package management system and enabled to integrate with the web server. Although we will discuss modules in later guides of this series, it is important to have this definition in mind before we dive into the configuration directives. You will see the reason in a minute.<\/p>\n<h2>3. Configuration directives<\/h2>\n<p>The following directives are listed in the main configuration file. All of them (and many, many more!) are explained thoroughly in the Apache 2.4 configuration docs online at http:\/\/httpd.apache.org\/docs\/current\/.<\/p>\n<div class=\"tip\">\n<p>If you want or need to read the Apache documentation offline, you can install the package <strong>httpd-manual<\/strong> in CentOS:<\/p>\n<pre class=\"brush:bash\">yum install httpd-manual<\/pre>\n<p>and <strong>apache2-doc<\/strong> in Ubuntu:<\/p>\n<pre class=\"brush:bash\">sudo apt-get install apache2-doc<\/pre>\n<p>You can then access the docs through a web browser (<strong>http:\/\/<em>server<\/em>\/manual<\/strong>, where <em><strong>server<\/strong><\/em> must be replaced with the hostname or the IP address of the machine). This tool can come in handy if at a given time you cannot access the Internet to check the same resource online.<\/p>\n<\/div>\n<div>\n<table style=\"height: 805px;\" border=\"1\" width=\"674\">\n<tbody>\n<tr>\n<td><strong>Directive<\/strong><\/td>\n<td><strong>Description<\/strong><\/td>\n<td><strong>Example<\/strong><\/td>\n<\/tr>\n<tr>\n<td><code>ServerRoot<\/code><\/td>\n<td>The directory tree where the server&#8217;s configuration, error, and log files are kept.<\/td>\n<td><code>Example<\/code><\/td>\n<\/tr>\n<tr>\n<td><code>Listen<\/code><\/td>\n<td>The IP and port where Apache is bound. The default is listening on port 80 of all network interfaces, although it is more secure to specify a single IP address.<\/td>\n<td><code>Listen 192.168.0.100:80<\/code><\/td>\n<\/tr>\n<tr>\n<td><code>User<\/code><br \/>\n<code>Group<\/code><\/td>\n<td>The name of the user\/group to run the web server as. It is usually good practice to create a dedicated user and group for running Apache, as it is the case with most system services. You can also use the UID and the GID instead of the username and groupname, although it is not common to do so.<\/td>\n<td><code>User apache<\/code><br \/>\n<code>Group apache<\/code><\/td>\n<\/tr>\n<tr>\n<td><code>ServerAdmin<\/code><\/td>\n<td>The system administrator&#8217;s email address. Problems with the server will be sent to this address.<\/td>\n<td><code>ServerAdmin root@localhost<\/code><\/td>\n<\/tr>\n<tr>\n<td><code>ServerName<\/code><\/td>\n<td>The hostname and port that the server uses to identify itself.<\/td>\n<td><code>ServerName www.example.com:80<\/code><\/td>\n<\/tr>\n<tr>\n<td><code>DocumentRoot<\/code><\/td>\n<td>The root directory where web pages and directories will be stored by default. Although all requests are taken made to this directory, you can create symbolic links to point to other locations.<\/td>\n<td><code>DocumentRoot \"\/var\/www\/html\"<\/code><\/td>\n<\/tr>\n<tr>\n<td><code>ErrorLog<\/code><\/td>\n<td>The location of the error log file<\/td>\n<td><code>ErrorLog \"logs\/error_log\"<\/code><\/td>\n<\/tr>\n<tr>\n<td><code>LogLevel<\/code><\/td>\n<td>Controls the verbosity of messages logged to ErrorLog. Possible values include:<\/p>\n<ol>\n<li><code>debug<\/code><\/li>\n<li><code>info<\/code><\/li>\n<li><code>notice<\/code><\/li>\n<li><code>warn<\/code><\/li>\n<li><code>error<\/code><\/li>\n<li><code>crit<\/code><\/li>\n<li><code>alert<\/code><\/li>\n<li><code>emerg<\/code><\/li>\n<\/ol>\n<p>When a particular level is specified, messages from higher levels (indicated by the numbered list above) will be logged as well.<\/td>\n<td><code>LogLevel warn<\/code><\/td>\n<\/tr>\n<tr>\n<td><code>Directory<\/code><\/td>\n<td>Used to enclose a group of directives that will apply only to the named directory and all its contents.<\/td>\n<td><code>&lt;Directory \/&gt;<br \/>\nAllowOverride none<br \/>\nRequire all denied<br \/>\n&lt;\/Directory&gt;<\/code><\/td>\n<\/tr>\n<tr>\n<td><code>Files<\/code><\/td>\n<td>Use to limit the scope of the enclosed directives by filename instead of by directory. Wildcards and other regular expressions are allowed.<\/td>\n<td><code>&lt;Files \"restricted.html\"&gt;<br \/>\n# Insert here directives that apply only to restricted.html<br \/>\n&lt;\/Files&gt;<\/code><\/td>\n<\/tr>\n<tr>\n<td><code>IfModule<\/code><\/td>\n<td>Used to specify directives that are only applied if a specific module is present.<\/td>\n<td><code>&lt;IfModule mod_rewrite.c&gt;<br \/>\nRewriteEngine on<br \/>\n&lt;\/IfModule&gt;<\/code><\/td>\n<\/tr>\n<tr>\n<td><code>Include<\/code><\/td>\n<td>Includes other existing configuration files. If an absolute path is not used, it is relative to the <code>ServerRoot<\/code> directory.<\/td>\n<td><code>Include conf\/ssl.conf<\/code><\/td>\n<\/tr>\n<tr>\n<td><code>IncludeOptional<\/code><\/td>\n<td>Similar to the <code>Include<\/code> directive, with the only difference is that it is ignored if there are no matches instead of causing an error (as it is the case with <code>Include<\/code>).<\/td>\n<td><code>IncludeOptional sites-enabled\/*.conf<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<div class=\"tip\">\n<p>To view the values of a certain directive quickly from the command line instead of opening the configuration file, you can use grep as follows. Let&#8217;s say we want to find out what is the directory where Apache is expecting web pages and directories to be stored by default. Yes, you guessed it right &#8211; that information is provided by the value of the <strong>DocumentRoot<\/strong> directive:<\/p>\n<pre class=\"brush:bash\">grep -i documentroot \/etc\/httpd\/conf\/httpd.conf<\/pre>\n<p>or<\/p>\n<pre class=\"brush:bash\">grep -i documentroot \/etc\/apache2\/apache2.conf<\/pre>\n<p>in CentOS and Ubuntu, respectively.<\/p>\n<\/div>\n<p>As we said before, these and all of the Apache directives are well documented in the project&#8217;s website and through the <strong>httpd-manual<\/strong> and <strong>apache2-doc<\/strong> packages. If you click on the <strong>Directives<\/strong> link at the top of the page (see Fig. 2):<\/p>\n<figure id=\"attachment_753\" aria-describedby=\"caption-attachment-753\" style=\"width: 543px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/02\/02part2.jpg\" rel=\"attachment wp-att-753\"><img decoding=\"async\" class=\"wp-image-753 size-full\" src=\"http:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/02\/02part2.jpg\" alt=\"Figure 2 - Apache Configuration Tutorial: The Directives page\" width=\"543\" height=\"92\" srcset=\"https:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/02\/02part2.jpg 543w, https:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/02\/02part2-300x51.jpg 300w\" sizes=\"(max-width: 543px) 100vw, 543px\" \/><\/a><figcaption id=\"caption-attachment-753\" class=\"wp-caption-text\">Figure 2 &#8211; The Directives page<\/figcaption><\/figure>\n<p>you will be taken to the complete list of directives available in the current version of Apache. Choose any directive (we will use <strong>Include<\/strong> as example) and click on the link to be redirected to the detailed description. Pay attention to the highlighted area in Fig. 3 below:<\/p>\n<figure id=\"attachment_754\" aria-describedby=\"caption-attachment-754\" style=\"width: 623px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/02\/03part2.jpg\" rel=\"attachment wp-att-754\"><img decoding=\"async\" class=\"wp-image-754 size-full\" src=\"http:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/02\/03part2.jpg\" alt=\"Figure 3 -Apache Configuration Tutorial:  Context of an Apache directive\" width=\"623\" height=\"225\" srcset=\"https:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/02\/03part2.jpg 623w, https:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/02\/03part2-300x108.jpg 300w, https:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/02\/03part2-620x225.jpg 620w\" sizes=\"(max-width: 623px) 100vw, 623px\" \/><\/a><figcaption id=\"caption-attachment-754\" class=\"wp-caption-text\">Figure 3 &#8211; Context of an Apache directive<\/figcaption><\/figure>\n<p>Each directive has a Context, or in other words, a place where it is valid and has meaning to the operation of the web server. In the case of <strong>Include<\/strong>, the description indicates that it can only be used in the system-wide server configuration, inside a virtual host definition, and within Directory tags. If you attempt to use it in a different place or inside the wrong set of tags (such as inside <strong>IfModule<\/strong> or <strong>Files<\/strong>), the web server will complain about it by refusing to restart correctly.<\/p>\n<h2>3. Basic authentication<\/h2>\n<p>Another set of directives, not outlined in the table above as they are not typically present out of the box in the configuration file, are those related with authentication and authorization. These settings allow to grant access to resources after a user has entered valid credentials.<\/p>\n<p>Although there are other authentication mechanisms, we will only cover basic authentication in this guide (which consists of username and password) for brevity. Please be aware that this method sends the password from the server to the client unencrypted, so it should not be used with sensitive data (in a later tutorial we will introduce more secure options). You can refer to the <a href=\"http:\/\/httpd.apache.org\/docs\/2.4\/howto\/auth.html\" target=\"_blank\" rel=\"noopener\">Authentication and Authorization<\/a> page of the documentation for further details.<\/p>\n<p>To create a password for user <strong>jdoe<\/strong> (which does not necessarily have to exist as a system user) and store them securely in a new password file named passwds inside <strong>\/etc\/httpd\/conf<\/strong> or <strong>\/etc\/apache2<\/strong> (in CentOS and Ubuntu, respectively), follow these steps (don&#8217;t forget to use <strong>sudo<\/strong> to gain administrative privileges and to change the path to the file to <strong>\/etc\/apache2\/passwds<\/strong> if you&#8217;re using Ubuntu):<\/p>\n<p><strong>Step 1 &#8211;<\/strong> Create the file with htpasswd, the tool that is used to manage basic authentication credentials. Use the -c option to indicate that we are creating a non-existent file:<\/p>\n<pre class=\"brush:bash\">htpasswd -c \/etc\/httpd\/conf\/passwds jdoe<\/pre>\n<p><strong>Step 2 &#8211;<\/strong> Choose a new password for jdoe and enter it twice when you are prompted to do so.<\/p>\n<p><strong>Step 3 &#8211;<\/strong> Change ownership of the file to the user Apache is running as and set its permissions to 600:<\/p>\n<p>In CentOS:<\/p>\n<pre class=\"brush:bash\">chown apache:apache \/etc\/httpd\/conf\/passwds\r\nchmod 600 \/etc\/httpd\/conf\/passwds<\/pre>\n<p>In Ubuntu:<\/p>\n<pre class=\"brush:bash\">chown www-data:www-data \/etc\/apache2\/passwds\r\nchmod 600 \/etc\/apache2\/passwds<\/pre>\n<p>Let&#8217;s take a look at what the contents of the file looks like in Fig. 4 (username and encrypted password are separated by a colon):<\/p>\n<figure id=\"attachment_755\" aria-describedby=\"caption-attachment-755\" style=\"width: 410px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/02\/04part2.jpg\" rel=\"attachment wp-att-755\"><img decoding=\"async\" class=\"wp-image-755 size-full\" src=\"http:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/02\/04part2.jpg\" alt=\"Figure 4: Apache Configuration Tutorial: The Apache passwords file\" width=\"410\" height=\"113\" srcset=\"https:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/02\/04part2.jpg 410w, https:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/02\/04part2-300x83.jpg 300w\" sizes=\"(max-width: 410px) 100vw, 410px\" \/><\/a><figcaption id=\"caption-attachment-755\" class=\"wp-caption-text\">Figure 4: The Apache passwords file<\/figcaption><\/figure>\n<p>In the following section you will see how to use these credentials to authenticate user <strong>jdoe<\/strong> and authorize him to access a resource served by Apache.<\/p>\n<p>If you want to add other users to the same file, use <strong>htpasswd<\/strong> as explained earlier, only omitting the <strong>-c<\/strong> switch since the file now exists (no need to create a different one).<\/p>\n<h2>4. Directives in action<\/h2>\n<p>To put into practice all of what we have discussed so far, let us work with and modify the example given in the first article of this series. You will recall that we created a simple page named <strong>index.html<\/strong> inside <strong>\/var\/www\/html<\/strong>. This directory, as you have learned in this guide, is of special importance as it is the default <strong>DocumentRoot<\/strong>.<\/p>\n<p>Let&#8217;s picture the following scenario. We need to serve a file named <strong>restricted.html<\/strong> (also located inside <strong>\/var\/www\/html<\/strong>) but only allow user <strong>jdoe<\/strong> to access such file after entering his password. Other files present inside <strong>DocumentRoot<\/strong> must be accessible to all users without authentication. Of course, this approach assumes this file exists in that directory already. If not, you can use the following example (open with your preferred text editor and save as <strong>restricted.html<\/strong>):<\/p>\n<pre class=\"brush:xml\">&lt;!DOCTYPE html&gt;\r\n&lt;html&gt;\r\n&lt;head&gt;\r\n&lt;meta charset=utf-8 \/&gt;\r\n&lt;title&gt;Restricted file&lt;\/title&gt;\r\n&lt;\/head&gt;\r\n&lt;body&gt;\r\n&lt;h1&gt;Restricted file&lt;\/h1&gt;\r\n&lt;img src=\"http:\/\/files.softicons.com\/download\/folder-icons\/dellios-system-icons-by-dellustrations\/png\/128\/restricted.png\" \/&gt;\r\n&lt;\/body&gt;\r\n&lt;\/html&gt;<\/pre>\n<p>To accomplish our goal, let&#8217;s open the Apache configuration file and add the following <strong>Directory<\/strong> block:<\/p>\n<pre class=\"brush:xml\">&lt;Directory \/var\/www\/html&gt;\r\n&lt;Files restricted.html&gt;\r\nAuthType Basic\r\nAuthName \"SystemCodeGeeks - Restricted file\"\r\nAuthBasicProvider file\r\nAuthUserFile \/etc\/apache2\/passwds\r\nRequire user jdoe\r\n&lt;\/Files&gt;\r\n&lt;\/Directory&gt;<\/pre>\n<p>Now restart Apache:<\/p>\n<p>In CentOS:<\/p>\n<pre class=\"brush:bash\">systemctl restart httpd<\/pre>\n<p>In Ubuntu:<\/p>\n<pre class=\"brush:bash\">service apache2 restart<\/pre>\n<p>And browse to <strong>http:\/\/<em>server<\/em>\/restricted.html<\/strong> (where, again, you will need to replace <strong><em>server<\/em><\/strong> with the hostname or IP address of your server) as shown in Fig. 5:<\/p>\n<figure id=\"attachment_756\" aria-describedby=\"caption-attachment-756\" style=\"width: 607px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/02\/05part2.jpg\" rel=\"attachment wp-att-756\"><img decoding=\"async\" class=\"wp-image-756 size-full\" src=\"http:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/02\/05part2.jpg\" alt=\"Apache Configuration Tutorial: 05part2\" width=\"607\" height=\"224\" srcset=\"https:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/02\/05part2.jpg 607w, https:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/02\/05part2-300x111.jpg 300w\" sizes=\"(max-width: 607px) 100vw, 607px\" \/><\/a><figcaption id=\"caption-attachment-756\" class=\"wp-caption-text\">FIgure 5 &#8211; Browsing to the restricted page<\/figcaption><\/figure>\n<p>If you do not enter valid credentials, you will get the following error message:<\/p>\n<figure id=\"attachment_757\" aria-describedby=\"caption-attachment-757\" style=\"width: 565px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/02\/06part2.jpg\" rel=\"attachment wp-att-757\"><img decoding=\"async\" class=\"wp-image-757 size-full\" src=\"http:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/02\/06part2.jpg\" alt=\"Figure 6 - Apache Configuration Tutorial: Without valid credentials, a restricted resource cannot be accessed\" width=\"565\" height=\"269\" srcset=\"https:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/02\/06part2.jpg 565w, https:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/02\/06part2-300x143.jpg 300w\" sizes=\"(max-width: 565px) 100vw, 565px\" \/><\/a><figcaption id=\"caption-attachment-757\" class=\"wp-caption-text\">Figure 6 &#8211; Without valid credentials, a restricted resource cannot be accessed<\/figcaption><\/figure>\n<p>Otherwise, you will be able to see the page:<\/p>\n<figure id=\"attachment_758\" aria-describedby=\"caption-attachment-758\" style=\"width: 412px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/02\/07part2.jpg\" rel=\"attachment wp-att-758\"><img decoding=\"async\" class=\"wp-image-758 size-full\" src=\"http:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/02\/07part2.jpg\" alt=\"Figure 7 - Apache Configuration Tutorial: With valid credentials, the resource can be accessed\" width=\"412\" height=\"272\" srcset=\"https:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/02\/07part2.jpg 412w, https:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/02\/07part2-300x198.jpg 300w\" sizes=\"(max-width: 412px) 100vw, 412px\" \/><\/a><figcaption id=\"caption-attachment-758\" class=\"wp-caption-text\">Figure 7 &#8211; With valid credentials, the resource can be accessed<\/figcaption><\/figure>\n<p>Congratulations! You have configured your Apache web server to serve content based on user basic authentication.<\/p>\n<h2>5. Basic security considerations<\/h2>\n<p>It is advised, though not strictly required, to hide the Apache and operating system versions in error pages (as seen in Fig. 6). To do that, make sure the following directives have the indicated values in the configuration file. This will prevent (or at least, make it more difficult for) potential attackers from targeting known vulnerabilities either the web service or your server as a whole.<\/p>\n<p>Add these lines at the end of the main configuration file:<\/p>\n<pre class=\"brush:bash\">ServerSignature Off\r\nServerTokens Prod<\/pre>\n<p>and you&#8217;re good to go.<\/p>\n<h2>6. Conclusion<\/h2>\n<p>In this guide we have explained how to set up Apache using directives in its configuration file. Don&#8217;t forget to check the official documentation for more details and options.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this post, we feature a comprehensive Apache Configuration Tutorial. This article is part of our Academy Course titled Apache HTTP Server Tutorial. In this\u00a0Apache Configuration Tutorial course, we provide a compilation of Apache HTTP Server tutorials that will help you get started with this web server. We cover a wide range of topics, from &hellip;<\/p>\n","protected":false},"author":15,"featured_media":184,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[24],"tags":[],"class_list":["post-684","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-apache"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Apache Configuration Tutorial (CentOS \/ Ubuntu Linux) - System Code Geeks - 2026<\/title>\n<meta name=\"description\" content=\"Interested to learn more about Apache Configuration?Then check out our detailed Apache Configuration Tutorial where we are focusing on its easiness of configuration and seamless integration with server-side scripting languages such as PHP in the context of a standalone web server.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.systemcodegeeks.com\/web-servers\/apache\/apache-configuration-tutorial\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Apache Configuration Tutorial (CentOS \/ Ubuntu Linux) - System Code Geeks - 2026\" \/>\n<meta property=\"og:description\" content=\"Interested to learn more about Apache Configuration?Then check out our detailed Apache Configuration Tutorial where we are focusing on its easiness of configuration and seamless integration with server-side scripting languages such as PHP in the context of a standalone web server.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.systemcodegeeks.com\/web-servers\/apache\/apache-configuration-tutorial\/\" \/>\n<meta property=\"og:site_name\" content=\"System Code Geeks\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/systemcodegeeks\" \/>\n<meta property=\"article:author\" content=\"https:\/\/www.facebook.com\/gacanepa\" \/>\n<meta property=\"article:published_time\" content=\"2016-02-08T15:11:36+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2018-08-29T08:59:21+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/01\/apache-logo.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"150\" \/>\n\t<meta property=\"og:image:height\" content=\"150\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Gabriel Canepa\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@gacanepa\" \/>\n<meta name=\"twitter:site\" content=\"@systemcodegeeks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Gabriel Canepa\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"11 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.systemcodegeeks.com\/web-servers\/apache\/apache-configuration-tutorial\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.systemcodegeeks.com\/web-servers\/apache\/apache-configuration-tutorial\/\"},\"author\":{\"name\":\"Gabriel Canepa\",\"@id\":\"https:\/\/www.systemcodegeeks.com\/#\/schema\/person\/967da353d0f1a1de21c9504942625a5f\"},\"headline\":\"Apache Configuration Tutorial (CentOS \/ Ubuntu Linux)\",\"datePublished\":\"2016-02-08T15:11:36+00:00\",\"dateModified\":\"2018-08-29T08:59:21+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.systemcodegeeks.com\/web-servers\/apache\/apache-configuration-tutorial\/\"},\"wordCount\":1996,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/www.systemcodegeeks.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/www.systemcodegeeks.com\/web-servers\/apache\/apache-configuration-tutorial\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/01\/apache-logo.jpg\",\"articleSection\":[\"Apache\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.systemcodegeeks.com\/web-servers\/apache\/apache-configuration-tutorial\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.systemcodegeeks.com\/web-servers\/apache\/apache-configuration-tutorial\/\",\"url\":\"https:\/\/www.systemcodegeeks.com\/web-servers\/apache\/apache-configuration-tutorial\/\",\"name\":\"Apache Configuration Tutorial (CentOS \/ Ubuntu Linux) - System Code Geeks - 2026\",\"isPartOf\":{\"@id\":\"https:\/\/www.systemcodegeeks.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.systemcodegeeks.com\/web-servers\/apache\/apache-configuration-tutorial\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.systemcodegeeks.com\/web-servers\/apache\/apache-configuration-tutorial\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/01\/apache-logo.jpg\",\"datePublished\":\"2016-02-08T15:11:36+00:00\",\"dateModified\":\"2018-08-29T08:59:21+00:00\",\"description\":\"Interested to learn more about Apache Configuration?Then check out our detailed Apache Configuration Tutorial where we are focusing on its easiness of configuration and seamless integration with server-side scripting languages such as PHP in the context of a standalone web server.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.systemcodegeeks.com\/web-servers\/apache\/apache-configuration-tutorial\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.systemcodegeeks.com\/web-servers\/apache\/apache-configuration-tutorial\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.systemcodegeeks.com\/web-servers\/apache\/apache-configuration-tutorial\/#primaryimage\",\"url\":\"https:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/01\/apache-logo.jpg\",\"contentUrl\":\"https:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/01\/apache-logo.jpg\",\"width\":150,\"height\":150},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.systemcodegeeks.com\/web-servers\/apache\/apache-configuration-tutorial\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.systemcodegeeks.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Web Servers\",\"item\":\"https:\/\/www.systemcodegeeks.com\/category\/web-servers\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Apache\",\"item\":\"https:\/\/www.systemcodegeeks.com\/category\/web-servers\/apache\/\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"Apache Configuration Tutorial (CentOS \/ Ubuntu Linux)\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.systemcodegeeks.com\/#website\",\"url\":\"https:\/\/www.systemcodegeeks.com\/\",\"name\":\"System Code Geeks\",\"description\":\"Operating System Developers Resource Center\",\"publisher\":{\"@id\":\"https:\/\/www.systemcodegeeks.com\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.systemcodegeeks.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.systemcodegeeks.com\/#organization\",\"name\":\"Exelixis Media P.C.\",\"url\":\"https:\/\/www.systemcodegeeks.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.systemcodegeeks.com\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"contentUrl\":\"https:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"width\":864,\"height\":246,\"caption\":\"Exelixis Media P.C.\"},\"image\":{\"@id\":\"https:\/\/www.systemcodegeeks.com\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/systemcodegeeks\",\"https:\/\/x.com\/systemcodegeeks\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.systemcodegeeks.com\/#\/schema\/person\/967da353d0f1a1de21c9504942625a5f\",\"name\":\"Gabriel Canepa\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.systemcodegeeks.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/27b3ea2a3fb1de4ed1c8694a1465c099a86586d8b833a0d852a26d76d750df9f?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/27b3ea2a3fb1de4ed1c8694a1465c099a86586d8b833a0d852a26d76d750df9f?s=96&d=mm&r=g\",\"caption\":\"Gabriel Canepa\"},\"description\":\"Gabriel Canepa is a Linux Foundation Certified System Administrator (LFCS-1500-0576-0100) and web developer from Villa Mercedes, San Luis, Argentina. He works for a worldwide leading consumer product company and takes great pleasure in using FOSS tools to increase productivity in all areas of his daily work. When he's not typing commands or writing code or articles, he enjoys telling bedtime stories with his wife to his two little daughters and playing with them, the great pleasure of his life.\",\"sameAs\":[\"http:\/\/www.gabrielcanepa.com.ar\/\",\"https:\/\/www.facebook.com\/gacanepa\",\"https:\/\/ar.linkedin.com\/in\/gacanepa\",\"https:\/\/x.com\/gacanepa\"],\"url\":\"https:\/\/www.systemcodegeeks.com\/author\/gabriel-canepa\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Apache Configuration Tutorial (CentOS \/ Ubuntu Linux) - System Code Geeks - 2026","description":"Interested to learn more about Apache Configuration?Then check out our detailed Apache Configuration Tutorial where we are focusing on its easiness of configuration and seamless integration with server-side scripting languages such as PHP in the context of a standalone web server.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.systemcodegeeks.com\/web-servers\/apache\/apache-configuration-tutorial\/","og_locale":"en_US","og_type":"article","og_title":"Apache Configuration Tutorial (CentOS \/ Ubuntu Linux) - System Code Geeks - 2026","og_description":"Interested to learn more about Apache Configuration?Then check out our detailed Apache Configuration Tutorial where we are focusing on its easiness of configuration and seamless integration with server-side scripting languages such as PHP in the context of a standalone web server.","og_url":"https:\/\/www.systemcodegeeks.com\/web-servers\/apache\/apache-configuration-tutorial\/","og_site_name":"System Code Geeks","article_publisher":"https:\/\/www.facebook.com\/systemcodegeeks","article_author":"https:\/\/www.facebook.com\/gacanepa","article_published_time":"2016-02-08T15:11:36+00:00","article_modified_time":"2018-08-29T08:59:21+00:00","og_image":[{"width":150,"height":150,"url":"https:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/01\/apache-logo.jpg","type":"image\/jpeg"}],"author":"Gabriel Canepa","twitter_card":"summary_large_image","twitter_creator":"@gacanepa","twitter_site":"@systemcodegeeks","twitter_misc":{"Written by":"Gabriel Canepa","Est. reading time":"11 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.systemcodegeeks.com\/web-servers\/apache\/apache-configuration-tutorial\/#article","isPartOf":{"@id":"https:\/\/www.systemcodegeeks.com\/web-servers\/apache\/apache-configuration-tutorial\/"},"author":{"name":"Gabriel Canepa","@id":"https:\/\/www.systemcodegeeks.com\/#\/schema\/person\/967da353d0f1a1de21c9504942625a5f"},"headline":"Apache Configuration Tutorial (CentOS \/ Ubuntu Linux)","datePublished":"2016-02-08T15:11:36+00:00","dateModified":"2018-08-29T08:59:21+00:00","mainEntityOfPage":{"@id":"https:\/\/www.systemcodegeeks.com\/web-servers\/apache\/apache-configuration-tutorial\/"},"wordCount":1996,"commentCount":0,"publisher":{"@id":"https:\/\/www.systemcodegeeks.com\/#organization"},"image":{"@id":"https:\/\/www.systemcodegeeks.com\/web-servers\/apache\/apache-configuration-tutorial\/#primaryimage"},"thumbnailUrl":"https:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/01\/apache-logo.jpg","articleSection":["Apache"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.systemcodegeeks.com\/web-servers\/apache\/apache-configuration-tutorial\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.systemcodegeeks.com\/web-servers\/apache\/apache-configuration-tutorial\/","url":"https:\/\/www.systemcodegeeks.com\/web-servers\/apache\/apache-configuration-tutorial\/","name":"Apache Configuration Tutorial (CentOS \/ Ubuntu Linux) - System Code Geeks - 2026","isPartOf":{"@id":"https:\/\/www.systemcodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.systemcodegeeks.com\/web-servers\/apache\/apache-configuration-tutorial\/#primaryimage"},"image":{"@id":"https:\/\/www.systemcodegeeks.com\/web-servers\/apache\/apache-configuration-tutorial\/#primaryimage"},"thumbnailUrl":"https:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/01\/apache-logo.jpg","datePublished":"2016-02-08T15:11:36+00:00","dateModified":"2018-08-29T08:59:21+00:00","description":"Interested to learn more about Apache Configuration?Then check out our detailed Apache Configuration Tutorial where we are focusing on its easiness of configuration and seamless integration with server-side scripting languages such as PHP in the context of a standalone web server.","breadcrumb":{"@id":"https:\/\/www.systemcodegeeks.com\/web-servers\/apache\/apache-configuration-tutorial\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.systemcodegeeks.com\/web-servers\/apache\/apache-configuration-tutorial\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.systemcodegeeks.com\/web-servers\/apache\/apache-configuration-tutorial\/#primaryimage","url":"https:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/01\/apache-logo.jpg","contentUrl":"https:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/01\/apache-logo.jpg","width":150,"height":150},{"@type":"BreadcrumbList","@id":"https:\/\/www.systemcodegeeks.com\/web-servers\/apache\/apache-configuration-tutorial\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.systemcodegeeks.com\/"},{"@type":"ListItem","position":2,"name":"Web Servers","item":"https:\/\/www.systemcodegeeks.com\/category\/web-servers\/"},{"@type":"ListItem","position":3,"name":"Apache","item":"https:\/\/www.systemcodegeeks.com\/category\/web-servers\/apache\/"},{"@type":"ListItem","position":4,"name":"Apache Configuration Tutorial (CentOS \/ Ubuntu Linux)"}]},{"@type":"WebSite","@id":"https:\/\/www.systemcodegeeks.com\/#website","url":"https:\/\/www.systemcodegeeks.com\/","name":"System Code Geeks","description":"Operating System Developers Resource Center","publisher":{"@id":"https:\/\/www.systemcodegeeks.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.systemcodegeeks.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.systemcodegeeks.com\/#organization","name":"Exelixis Media P.C.","url":"https:\/\/www.systemcodegeeks.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.systemcodegeeks.com\/#\/schema\/logo\/image\/","url":"https:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","contentUrl":"https:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","width":864,"height":246,"caption":"Exelixis Media P.C."},"image":{"@id":"https:\/\/www.systemcodegeeks.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/systemcodegeeks","https:\/\/x.com\/systemcodegeeks"]},{"@type":"Person","@id":"https:\/\/www.systemcodegeeks.com\/#\/schema\/person\/967da353d0f1a1de21c9504942625a5f","name":"Gabriel Canepa","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.systemcodegeeks.com\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/27b3ea2a3fb1de4ed1c8694a1465c099a86586d8b833a0d852a26d76d750df9f?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/27b3ea2a3fb1de4ed1c8694a1465c099a86586d8b833a0d852a26d76d750df9f?s=96&d=mm&r=g","caption":"Gabriel Canepa"},"description":"Gabriel Canepa is a Linux Foundation Certified System Administrator (LFCS-1500-0576-0100) and web developer from Villa Mercedes, San Luis, Argentina. He works for a worldwide leading consumer product company and takes great pleasure in using FOSS tools to increase productivity in all areas of his daily work. When he's not typing commands or writing code or articles, he enjoys telling bedtime stories with his wife to his two little daughters and playing with them, the great pleasure of his life.","sameAs":["http:\/\/www.gabrielcanepa.com.ar\/","https:\/\/www.facebook.com\/gacanepa","https:\/\/ar.linkedin.com\/in\/gacanepa","https:\/\/x.com\/gacanepa"],"url":"https:\/\/www.systemcodegeeks.com\/author\/gabriel-canepa\/"}]}},"_links":{"self":[{"href":"https:\/\/www.systemcodegeeks.com\/wp-json\/wp\/v2\/posts\/684","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.systemcodegeeks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.systemcodegeeks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.systemcodegeeks.com\/wp-json\/wp\/v2\/users\/15"}],"replies":[{"embeddable":true,"href":"https:\/\/www.systemcodegeeks.com\/wp-json\/wp\/v2\/comments?post=684"}],"version-history":[{"count":0,"href":"https:\/\/www.systemcodegeeks.com\/wp-json\/wp\/v2\/posts\/684\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.systemcodegeeks.com\/wp-json\/wp\/v2\/media\/184"}],"wp:attachment":[{"href":"https:\/\/www.systemcodegeeks.com\/wp-json\/wp\/v2\/media?parent=684"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.systemcodegeeks.com\/wp-json\/wp\/v2\/categories?post=684"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.systemcodegeeks.com\/wp-json\/wp\/v2\/tags?post=684"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}