Download the PHP package jturbide/vhost without Composer
On this page you can find all versions of the php package jturbide/vhost. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download jturbide/vhost
More information about jturbide/vhost
Files in jturbide/vhost
Package vhost
Short Description A command-line tool built with Symfony Console that automatically generates Apache and Nginx virtual host configurations from YAML definitions, updates system hosts files, restarts web servers, and manages PHP caches (OPCache, APCu, sessions). Supports both Linux and Windows environments.
License BSD-3-Clause
Informations about the package vhost
Vhost Generator CLI
A command-line tool built with Symfony Console that automatically generates Apache and Nginx virtual host configurations from YAML definitions, updates system hosts files, restarts web servers, and manages PHP caches (OPCache, APCu, sessions). Supports both Linux and Windows environments.
Features
- Cross-platform: runs on Linux and Windows.
- Generates vhost configs for both Apache and Nginx from simple YAML definitions.
- Injects global config snippets into each server’s main config file (placing them next to confFile).
- Updates /etc/hosts or C:\Windows\System32\drivers\etc\hosts for local domain resolution.
- Respects existing files; uses backups and --force to prevent accidental overwrites.
- Clears PHP caches (OPCache, APCu, sessions) on multiple PHP versions (Linux with Remi).
- Service restarts: can optionally restart Apache, Nginx, and PHP-FPM.
- Verbosity levels with colored [INFO], [OK], [WARNING], and [ERROR] logs.
Requirements
- PHP 8.0+
- Composer (to install dependencies)
- Symfony Console and Symfony YAML libraries (handled by composer.json)
- Linux: systemctl, apachectl, nginx commands for restarts/tests (or suitable equivalents)
- Windows: net stop, net start with correct service names
- Two YAML config files: config.yaml and sites.yaml
Installation
- Clone or download this repository.
- Run 'composer install'.
- Ensure 'bin/vhost.php' is executable (chmod +x if on Linux).
- Make sure 'config.yaml' and 'sites.yaml' exist in the root directory.
Configuration Files
config.yaml
Defines per-platform (Linux, Windows) settings, including main config files, vhost directories, service names, default SSL certs, optional global config snippets, and your templates.
Example minimal structure:
sites.yaml
Lists all the domains to configure, their document root paths, any aliases, custom SSL certs, and optional 'custom' snippet.
Example structure:
Usage
Run the command from your project root:
CLI Options
--force, -f
Overwrite any existing files (site vhosts, global snippets, main config blocks).
--no-backup
Disable creating .bak-YYYYmmddHHMMSS copies before overwriting.
--os=VALUE
Override OS detection with 'linux' or 'windows'. Defaults to PHP_OS_FAMILY.
--restart, -r
Restart Apache/Nginx after config generation.
--restart-php
Restart discovered PHP-FPM services on Linux.
--clear-opcache
Clear OPCache on all discovered PHP versions (Remi-based).
--clear-apcu
Clear APCu on all discovered PHP versions (Remi-based).
--clear-sessions
Remove session files based on each version’s session.save_path.
Examples
1) Basic generation (no backups, no restarts):
2) Force overwrite and restart services:
3) Clear all caches (OPCache, APCu, sessions):
4) Manually set OS:
How It Works
Global Snippet Injection
Reads your config.yaml
for each server (apache or nginx). Places your globalSnippet
text into a file named global-apache.conf
or global-nginx.conf
located in the same directory as confFile
. Then injects an Include
or include
line into your main config, marked by # BEGIN AUTOGENERATED-apache
or # BEGIN AUTOGENERATED-nginx
.
Site Vhost Generation
For each site in sites.yaml:
- Loads the templateFile (e.g.
templates/linux/apache.conf
). - Fills placeholders like
{{name}}
,{{root}}
,{{ssl_certificate}}
, etc. - Merges optional
{{custom}}
snippet if defined. - Writes the final
.conf
to the confDir (e.g./etc/httpd/conf.d/vhosts/myapp.local.conf
). - Skips overwriting unless
--force
. If doc root doesn't exist, logs a warning and skips.
Hosts File Updates
Appends domain entries to your system hosts file in a block marked # BEGIN WEB.LOCAL
/ # END WEB.LOCAL
. Respects backups if needed. Uses the IP from servers.localhost
in config.yaml
by default, or a custom ip
in sites.yaml
if present.
Service Restarts
If --restart
is specified:
- On Linux, runs 'apachectl configtest && systemctl restart httpd' and 'nginx -t && systemctl restart nginx' (or whatever service names are set in config.yaml).
- On Windows, runs 'net stop' and 'net start' for each service name.
If --restart-php
is used, it restarts any discovered 'php.*fpm' services on Linux.
PHP Cache Clearing
If --clear-opcache
or --clear-apcu
, the script runs php -r ...
in each discovered /opt/remi/phpXX
version to reset OPCache or APCu. If --clear-sessions
, removes session files in each version’s session.save_path (parsed from php.ini). This feature is Linux-specific by default.
Advanced Topics
Overwriting and Backups
- By default, files are not overwritten if they exist. Use
--force
to overwrite. - If backups are enabled, the script copies existing files to filename.bak-YYYYmmddHHMMSS.
Directory Checks
- If the site document root doesn’t exist, the script logs a warning and skips that site’s vhost generation.
Customization
- Add more placeholders to your template files (e.g.
{{myVar}}
). - Modify the script to parse them from site or config variables as needed.
- Adjust session clearing logic to match your system’s layout if not using Remi or if on Windows.
Installing Apache Lounge on Windows and Setting Up the Service
Step-by-Step Guide
-
Download Apache from Apache Lounge
- Visit Apache Lounge and download the appropriate version of Apache for your system (e.g., 64-bit or 32-bit).
-
Extract Apache Files
- Extract the downloaded
.zip
file to a desired location (e.g.,C:\httpd\
).
- Extract the downloaded
-
Configure Apache
- Open the
httpd.conf
file located in theconf
directory of the extracted files (e.g.,C:\httpd\conf\httpd.conf
). -
Modify the following lines to suit your environment:
-
Update the
ServerRoot
to the extracted path, e.g.: -
Update the
DocumentRoot
to your desired root directory, e.g.: - Ensure you have configured your virtual host settings correctly (refer to the relevant sections in this document).
-
- Open the
-
Install the Service
- Open a Command Prompt with Administrator privileges.
-
Navigate to the
bin
directory of the extracted Apache folder, e.g.: - Run the following command to install Apache as a Windows service:
-
Verify Installation
- After running the command, Apache is registered as a Windows service.
- Open the Windows Services Manager (press
Win + R
, typeservices.msc
, and hit Enter). - Look for the service named
Apache2.4
(or the name defined in your Apache setup). - Confirm that the service appears as "Automatic" in the Startup Type column.
-
Start the Service
-
You can start Apache in any of the following ways:
-
Run the command in the
bin
directory: - Or, start the service from the Windows Services Manager by right-clicking on
Apache2.4
and selecting " Start."
-
-
- Test Your Setup
- Open a web browser and navigate to
http://localhost
. - If everything is configured correctly, you should see the Apache default page or your defined
DocumentRoot
content.
- Open a web browser and navigate to
Uninstalling the Apache Service
- If you need to remove the Apache service, navigate to the
bin
directory and run:
This should properly unregister Apache as a Windows service.
License
This sample project is provided as is, under no specific license unless you add one. Feel free to incorporate it into your private or commercial workflow.
For any questions or suggestions, please open an issue or contact the maintainer.
Enjoy automating your virtual host configurations across Linux and Windows!