PHP Classes

PHP Add Apache Virtual Host: Add a virtual host to Apache configuration

Recommend this page to a friend!
  Info   View files View files (7)   DownloadInstall with Composer Download .zip   Reputation   Support forum (4)   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2023-12-03 (3 days ago) RSS 2.0 feedStarStarStar 57%Total: 1,373 This week: 5All time: 2,826 This week: 81Up
Version License PHP version Categories
add-host 10GNU Lesser Genera...5.3PHP 5, Unix, Systems administration, C..., H...


This class can be used to add a virtual host to Apache configuration.

It creates a Apache configuration file with the definitions of a virtual host for a given IP address, domain and document root folder.

The class can also create a .htaccess file to set mod_rewrite options, add domain to the /etc/hosts file, download and install Composer.

Innovation Award
PHP Programming Innovation award nominee
July 2013
Number 2

Prize: One downloadable e-book of choice by O'Reilly
Apache is a popular Web server that has configuration format which is not very trivial to understand.

This class can help automating several types of tasks to setup virtual hosts handled by Apache.

Manuel Lemos
Picture of Evaldo Barbosa
  Performance   Level  
Name: Evaldo Barbosa <contact>
Classes: 3 packages by
Country: Brazil Brazil
Age: 42
All time rank: 128485 in Brazil Brazil
Week rank: 79 Up7 in Brazil Brazil Up
Innovation award
Innovation award
Nominee: 3x

Winner: 1x


# Add Virtualhosts Tool PHP Script to create Apache virtual hosts (VHost) using the command line. #### Usage: > sudo path_to/addhost.php IP DOMAIN PATH_TO_PROJECT_FOLDER [--htaccess] [--composer] [--errorlog] or > sudo path_to/addhost.php IP DOMAIN --removehost or > sudo path_to/addhost.php IP DOMAIN --checkhost #### Example: > sudo path_to/addhost.php dev.localdomain /home/user/project #### How does this work? First addhost verifies if the project source folder exists, if not it is created. After that addhost opens the /etc/hosts file and appends the IP and DOMAIN. Finally the virtual host config file is creates in the apache enabled sites folder. #### I want to configure something. How I do? * With --htaccess option automatically creates the .htaccess in your public folder. * With --composer addhost downloads composer.phar file and creates a project composer.json. * With --errorlog provides you with a virtualhost's error log file. #### I need to use proxy, does this works? Yeah! This package now is preparet to support proxy. You need to edit the conf file and define two constants. ###### EXAMPLE: PROXY_HOST: Here you should write the IP or proxy host name and port number separated by ':'. Example: define('PROXY_HOST',''); PROXY_USER: Here you should write the proxy user and password separated by ':'. Example: define('PROXY_USER','evaldobarbosa:myproxypassword'); #### Can Addhost remove old VHosts? Yes! See below for the syntax to remove old hosts. > sudo path_to/addhost.php dev.localdomain --removehost #### Finally... Restart apache. Article (brazilian portuguese) --- > - > iMasters -

  Files folder image Files  
File Role Description
Plain text file addhost.class.php Class Class source
Accessible without login Plain text file addhost.php Appl. Application script
Accessible without login Plain text file conf.php Conf. Configuration script
Accessible without login Plain text file de_de.lang.php Aux. external contribuition
Accessible without login Plain text file en_en.lang.php Aux. Auxiliary script
Accessible without login Plain text file pt_br.lang.php Aux. Auxiliary script
Accessible without login Plain text file Data Auxiliary data

 Version Control Unique User Downloads Download Rankings  
This week:5
All time:2,826
This week:81Up
User Ratings User Comments (1)
 All time