Skip to content
ZeroServer.tools

Apache Config Generator

Generate Apache VirtualHost configs for HTTP/HTTPS sites with PHP and SSL.

Presets

VirtualHost Settings

Virtual Hosts2 (HTTP + HTTPS)
PHP SocketFPM Sock (PHP 8.2)
Domain Nameexample.com
Output Size956 B (32 lines)

Apache VirtualHost Configuration Guide

An Apache VirtualHost configuration file controls how the Apache HTTP Server handles requests for a specific domain. Save the generated .conf file to /etc/apache2/sites-available/ on Ubuntu/Debian, or to /etc/httpd/conf.d/ on CentOS/RHEL. Enable it with a2ensite example.com.conf and reload Apache with systemctl reload apache2. For SSL, replace the certificate paths with your actual certificate files from Let's Encrypt (Certbot) or your certificate authority. PHP-FPM handler lines assume the standard socket path used by the php8.2-fpm package on Debian-based systems.

Built and maintained by Meet Shah · Last updated

What this tool is used for

  • Producing a VirtualHost block for a new site.
  • Getting the SSL directive set right without copying from an old config.
  • Producing an HTTP-to-HTTPS redirect host alongside the main one.
  • Generating a starting config you then adapt.
  • Comparing a generated block against an inherited one.

Frequently Asked Questions

What does a VirtualHost block actually do?
It lets one Apache instance serve many sites from one IP by matching the `Host` header against `ServerName` and `ServerAlias`. Requests that match no block fall through to the FIRST one defined, which is why a misconfigured site so often serves a different site's content.
Why are there two blocks when SSL is enabled?
Because port 80 and port 443 are separate listeners. The standard arrangement is a `*:80` block that does nothing but redirect to HTTPS, and a `*:443` block with the certificate and the real configuration. Serving content on both is how a site ends up quietly available unencrypted.
Should the www redirect be to www or away from it?
Either, as long as it is consistent — the harm is serving both, which splits caching and search signals across two hostnames. The redirect must be a 301 so it is treated as canonical, and it should happen in one hop rather than chaining through http → https → www.
Is it better to configure this here or in .htaccess?
Here, if you have access. `.htaccess` is read and re-parsed on every request in every directory along the path, which is a measurable cost, and it needs `AllowOverride` enabled to work at all. It exists for shared hosting where you cannot touch the main config.
How do I check the config before restarting?
`apachectl configtest` — it parses the configuration and reports syntax errors without touching the running server. Then reload rather than restart, so existing connections finish. A restart on a syntax error leaves the server down, which is exactly when you least want it.

Common errors and gotchas

  • Omitting ServerName, which makes the host match requests you did not intend.
  • Leaving directory access open, which exposes files above the document root.
  • Putting a redirect inside the same host as the SSL config, which creates a loop.
  • Assuming a module is enabled, when the directives silently fail without it.
  • Deploying without testing the config, which the server's own check does in a second.

Related Developer Utilities tools

Private & free — this tool runs entirely in your browser.

BluehostReliable WordPress & web hosting — exclusive pricing from $3.79/mo.affiliate