Apache2 Web Server Configuration

Posted on  by admin
  1. Configure Apache Web Server Ubuntu
  2. Apache2 Web Server Configuration Ubuntu
  3. Apache2 Configuration File
  4. What Is 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.

Table of Contents

Configuring a Web Server¶ The preferred way to develop your Symfony application is to use Symfony Local Web Server. However, when running the application in the production environment, you’ll need to use a fully-featured web server. This article describes several ways to use Symfony with Apache. Apache2.conf: This is the main configuration file for the server. Almost all configuration can be done from within this file, although it is recommended to use separate, designated files for simplicity. This file will configure defaults and be the central point of access for the server to read configuration details.

Apache Configuration

Valid for versions 82 through the latest version

Server

Last modified: September 29, 2020

This collection of features allows you to configure Apache. Apache functions as your web server software and handles HTTP requests.

  • Global Configuration — This interface allows you to adjust several advanced features of the Apache web server.

  • DirectoryIndex Priority — This interface allows you to specify filenames that Apache will recognize and display as index pages.

  • Include Editor — This interface allows you to add other configuration files to your Apache configuration file (httpd.conf).

  • Reserved IP Address Editor — This interface allows you to configure Apache to ignore HTTP requests on specific IP addresses. Use this feature if you wish to prevent the assignment of specific IP addresses to new accounts.

  • Memory Usage Restrictions — This interface allows you to calculate and set a new Apache memory limit. Setting a process memory limit increases the stability of your server, but may reduce performance slightly. This limit applies to each Apache process, not to all Apache processes combined.

  • Log Rotation — This interface allows you to specify which Apache log files cPanel’s cpanellogd daemon should manipulate.

  • Piped Log Configuration — This interface configures Apache to use a single target for all virtual host access and bandwidth logs.

Additional Documentation

Learn how to set up custom error pages in Apache. The Apache web server provides a default set of generic error pages for 404, 500, and other common Apache errors.

However, creating custom error pages allows you to:

  • Continue your branding on these pages
  • Integrate their design into the look and feel of your website
  • Direct lost visitors to their intended destinations
  • Provide error pages in languages other than English

Requirements

  • Cloud Server running Linux (CentOS 7 or Ubuntu 14.04)
  • Apache installed and running

vServer (VPS) from IONOS

Low-cost, powerful VPS hosting for running your custom applications, with a personal assistant and 24/7 support.

Ready in 55 sec.
Apache web server software

Create the Custom Error Page

First, you will need to create the custom error page. For testing purposes, we will create an example error page to handle 404 errors.

Use SSH to connect to your server and go to your website's document root. Create a new page named my-404.html with the command:

Save and exit the file.

You can view the file by going to http://example.com/my-404.html to make sure it is displaying correctly.

Configure Apache to Use the Custom Error Page

Configure Apache Web Server Ubuntu

To tell Apache to use a custom error page, you will need to add an ErrorDocument directive. The syntax for this directive is:

For this example, since the my-404.html file is in the site's document root, we will be adding the directive:

This directive needs to go inside the VirtualHost command block in the site's main Apache configuration file.

By common convention, this Apache configuration file is usually:

  • CentOS 7/etc/httpd/conf.d/example.com.conf
  • Ubuntu 14.04/etc/apache2/sites-available/example.com.conf

The location and filename of a site's Apache configuration file can vary based on how you or your server administrator has set up hosting.

Edit this file with your editor of choice, for example with the command:

Apache2 Web Server Configuration Ubuntu

  • CentOS 7sudo nano /etc/httpd/conf.d/example.com.conf
  • Ubuntu 14.04sudo nano /etc/apache2/sites-available/example.com.conf

Scroll through the file until you find the VirtualHost command block, which will look like:

Apache2 Web Server Configuration

Apache2 Configuration File

Apache2 Web Server Configuration

Add the ErrorDocument to the VirtualHost command block, but be sure to put it outside any Directory command blocks. For example:

Save and exit the file, then restart Apache for the changes to take effect:

  • CentOS 7sudo systemctl restart httpd
  • Ubuntu 14.04sudo services apache2 restart

What Is Apache2

Finally, test your error document by going to an invalid URL for your website. You will be redirected to your new custom 404 page instead.

Other HTTP Error Codes

The most common custom error page is for a 404 error. However, you may want to create custom error pages for other Apache errors as well.

These pages can be configured for any 4xx or 5xx error code. A full list of these HTTP error codes can be found on Wikipedia.

Related articles