How to create local domain management for Windows in php?

I am crazy about this thing, but I want to do it myself in php.

I installed the following on my system.

WAMP Server 2.2, which includes the following

  • Apache web server version 2.2.222
  • MySQL server version 5.5.24
  • PHP Version 5.3.13
  • Windows 8 Version 64Bit

Hosts File Location:

C:\Windows\System32\Drivers\etc\hosts 

WAMP server location:

 C:\wamp 

Apache web server location:

  - C:\wamp\bin\apache\apache2.2.22 - C:\wamp\bin\apache\apache2.2.22\conf\extra\httpd-vhosts.conf 

MySQL Server Location:

 C:\wamp\bin\mysql\mysql5.5.24 

PHP location:

 C:\wamp\bin\php\php5.3.13 

I have a simple example of creating VHost in localhost for example I want to create a simple domain www.mylocalsite.com on port 80

For this, I have the following steps:

(1) Enagle Apache Modules

  • rewrite_module
  • vhosts_alias_module

(2) Open the httpd.conf file to enable Vhost settings

 C:\wamp\bin\apache\apache2.2.22\conf\httpd.conf 

Virtual hosts

 Include conf/extra/httpd-vhosts.conf // Remove the # before Include and save file 

(3) Add a VHost entry in the httpd-vhosts.conf file

 <VirtualHost *:90> DocumentRoot "C:/mylocalsite.com/" ServerName www.mylocalsite.com # This should be omitted in the production environment SetEnv APPLICATION_ENV development <Directory "C:/mylocalsite.com/"> Options Indexes MultiViews FollowSymLinks AllowOverride All Order allow,deny Allow from all </Directory> ErrorLog "C:/mylocalsite.com/logs/error.log" // Logs folder should be exists CustomLog "C:/mylocalsite.com/logs/access.log" common </VirtualHost> 

(4) Add an entry to the hosts file Open the file in Notepad with administrator privileges C: \ Windows \ System32 \ Drivers \ etc \ hosts add the following line to the end of the file and save it.

 127.0.0.1 www.mylocalsite.com 

(5) Restart the Apache web server (from WAMP) and run it in the browser http://www.mylocalsite.com/ .

Now, my question is: how can I perform the above steps in a dynamic nature using PHP / JSP or any other language .

Suppose I create one HTML form with the following fields, and when submitted, it will create a new MySQL record for this domain.

EDIT:

 Domain Type: select option or Radio Options ( Root/Sub-Domain ) Sub-Domain Name ( Optional ): Text field Domain Name: Text field Project Path: text field Log Folder Path: text field Tmp Folder Path: text field Database Type: text field ( mysql/pgsql ) <Submit> 

when i press the button , it will automatically create a domain entry in the hosts file, vhosts in httpd-vhosts. conf .

And when you restart the Apache server, it will automatically start the automatically created domain or subdomain.

Does anyone know how I can install the following things in any language just for the local system?

+7
java php apache virtualhost localhost
source share
1 answer

Do not use a web form. You can see my demo with a batch file:

(1) Create a vhost template.txt

 <VirtualHost *:90> DocumentRoot "_ROOT_" ServerName _DOMAIN_ # This should be omitted in the production environment SetEnv APPLICATION_ENV development <Directory "_ROOT_"> Options Indexes MultiViews FollowSymLinks AllowOverride All Order allow,deny Allow from all </Directory> ErrorLog "_ROOT_/logs/error.log"// Logs folder should be exists CustomLog "_ROOT_/logs/access.log" common </VirtualHost> 

(2) Create add_vhost.bat

 @echo off set /p domain=Domain (www.mylocalsite2.com): set lineHost=127.0.0.1 %domain% REM Create the domain entry in hosts file echo %lineHost% >> C:\Windows\System32\drivers\etc\hosts set /p folder=Folder (C:/mylocalsite2.com/): REM Create vhost entry in httpd-vhosts.conf file setlocal enabledelayedexpansion for /f "tokens=*" %%i in (template.txt) do ( set str=%%i set str=!str:_ROOT_=%folder%! set str=!str:_DOMAIN_=%domain%! echo !str! >> C:\wamp\bin\apache\apache2.2.22\conf\extra\httpd-vhosts.conf ) 

(3) Run add_vhost.bat as administrator (to write the HOSTS file)

+2
source share

All Articles