Apache VirtualHost Generator
Assemble a complete VirtualHost block for a domain, HTTPS and PHP-FPM and drop it into sites-available.
-
1Enter data
Enter content, paste text or load a file from disk. -
2Click the button
The tool will immediately process your data in the browser. -
3Get the result
Copy the finished text or save the file to your device.
return "Result ready in 0.1s";
}
Rate this tool:
Related tools
Other tools you may find usefulApache VirtualHost generator - domain, PHP-FPM and HTTPS in one file
The Apache VirtualHost generator assembles a ready <VirtualHost> block in which a domain gets its own DocumentRoot, a <Directory> section, a handoff of PHP to PHP-FPM and separate logs. When you enable SSL, it adds a block on port 443 with the certificate and a second block on port 80 that redirects traffic to HTTPS.
What this tool actually does
You enter a domain, a DocumentRoot directory, an admin address, a port and the PHP-FPM socket, and you get a complete configuration file. The first line is <VirtualHost *:80> or <VirtualHost *:443>, depending on SSL. Then come ServerName and ServerAlias www., so the site answers with and without the prefix. The domain is checked against valid DNS syntax and the DocumentRoot has to be an absolute path - these values go straight into the server configuration.
A VirtualHost sits above the .htaccess file. Build a directory rule in the .htaccess file generator, and add password access with an entry from the .htpasswd generator.
The Directory section and the 403 error
The most common reason a fresh site returns 403 Forbidden is a missing Require all granted in the <Directory> block. Since 2.4 Apache denies access by default to directories you do not open explicitly. That is why the tool inserts three directives: Options -Indexes +FollowSymLinks turns off directory listing, AllowOverride All lets Apache read rules from .htaccess, and Require all granted opens the resource to every client. Without that last line the server answers 403.
Key directives in the generated file
| Directive | What it controls |
|---|---|
ServerName / ServerAlias | The main domain and the www. name Apache matches a request against |
DocumentRoot | The directory files are served from (for Laravel: public) |
<Directory> | Directory permissions, including Require all granted |
<FilesMatch> | Handing .php files to PHP-FPM through SetHandler |
SSLCertificate* | Paths to fullchain.pem and privkey.pem |
ErrorLog / CustomLog | Separate error and access logs for the domain |
SSL, port 443 and the redirect from HTTP
An SSL certificate works only in a block listening on port 443, not on 80. So when you tick SSL, the tool routes the main block to *:443, inserts SSLEngine on and the SSLCertificateFile and SSLCertificateKeyFile paths to the Let's Encrypt directory /etc/letsencrypt/live/. It also adds a short <VirtualHost *:80> block that uses a RewriteRule to redirect HTTP to HTTPS with a 301 code. Confirm the certificate in the SSL certificate checker, and assemble security headers in the CSP header generator.
PHP-FPM instead of mod_php
Modern Apache does not run PHP inside the server; it hands it to PHP-FPM through a socket, e.g. unix:/run/php/php8.3-fpm.sock. The tool writes this into a <FilesMatch \.php$> block with SetHandler "proxy:...|fcgi://localhost". This layout is faster, separates PHP permissions from Apache and allows different PHP versions per domain. It needs the proxy_fcgi and setenvif modules. An empty field skips this block - the vhost then serves static files.
Where to save the file and how to enable it
- Save the configuration in
/etc/apache2/sites-available/, e.g. asexample.com.conf. - Enable the site with
a2ensite example.com.conf— a symlink appears insites-enabled/. - With SSL and the redirect, enable the modules:
a2enmod ssl rewrite proxy_fcgi setenvif. - Check the syntax with
apache2ctl configtest(it should returnSyntax OK). - Reload the server with
systemctl reload apache2.
DocumentRoot at the project's public directory, not at its root - otherwise the .env file and the source code would be reachable through a browser.One server, many domains
That is the whole point of VirtualHosts: one Apache serves many sites, matching the Host header of each request to the right ServerName. Every domain gets its own file in sites-available and separate logs. If you move rules onto Nginx acting as a proxy, exceptions for single paths are easy to assemble in the Nginx location block configurator.
Frequently asked questions
Why does the site return 403 Forbidden even though the path is correct?
Usually the <Directory> block is missing Require all granted. Since version 2.4 Apache denies access by default to directories you do not open explicitly. The vhost generated here always inserts that line.
I enabled SSL and Apache will not start. What should I check?
The SSL block has to listen on port 443, which is why the tool moves it from 80 to 443 automatically. Also make sure the ssl module is enabled and that the fullchain.pem and privkey.pem files exist at the configured paths. The error log always names the actual reason.
What do I put in DocumentRoot for Laravel?
The project's public directory, e.g. /var/www/example.com/public. Pointing at the project root would expose the .env file and the whole codebase. The same rule applies to Symfony.
Why does the site show the default page instead of mine?
Usually the vhost was not enabled with a2ensite, or it clashes with the default 000-default site. Disable it with a2dissite 000-default, run apache2ctl configtest and reload. Apache uses the first matching block.
Do I have to use PHP-FPM?
No, but it is the recommended layout on modern Apache. An empty field skips the <FilesMatch> block and the vhost serves static files. With a socket, remember the proxy_fcgi and setenvif modules, and the PHP version in the socket path has to match the installed FPM service.