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
2024-01-09 (3 months ago) RSS 2.0 feedStarStarStar 52%Total: 1,377 All time: 2,824 This week: 206Up
Version License PHP version Categories
add-host 11GNU Lesser Genera...5.3PHP 5, Unix, Systems administration, C..., H...
Description 

Author

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: 43
All time rank: 128485 in Brazil Brazil
Week rank: 289 Up22 in Brazil Brazil Up
Innovation award
Innovation award
Nominee: 3x

Winner: 1x

Details

# 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 127.0.2.1 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','192.168.0.15:3128'); 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 127.0.2.1 dev.localdomain --removehost #### Finally... Restart apache. Article (brazilian portuguese) --- > PHP-DF.org - http://bit.ly/19zPh3A > iMasters - http://bit.ly/1aYFFjz

  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 README.md Data Auxiliary data

 Version Control Unique User Downloads Download Rankings  
 100%
Total:1,377
This week:0
All time:2,824
This week:206Up
User Ratings User Comments (1)
 All time
Utility:87%StarStarStarStarStar
Consistency:87%StarStarStarStarStar
Documentation:-
Examples:-
Tests:-
Videos:-
Overall:52%StarStarStar
Rank:2308