apache2-vhost - Apache2 vhost configuration manager
apache2-vhost -[aprs] <vhostdomain>; apache2-vhost -[hlv]
apache2-vhost is a command line program to assist in adding and removing apache2 virtual hosts to and from the system. It completes this task by utilizing the creation and removal of regular and symlinked files in the HTTPD_ROOT/sites-available/ and HTTPD_ROOT/sites-enabled/ directories respectively, and managing <vhostdomain> entries in the system's hosts file. It uses the current working directory for the virtual host's document_root.
This program was written primarily for web developers that need to host several web projects on one system when developing and testing. It should allow a web developer to navigate to http://<vhostdomain>/ without too much mucking around with apache2 configs themselves.
- -a, --add <vhostdomain> Creates an apache2 vhost configuration file using the current working directory as document_root for <vhostdomain> in HTTPD_ROOT/sites-available/; then symlinks the file to HTTPD_ROOT/sites-enabled/ and adds an entry to to /etc/hosts as if
apache2-vhost --link <vhostdomain>
was called
-
-h, --help Outputs this help text
-
-l, --list Lists all files with the file extension *.vhost.conf in HTTPD_ROOT/sites-available/
-
-p, --purge <vhostdomain> Removes the associated <vhostdomain> file from HTTPD_ROOT/sites-available/; then removes the associated link from HTTPD_ROOT/sites-enabled/ and entry from /etc/hosts as if
apache2-vhost --remove <vhostdomain>
was called
-
-r, --remove <vhostdomain> Removes the associated <vhostdomain> file from HTTPD_ROOT/sites-enabled/ and entry from /etc/hosts
-
-s, --link <vhostdomain> Symlinks the associated <vhostdomain> file from HTTPD_ROOT/sites-available/ to HTTPD_ROOT/sites-enabled/ and adds an entry to /etc/hosts
-
-v, --version Print the version number and exit
apache2-vhost --add fake.localhost
adds a new apache2 vhost file to HTTPD_ROOT/sites-available/, then symlinks it to HTTPD_ROOT/sites-enabled/ and adds an entry to /etc/hosts
apache2-vhost --remove fake.localhost
removes the fake.localhost symlink from HTTPD_ROOT/sites-enabled/, then removes the entry from /etc/hosts. The file located at HTTPD_ROOT/sites-available/fake.localhost.vhost.conf is left alone
This section describes any environment dependencies that are required for apache2-vhost to properly operate. Generally speaking, the main requirement is that apache2 is installed on the system apache-vhost is executed on.
HTTPD_ROOT Location of apache2's configuration files. apache2-vhost attempts to find the location by forking and calling
apache2 -V
and comparing the output for the HTTPD_ROOT configuration. If no HTTPD_ROOT configuration can be found, /etc/apache2 is used as a fallback location.
-
HTTPD_ROOT/sites-available/ Directory where generated <vhostdomain>.vhost.conf files are stored
-
HTTPD_ROOT/sites-enabled/ Directory where <vhostdomain>.vhost.conf symlinks are stored
-
/etc/hosts System file to point <vhostdomain> to 127.0.0.1
The full documentation for apache2-vhost can be found in the source code. If apache2-vhost has been distributed as a binary only, you can find the source code online at https://github.com/akoimeexx/apache2-vhost
Also included in the git repository is localhost.function.sh, the bash script function I originally started writing to manage my virtual host files. It is provided for reference only, and should not be used in a production environment as it is not thoroughly tested.
apache2-vhost returns EXIT_SUCCESS (0) on normal operation, or an exit code as defined in /usr/include/sysexits.h on failure, along with a human-readable error description on stderr.
It should be noted that this program will exit out on a file operation error if the user running it does not have correct permissions. This is by design; if you don't have sudo access you probably shouldn't be mucking about with /etc/hosts and the like.
No known bugs, please report any bugs found to the author.
Johnathan McKnight
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.