Web Servers (Apache, Nginx, Caddy)

Mastering Apache: An In-depth Guide to Key Features and Advanced Techniques

By the Domain India teamPublished 9 min read
Knowledge base article
Contents (11 sections)

Apache HTTP Server is one of the most widely used web servers, and it is the web server behind Domain India's shared hosting. This guide covers the parts that matter in practice: installing Apache on your own server, how its configuration is laid out, virtual hosts, HTTPS, PHP, performance, security and troubleshooting. The server commands apply to your own VPS or server; on shared hosting you control only .htaccess, as section 9 explains.

Key takeaways

On Ubuntu or Debian install apache2; on AlmaLinux or Rocky Linux install httpd. Put each site in its own virtual host, get free HTTPS with Certbot, and run PHP through PHP-FPM with the event MPM rather than mod_php. Turn on compression and caching headers, hide version details, and always run apachectl configtest before a reload. On shared hosting you can't change server settings, but .htaccess rules work.

1. What Apache does

A web server listens for browser requests on ports 80 (HTTP) and 443 (HTTPS), finds the right file or application, and sends back the response. Apache's strengths are its modules, which add features such as HTTPS, URL rewriting and reverse proxying, and .htaccess files, which let each site change some settings without access to the main configuration. That second feature is why shared hosting companies use it.

2. Install Apache on your server

Use your distribution's packages, which receive security updates with the rest of the system.

bash
# Ubuntu / Debian
sudo apt update
sudo apt install apache2
sudo systemctl enable --now apache2

# AlmaLinux / Rocky Linux
sudo dnf install httpd mod_ssl
sudo systemctl enable --now httpd

Open the firewall for web traffic (sudo ufw allow 'Apache Full' on Ubuntu, or sudo firewall-cmd --permanent --add-service={http,https} && sudo firewall-cmd --reload on AlmaLinux), then visit http://your-server-ip. The default test page confirms Apache is running.

3. How the configuration is laid out

The two families organise files differently:

ItemUbuntu / DebianAlmaLinux / Rocky Linux
Main config/etc/apache2/apache2.conf/etc/httpd/conf/httpd.conf
Site configssites-available/, enabled with a2ensiteconf.d/*.conf, loaded automatically
Modulesmods-available/, enabled with a2enmodconf.modules.d/*.conf
Logs/var/log/apache2//var/log/httpd/
Service nameapache2httpd

Three commands you will use constantly:

bash
sudo apachectl configtest      # check syntax before applying
sudo systemctl reload apache2  # apply changes without dropping connections (httpd on AlmaLinux)
sudo apachectl -M              # list loaded modules

4. Virtual hosts: one server, many sites

A virtual host maps a domain name to a folder and its own settings. This is the standard setup for a site on Ubuntu, saved as /etc/apache2/sites-available/example.com.conf:

apache
<VirtualHost *:80>
    ServerName example.com
    ServerAlias www.example.com
    DocumentRoot /var/www/example.com/public

    <Directory /var/www/example.com/public>
        Options -Indexes +FollowSymLinks
        AllowOverride All
        Require all granted
    </Directory>

    ErrorLog ${APACHE_LOG_DIR}/example.com-error.log
    CustomLog ${APACHE_LOG_DIR}/example.com-access.log combined
</VirtualHost>

Enable it with sudo a2ensite example.com.conf, test, and reload. On AlmaLinux, save the same block as /etc/httpd/conf.d/example.com.conf and use /var/log/httpd/ paths.

AllowOverride All lets .htaccess files in that folder work. If you don't need .htaccess, set it to None and put the rules in the virtual host instead; Apache is slightly faster when it doesn't look for those files on every request.

5. HTTPS with a free certificate

Let's Encrypt certificates are free and renew automatically through Certbot:

bash
sudo apt install certbot python3-certbot-apache      # Ubuntu / Debian
sudo certbot --apache -d example.com -d www.example.com

On AlmaLinux, Certbot comes from the EPEL repository (sudo dnf install epel-release, then sudo dnf install certbot python3-certbot-apache). Certbot creates the HTTPS virtual host, offers to redirect HTTP to HTTPS, and installs a renewal timer. Test renewal with sudo certbot renew --dry-run.

6. Running PHP the modern way

The old method loads PHP into Apache as mod_php, which forces the slow prefork MPM. The current recommendation is the event MPM with PHP-FPM, where PHP runs as a separate service:

bash
# Ubuntu / Debian: replace 8.3 with the PHP version your system installs
sudo apt install php-fpm
sudo a2dismod php8.3 mpm_prefork     # only if mod_php was installed
sudo a2enmod mpm_event proxy_fcgi setenvif
sudo a2enconf php8.3-fpm
sudo systemctl restart apache2

Check the version with php -v or ls /etc/php/.

On AlmaLinux, the php-fpm package ships an Apache config that works with the default event MPM; install it and enable the php-fpm service. With PHP-FPM, PHP settings go in php.ini, the FPM pool file or a .user.ini file, not in php_value lines in Apache config.

7. Performance

Compression. Enable mod_deflate (and mod_brotli where your distribution packages it) for text types:

apache
<IfModule mod_deflate.c>
    AddOutputFilterByType DEFLATE text/html text/css text/plain application/javascript application/json image/svg+xml
</IfModule>

Browser caching. Let browsers keep static files, with mod_expires:

apache
<IfModule mod_expires.c>
    ExpiresActive On
    ExpiresByType image/webp "access plus 1 month"
    ExpiresByType text/css "access plus 1 week"
    ExpiresByType application/javascript "access plus 1 week"
</IfModule>

Other quick wins:

  • HTTP/2. Enable mod_http2 and add Protocols h2 http/1.1 to your HTTPS virtual host. It needs the event MPM.
  • Worker limits. Size MaxRequestWorkers to your RAM: each busy worker plus its PHP-FPM process uses memory, and a server that starts swapping gets slower, not faster.
  • Caching the application. For WordPress, a page cache plugin such as WP Super Cache or W3 Total Cache saves more time than any Apache setting.

8. Security and troubleshooting

Hide version details and add common security headers (enable mod_headers first):

apache
ServerTokens Prod
ServerSignature Off
TraceEnable Off

Header always set X-Content-Type-Options "nosniff"
Header always set X-Frame-Options "SAMEORIGIN"
Header always set Referrer-Policy "strict-origin-when-cross-origin"
Header always set Strict-Transport-Security "max-age=31536000"

Add Strict-Transport-Security only once HTTPS works reliably on the site: browsers remember it for the whole max-age and will refuse plain HTTP. Also disable modules you don't use, keep Options -Indexes so folders aren't listed, and keep the server updated. A web application firewall such as ModSecurity with the OWASP Core Rule Set adds another layer.

When something breaks:

SymptomFirst thing to check
Apache won't start or reloadsudo apachectl configtest, then journalctl -u apache2 (or httpd)
500 Internal Server ErrorThe site's error log; usually a bad .htaccess line or a PHP fatal error
403 ForbiddenFile permissions, a Require rule, or a missing index file with -Indexes
503 or timeoutsPHP-FPM is down or out of workers; check its status and log
Wrong site appearsServerName and ServerAlias; list virtual hosts with apachectl -S

9. Running this on Domain India

On shared hosting (cPanel, DirectAdmin, Webuzo), Domain India runs Apache, and on cPanel an nginx proxy sits in front of it. You can't edit the server configuration, install modules or restart Apache, but .htaccess rules and mod_rewrite work on all three. Two rules to know:

  • PHP does not run as an Apache module, so a php_value or php_flag line in .htaccess causes a 500 error.
  • On DirectAdmin, .htaccess Options accepts only Indexes, IncludesNOEXEC, MultiViews, SymLinksIfOwnerMatch, FollowSymLinks and None.

See how to enable mod_rewrite, troubleshooting 500 errors and the .htaccess guide.

On a Domain India VPS, everything in sections 2-8 applies. The VPS is self-managed with full root access, so you install and look after Apache yourself. If you choose the free CyberPanel on your VPS, note that it uses OpenLiteSpeed rather than Apache.

10. Where Domain India fits

If you want Apache to just work, shared hosting gives you a tuned server where you only manage your site. If you want to configure Apache yourself, a VPS gives you full root access. Domain India list prices on 19 September 2026, excluding 18% GST, are on the cards below.

cPanel Starter
₹125/mo + GST
  • 25 GB NVMe SSD Storage
  • 50 GB Monthly Bandwidth
  • 1 Website
  • 10 Email Accounts
See plan details
VPS Starter
₹552.65/mo + GST
  • 1 vCPU
  • 2 GB DDR4 RAM
  • 64 GB NVMe SSD Storage
  • 2 TB Monthly Bandwidth
See plan details

Frequently asked questions

What is the difference between apache2 and httpd?

They are the same Apache HTTP Server. Debian and Ubuntu call the package and service apache2, while AlmaLinux, Rocky Linux and other Red Hat family systems call it httpd. The configuration layout also differs between the two families.

How do I check that my Apache configuration is valid?

Run sudo apachectl configtest. It prints Syntax OK or the file and line of the error. Run it before every reload, so a typo doesn't take your sites offline.

Should I use mod_php or PHP-FPM with Apache?

Use PHP-FPM with the event MPM. mod_php forces the older prefork MPM, which uses more memory under load and cannot use HTTP/2. PHP-FPM runs PHP as a separate service that Apache talks to through proxy_fcgi.

Can I edit Apache settings on shared hosting?

No. On shared hosting the server configuration is shared by every account, so you can't change it or restart Apache. You can use .htaccess files for rewrites, redirects, access rules and headers. On Domain India shared hosting, php_value lines in .htaccess cause a 500 error because PHP does not run as an Apache module.

Does Domain India shared hosting use Apache or LiteSpeed?

Apache. On cPanel servers an nginx proxy sits in front of Apache. For WordPress caching on Domain India shared hosting, use a plugin such as WP Super Cache or W3 Total Cache.

How do I get free HTTPS on Apache?

Install Certbot and run certbot --apache for your domain. It gets a free Let's Encrypt certificate, configures the HTTPS virtual host and renews the certificate automatically.

Ready to run your own server? Compare VPS plans for full control of Apache, choose cPanel hosting if you'd rather we run the server, or open a ticket if you're unsure which fits.

Run Apache your way

Full root access on a self-managed VPS, so you can install and tune Apache exactly as this guide describes.

See VPS plans

Was this article helpful?

Your answer helps us decide what to improve next.

Still need help? Open a support ticket and our team will reply.

Prefer an app? Add this site to your home screen.Get the app
Apache Web Server Guide: Setup, HTTPS & Tuning