Apache HTTP Server Overview and Configuration
Apache HTTP Server (httpd) is the world's most widely used open-source web server software. On Debian/Ubuntu-based systems it is installed as the apache2 package; on RHEL/AlmaLinux-based systems it is installed as httpd. Configuration files can be split and managed per module and per virtual host. On Ubuntu-based systems, a2ensite / a2dissite enable and disable per-site configuration, while on RHEL-based systems the Include directive is used.
Syntax
Global settings (applied to the entire server). www-data is common on Ubuntu-based systems; apache is common on RHEL-based systems.
User www-data Group www-data ServerAdmin admin@example.jp ServerName www.example.jp # Prod (product name only) is recommended for security. ServerTokens Prod ServerSignature Off
Document root and access control. AllowOverride All permits configuration overrides via .htaccess.
DocumentRoot /var/www/html
<Directory /var/www/html>
# None: fully disabled / FileInfo: MIME types etc. / All: everything allowed
AllowOverride All
Require all granted
</Directory>
Configuration file structure on Ubuntu-based systems (/etc/apache2/).
# /etc/apache2/ # ├── apache2.conf ← main configuration file # ├── ports.conf ← ports to listen on # ├── mods-available/ ← available modules (.load / .conf) # ├── mods-enabled/ ← symbolic links to enabled modules # ├── sites-available/ ← available virtual host configuration files # │ ├── 000-default.conf ← default site configuration # │ └── app1.conf ← additional site configuration (example) # ├── sites-enabled/ ← symbolic links to enabled sites # │ └── app1.conf -> ../sites-available/app1.conf # └── conf-available/ ← other configuration fragments
Basic structure of a VirtualHost directive. <VirtualHost *:80> defines a virtual host on port 80 (* means all IP addresses).
<VirtualHost *:80>
ServerName example.jp
ServerAlias www.example.jp
DocumentRoot /var/www/example
ErrorLog ${APACHE_LOG_DIR}/example-error.log
# combined: IP address, date/time, request, status, bytes, referrer, user agent
CustomLog ${APACHE_LOG_DIR}/example-access.log combined
</VirtualHost>
Directive / Command Reference
| Directive / Command | Description |
|---|---|
ServerName {domain} | Specifies the hostname of the server or virtual host. Used for request routing. |
ServerAlias {domain} ... | Sets additional domain names (aliases) for a virtual host. Useful for handling both www and non-www variants. |
ServerAdmin {email} | Sets the server administrator's email address. Displayed on error pages. |
DocumentRoot {path} | Specifies the root directory where the website's files are stored. |
<Directory {path}> ... </Directory> | Sets access control and options for a specific directory in block form. |
AllowOverride {value} | Specifies the scope of configuration overrides allowed by .htaccess files. Accepts None (disabled), All (everything allowed), FileInfo, and others. |
Require all granted | Allows access from all clients. Use Require all denied to deny all access instead. |
ErrorLog {path} | Specifies the output file for error logs. ${APACHE_LOG_DIR} is an environment variable that typically resolves to /var/log/apache2. |
CustomLog {path} {format} | Specifies the output file and format for access logs. combined is the most commonly used format. |
<VirtualHost *:80> | Defines a virtual host block for port 80. Use *:443 for HTTPS. |
a2ensite {config-file} | On Ubuntu-based systems, creates a symbolic link from sites-available/ to sites-enabled/ to activate a configuration file. |
a2dissite {config-file} | On Ubuntu-based systems, disables a virtual host configuration by removing its symbolic link. |
a2enmod {module} | On Ubuntu-based systems, enables an Apache module such as mod_rewrite or mod_ssl. |
a2dismod {module} | On Ubuntu-based systems, disables an Apache module. |
apachectl configtest | Checks the configuration file syntax. If the output shows Syntax OK, the configuration is valid. |
Examples
/etc/apache2/sites-available/app1.conf
<VirtualHost *:80>
ServerName app1.example.jp
# Handles both www and non-www variants.
ServerAlias www.app1.example.jp
ServerAdmin admin1@example.jp
DocumentRoot /var/www/app1/public
<Directory /var/www/app1/public>
# Set to All when using .htaccess for URL rewriting (e.g., WordPress or Laravel).
AllowOverride All
Require all granted
# Looks for index files in order: index.php → index.html
DirectoryIndex index.php index.html
</Directory>
# PHP-FPM integration (requires mod_proxy_fcgi).
# <FilesMatch "\.php$">
# SetHandler "proxy:unix:/run/php/php8.2-fpm.sock|fcgi://localhost/"
# </FilesMatch>
ErrorLog ${APACHE_LOG_DIR}/app1-error.log
CustomLog ${APACHE_LOG_DIR}/app1-access.log combined
</VirtualHost>
# HTTP → HTTPS redirect (see ssl_overview for SSL configuration)
# <VirtualHost *:80>
# ServerName app1.example.jp
# Redirect permanent / https://app1.example.jp/
# </VirtualHost>
Run the following command:
$ sudo apachectl configtest
Syntax OK
$ sudo a2ensite app1.conf
Enabling site app1.
To activate the new configuration, you need to run:
systemctl reload apache2
$ sudo systemctl reload apache2
$ sudo systemctl status apache2
● apache2.service - The Apache HTTP Server
Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled)
Active: active (running) since Wed 2026-03-25 10:00:00 UTC; 3s ago
$ curl -I http://app1.example.jp/
HTTP/1.1 200 OK
Server: Apache
Content-Type: text/html; charset=UTF-8
Enabling mod_rewrite and setting rewrite rules in .htaccess
Enable the mod_rewrite module required for URL rewriting (e.g., /user/user1 → index.php?id=user1) on Ubuntu-based systems.
$ sudo a2enmod rewrite Enabling module rewrite. To activate the new configuration, you need to run: systemctl restart apache2 $ sudo systemctl restart apache2
Write the rewrite rules in /var/www/app1/public/.htaccess. This only rewrites when the requested file or directory does not exist, forwarding all requests to index.php (front controller pattern).
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.php [QSA,L]
Configuration on RHEL/AlmaLinux-based systems (place files in /etc/httpd/conf.d/)
On RHEL/AlmaLinux-based systems, files placed in /etc/httpd/conf.d/ are loaded automatically. The a2ensite command is not needed.
<VirtualHost *:80>
ServerName app2.example.jp
ServerAdmin admin2@example.jp
DocumentRoot /var/www/app2/public
<Directory /var/www/app2/public>
AllowOverride All
Require all granted
</Directory>
ErrorLog /var/log/httpd/app2-error.log
CustomLog /var/log/httpd/app2-access.log combined
</VirtualHost>
Check the syntax and then restart httpd.
$ sudo apachectl configtest
Syntax OK
$ sudo systemctl restart httpd
$ sudo systemctl status httpd
● httpd.service - The Apache HTTP Server
Loaded: loaded (/lib/systemd/system/httpd.service; enabled; vendor preset: disabled)
Active: active (running) since Wed 2026-03-25 10:05:00 UTC; 2s ago
Overview
Apache HTTP Server has been in active development since 1995. It is known for its flexible per-directory configuration via .htaccess and its rich module ecosystem (mod_rewrite, mod_ssl, mod_proxy, and more). On Ubuntu-based systems, the standard workflow is to create a configuration file in sites-available/ and enable it with a2ensite, making it easy to manage multiple sites on a single server. On RHEL/AlmaLinux-based systems, placing a file in /etc/httpd/conf.d/ is all that is needed for it to be loaded automatically. After making configuration changes, always run apachectl configtest to check the syntax, then apply the changes with systemctl reload apache2 (or httpd). Enabling HTTPS requires configuring mod_ssl and a certificate (see SSL / TLS configuration). Nginx, known for its lightweight design and high concurrency, is also widely used as an alternative to Apache. Use systemctl to manage service start, stop, and autostart.
If you find any errors or copyright issues, please contact us.