Apache. Virtual hosts in expert mode
In BeAdmin you can create an Apache virtual host only in expert mode — the config is edited by hand. This article walks through the template, the ServerName check, attaching PHP via PHP-FPM and working with .htaccess. For module installation and operating modes, see the Quick start.
Creating a virtual host
To set up an Apache virtual host you have to write its configuration manually in the <VirtualHost>...</VirtualHost> format.
To create a host:
- In the side menu of the Apache section, click «Create virtual host».
- In the «Set up host configuration» dialog that opens, enter the site's domain name (for example,
example.com). This value goes into the config file name (example.com.conf) and into theServerNamecheck. - Click «Continue».
- The editor opens with a
<VirtualHost>template — adapt it to your site. - Click «Create».
The default template looks like this:
<VirtualHost *:8808>
ServerName example.com
ServerAlias www.example.com
DocumentRoot /home/www/example.com/public
<Directory /home/www/example.com/public>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
DirectoryIndex index.php index.html
</VirtualHost>What each directive does:
<VirtualHost *:8808>— Apache accepts requests on all interfaces on port 8808.ServerName— the site's main domain; must match the value you entered in the form (see below).ServerAlias— additional domains and subdomains served by the same virtual host.DocumentRoot— path to the site files on disk.<Directory ...>— rules for a specific directory:Options Indexes FollowSymLinks— shows the directory listing and allows following symbolic links.AllowOverride All— enables.htaccess.Require all granted— opens access.
DirectoryIndex— the lookup order for the index file when a directory is requested.
Once saved, the host appears in the side menu and starts handling requests immediately (provided Apache is running). BeAdmin reloads the Apache config on its own without restarting the service — open connections are kept alive, and you don't need to click «Reload configuration» in the module header.
Port in the template
Port *:8808 on the first line of the template is the HTTP port of the Nginx + Apache combo, which is the BeAdmin default for this mode. If Apache runs in standalone mode, change the port to :80 — or to whatever you set in the module installation dialog. For an HTTPS host, use :8843 (combo) or :443 (standalone). For more on the modes and default ports, see the Quick start.
ServerName must match the domain
The panel checks that the ServerName and ServerAlias values in the config either equal the domain you entered in the field or end with it (subdomains *.example.com are allowed). If the field says example.com but the config has ServerName api.other.com, the host will not save.
Managing an existing host
You can't disable a host without deleting it — comment out the <VirtualHost> block and click «Update», or delete the file entirely. To delete a host, use the trash icon next to its name in the side menu.
Attaching PHP via PHP-FPM
Out of the box the Apache module in BeAdmin installs plain Apache with no PHP handler. To attach PHP, add a PHP-FPM block inside the <VirtualHost> block (next to <Directory>):
<FilesMatch \.php$>
SetHandler "proxy:unix:/var/run/php/php8.3-fpm.sock|fcgi://localhost"
</FilesMatch>The PHP module in BeAdmin supports several versions; each one creates its own socket /var/run/php/php<version>-fpm.sock — for example, php8.3-fpm.sock. Look up the version for a particular site in the PHP module and substitute it into SetHandler.
.htaccess and AllowOverride
.htaccess is a file with Apache directives placed inside the site's directory. Apache reads it on every request, so no service restart is needed. For this to work, the host's <Directory> block must include AllowOverride All — it is already part of the default template above.
To edit .htaccess, open the «Files» section in BeAdmin, navigate to the site's directory and open the file in the editor. If the file does not exist yet, create it there. Changes take effect on the next request.
See also
- Apache. Quick start — module overview, operating modes, installation.
- Official Apache HTTP Server documentation — reference for directives, modules and MPM models.