---
slug: fifth-blog-post
title: Fifth Blog Post
authors: [slorber, yangshun]
tags: [hola, docusaurus]
---

<!-- truncate -->

import CodeBlock from '@site/src/components/CodeBloack';

<br/>
<span className="main-head">Getting Your Website Online: Apache Setup for Ubuntu or Debian</span>

<div className="head">Introduction:</div>

<div className="text">Apache is like the engine that runs many websites you visit every day. It's super popular and used by over half of all websites online! While there are other web servers out there, Apache is a great one to learn about because it's everywhere.</div><br/>

<div className="text">In this article, we'll talk about some basic settings in Apache that you can tweak to customize how your website works. We'll focus on how things are set up in Ubuntu and Debian, which are types of operating systems. They have a particular way of organizing Apache's settings that might be a bit different from other systems, but don't worry, we'll guide you through it step by step!</div><br/>

<div className="text" style={{ fontSize:'28px' }}>Getting started:</div>
<div className="text">Before we get started, it's important to make sure your Ubuntu system is up to date. If you're using an older version like 16.04 or below, it's a good idea to upgrade to a newer version. This is because older versions may not receive security updates anymore, which could make your system vulnerable.</div>

<div className="text">Don't worry though! We've got guides to help you through the upgrade process. Just follow along, and we'll make sure your system is ready to go!</div>

<div className="text">Before we begin, make sure you have the following:</div>
<div className="text"><ul><li>A server running Ubuntu (an operating system).</li><li>A regular user account with special permissions (called sudo privileges).</li><li>A firewall set up to protect your server.</li></ul></div> 

<div className="text">If you're not sure how to set these up, don't worry! We have guides to help you. Just choose your operating system (Ubuntu or Debian) from the list and follow our Initial Server Setup Guide.</div>

<div className="text">Now, before we start, you need to have Apache installed on your server. We've got tutorials to help you with that too! Depending on your Ubuntu version, follow either the "How to Install the Apache Web Server on Ubuntu" or "How to Install the Apache Web Server on Debian 10" tutorial. They'll walk you through the installation process step by step.</div>

<div className="head">Getting Started with Apache on Ubuntu: 5 Easy Steps</div>
<div className="text"><ol><li>Understanding Apache's Folders: Learn where Apache keeps its important files.</li><li>Getting to Know the Apache2.conf File: Explore the main configuration file for Apache.</li><li>Adjusting Apache's Settings: Make changes to how Apache behaves across your entire server.</li><li>Creating Virtual Hosts: Set up separate configurations for different websites on your server.</li><li>Activating Websites and Features: Enable your websites and additional functionalities in Apache.</li></ol></div> <br/>

<div className="head">Understanding Apache's Folders:</div>
<div className="text">Apache stores its important files in a special folder called /etc/apache2. This folder is where you can find all the settings and configurations for your Apache web server. To see what's inside this folder, you can use a command that lists all the files.</div>

<CodeBlock code={`ls -f /etc/apache2`} /><br/>

<CodeBlock code={`Output

envars sites-available . apache2.conf .. sites-enabled mods-available ports.conf magic mods-enabled conf-enabled conf-available
`} /><br/>

<div className="text">Inside this folder, you'll see a bunch of simple text files and a few folders. Here are some key places you should know about:</div>

<div className="text"><ol><li>apache2.conf: This is the main settings file for the server. Most settings are managed here, but it's recommended to use separate files for easier organization. This file sets up defaults and is where the server looks for configuration details.</li><br/><li>ports.conf: This file sets the ports that virtual hosts should use. It's important to check this file if you're setting up SSL (secure connections).</li><br/><li>sites-available/ and sites-enabled/: In the sites-available folder, you'll find configurations for virtual hosts (websites). These configurations determine which content gets served for different requests. The sites-enabled folder contains active virtual host configurations. Apache reads these files when it starts up or reloads to compile the full configuration.</li><br/><li>conf-available/ and conf-enabled/: These folders hold extra configuration pieces that aren't specific to virtual hosts.</li><br/><li>mods-available/ and mods-enabled/: Here, you'll find optional modules that Apache can load. Files ending in .load load the modules, while those ending in .conf store module configurations.</li></ol></div>

<div className="text">In Apache, configuration isn't done in just one big file. Instead, it's set up in a modular way. This means you can add and change settings by working with different files, making it easier to manage your server.</div> <br/>


<div className="head">Getting to Know the Apache2.conf File:</div>
<div className="text">The main settings for your Apache server are stored in a file called apache2.conf, located in the /etc/apache2/ folder. This file is divided into three main parts:</div>

<div className="text"><ol><li>Settings for the overall Apache server process.</li><li>Settings for the default server.</li><li>Settings for virtual hosts.</li></ol></div>

<div className="text">You can open this file using any text editor you like. For example, you can use a simple one called nano.</div>

<CodeBlock code={`sudo nano /etc/apache2/apache2.conf`} /><br/>

<div className="text">In Ubuntu and Debian, the apache2.conf file is where you set up global settings for your server. Instead of cramming all settings into one file, you use the Include directive to bring in other configuration files. This helps keep things organized.</div><br/>

<div className="text">Inside apache2.conf, you'll see statements like Include and IncludeOptional. These tell Apache to read additional files, such as module definitions, ports.conf, configurations from the conf-enabled/ folder, and virtual host settings from the sites-enabled/ folder. This way, Apache puts together all the settings it needs when it starts up.</div>

<CodeBlock code={`…
IncludeOptional mods-enabled/*.load
IncludeOptional mods-enabled/*.conf
…
Include ports.conf
…
IncludeOptional conf-enabled/*.conf
…
IncludeOptional sites-enabled/*.conf
`} /><br/>


<div className="head">Adjusting Apache's Settings:</div>

<div className="text">Now, let's make some changes to how Apache works on your server. We'll adjust settings that affect the entire server, so it's important to get these settings right.</div><br/>

<div className="text">When setting up your Apache server, it's essential to understand and adjust some key parameters to optimize its performance. Here's a breakdown of important settings:</div>

<div className="text"><ol><li>Timeout: By default, Apache gives itself 300 seconds to complete each request. You can safely lower this to between 30 and 60 seconds for faster responses.</li><br/><li>KeepAlive: When KeepAlive is turned on, it lets one connection handle multiple requests from the same client. If it's turned off, each request requires a new connection, which can increase overhead. Keeping KeepAlive on can save time, especially if you have a lot of traffic.</li><br/><li>MaxKeepAliveRequests: This setting determines how many requests each connection can handle before it's closed. A higher value allows Apache to serve content more efficiently. The default setting is 100, but you can set it to 0 for an unlimited number of requests per connection.</li><br/><li>KeepAliveTimeout: This specifies how long Apache should wait for the next request after completing the last one. If the timeout is reached, the connection is closed. The default is 5 seconds.</li></ol></div><br/>

<div className="text">After making changes, you can close the configuration file by pressing CTRL+X.</div>
<div className="text">Multi-Processing Modules (MPMs):</div>
<div className="text">These extend Apache's capabilities to listen for, direct, and handle various network requests. You can find out which MPM your Apache uses by running a specific command.</div>

<CodeBlock code={`apache2 -L`} /><br/>

<CodeBlock code={`Output

Compiled in modules:
  core.c
  mod_so.c
  mod_watchdog.c
  http_core.c
  mod_log_config.c
  mod_logio.c
  mod_version.c
  mod_unixd.c
`} /><br/>

<div className="text">To find out the type of Multi-Processing Module (MPM) your server is using, you can use the command: a2query -M.</div>

<CodeBlock code={`a2query -M`} /><br/>

<CodeBlock code={`Output

event`} /><br/>



<div className="text">The result shows that the event MPM is being used on this server. Your setup might offer different options, but you can only choose one at a time.</div>

<div className="head">Creating Virtual Hosts:</div>
<div className="text">Now, let's set up individual configurations for different websites on your server. This helps Apache know which content to serve for each website you host.</div>

<div className="text">You'll find a default virtual host declaration in a file called 000-default.conf within the sites-available/ directory. You can take a look at this file to understand the basic format of a virtual host configuration.</div>

<div className="text">To open the file, use the following command:</div>

<CodeBlock code={`sudo nano /etc/apache2/sites-available/000-default.conf

<VirtualHost *:80>
…
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html
…
ErrorLog $ {APACHE LOG DIR}/error.log
CustomLog $ {APACHE LOG DIR}/access.log combined
…
`} /><br/>

<div className="text">The default virtual host is set up to deal with any requests on port 80, which is the standard for HTTP. You'll see this in the declaration header, where it says *:80, meaning it's listening on port 80 on any interface.</div><br/>

<div className="text">But just because it's set up this way doesn't mean it will handle every request to the server on this port. Apache looks for the most specific virtual host definition that matches the request. If it finds one that's more specific, it'll use that instead.</div><br/>

<div className="text">After you're done checking out the file, you can close it by pressing CTRL+X.</div><br/>
<div className="text">Exploring Apache Virtual Host Settings:</div> <br/>

<div className="text">In the virtual host configuration, you'll find various options that apply to the entire virtual host. These settings are separate from any other specific configurations.</div><br/>

<div className="text">To begin, let's take a look at the security.conf file located in the conf-available/ directory.</div>

<CodeBlock code={`sudo nano /etc/apache2/conf-available/security.conf`} /><br/>

<div className="text">In this file, there's a setting called "Server Signature" which allows you to specify an email address for server-related issues. By default, it's set to "On," but switching it to "EMail" will display the server admin's email address.</div><br/>

<div className="text">Remember, if you make this change, be prepared to receive emails regarding server problems.</div>

<CodeBlock code={`…
ServerSignature EMail
…
`} /><br/>

<div className="text">To exit the file, press CTRL+X. After you've made changes, a prompt will ask if you want to save them. Press Y to save or N to discard.</div><br/>

<div className="text">In your virtual host file, you can include a directive called ServerName. This specifies the domain name or IP address that this request should handle. If it matches the ServerName value, it'll override the default definition.</div><br/>

<div className="text">To open your virtual host file, use the following command, replacing "your_domain" with your actual domain name:</div>

<CodeBlock code={`sudo nano /etc/apache2/sites-available/your_domain.conf`} /><br/>

<div className="text">Add your domain name to the ServerName directive.Just include your actual domain name after the ServerName directive in the virtual host file.</div>

<CodeBlock code={`…
ServerName your_domain
…
`} /><br/>

<div className="text">You can make the virtual host apply to multiple names using the ServerAlias directive. This allows you to specify alternate paths to access the same content. For example, a common use case is adding "www" before your domain name.</div>

<CodeBlock code={`…
ServerAlias www.your_domain.com
…
`} /><br/>

<div className="text">The DocumentRoot directive tells Apache where to look for the content for this virtual host. On Ubuntu, the default setup serves content from the /var/www/ directory.</div><br/>

<CodeBlock code={`…
DocumentRoot /var/www/your_domain/public_html
…
`} /><br/>

<div className="head">Managing Directory Settings:</div>
<div className="text">Within the virtual host configuration, there are rules for how the server handles different directories on the file system. Apache applies these rules in a specific order, from shortest to longest directory paths. This allows later rules to potentially override earlier ones. <br/><br/> To open the apache2.conf file, use this command:</div>


<CodeBlock code={`sudo nano /etc/apache2/apache2.conf
…
<Directory />
        Options FollowSymLinks
        AllowOverride None
        Require all denied
</Directory>
<Directory /usr/share>
        AllowOverride None
        Require all granted
</Directory>
<Directory /var/www/>
        Options Indexes FollowSymLinks
        AllowOverride None
        Require all granted
</Directory>
…
`} /><br/>

<div className="text">The first directory definition sets rules for the root directory (/), which is the starting point for all files on the server. This configuration serves as the foundation for your virtual host, applying to all files on the file system.Take note of the directory settings and helpful comments in this file. By default, access to all content is denied unless specified otherwise in later directory definitions</div><br/>

<div className="text">The Require directive decides who can access different parts of your server. Meanwhile, the AllowOverride directive determines if an .htaccess file can change settings in the content directory. By default, this is not allowed, but it can be handy to enable in certain situations. After you're done looking at this file, you can close it by pressing CTRL+X.</div><br/>

<div className="text" style={{ fontSize:'28px' }}>Handling Aliases and Scripts:</div>

<div className="text">Before defining directories, you might encounter Alias or ScriptAlias directives. These instructions help Apache manage specific paths on your server.To open your virtual host configuration file, use this command, and remember to replace "your_domain" with your actual domain name:</div>


<CodeBlock code={`sudo nano /etc/apache2/sites-available/your_domain.conf`} /><br/>

<div className="text">The Alias directive helps Apache connect a URL path to a directory path. For example, in a virtual host for your_domain, using this directive lets you access content stored in /usr/local/apache/content/ when you visit your_domain.com/content/.</div><br/>

<CodeBlock code={`Alias “/content/” “/usr/local/apache/content/”`} /><br/>


<div className="text">Just like the Alias directive, the ScriptAlias directive connects a URL path to a directory path. However, it's specifically used for directories that contain executable components.</div>

<CodeBlock code={`ScriptAlias "/cgi-bin/" "/usr/local/apache2/cgi-bin/"`} /><br/>

<div className="text">After you finish making changes to the file, remember to save your edits by pressing CTRL+X. If you've made changes, you'll be asked if you want to save them. Press Y for yes, or N for no to discard them.And don't forget to define the directory with the appropriate access privileges as explained earlier!</div><br/>


<div className="head">Activating Websites and Features:</div>

<div className="text">Once you've set up your virtual host file just the way you want it, you can use Apache's tools to turn it into a live website. To do this, you'll create a symbolic link in the sites-enabled directory that points to your virtual host file in the sites-available directory. Here's the command to do that. Just make sure to replace "your_domain" with the name of your own virtual host site configuration file:</div>

<CodeBlock code={`sudo a2ensite your_domain`} /><br/>

<div className="text">After you've activated a site, use this command to let Apache know to update its settings, making sure the changes you made take effect:</div>

<CodeBlock code={`sudo systemctl restart apache2`} /><br/>

<div className="text">There's a way to turn off a virtual host too. You do this by deleting the symbolic link from the sites-enabled directory. For instance, if you have the default 000-default site enabled, you can disable it like this:</div>

<CodeBlock code={`sudo a2dissite 000-default`} /><br/>

<div className="text">You can turn modules on or off using the a2enmod and a2dismod commands. They're similar to the a2ensite and a2dissite commands.For instance, if you want to activate the info module, you can use this command:</div>

<CodeBlock code={`sudo a2enmod info`} /><br/>

<div className="text">Similarly, if you want to turn off a module, you can use the a2dismod command:</div>

<CodeBlock code={`sudo a2dismod info`} /><br/>

<div className="text">Don't forget to restart Apache after you've made changes to configuration files or after enabling or disabling modules.</div><br/>

<div className="con">Conclusion</div><br/>

<div className="text">Apache is flexible and made up of many parts, so the settings you need might vary based on your setup. After looking at some common scenarios, you should have a good grasp of what the main configuration files do and how they work together.</div><br/>

<div className="text">If you want to learn about specific settings, the files we've talked about have helpful comments, and Apache offers great documentation. Hopefully, you're feeling less overwhelmed by the configuration files now, and you're ready to try making changes to fit your needs</div> <br/>

<div className="text">Remember, if you have any questions or need further assistance, feel free to ask!</div>













