如何在php中为windows创建localhost域管理?

Ash*_*mar 7 php java apache localhost virtualhost

我对这个事情感到很疯狂,但我想在php中自己制作它.

我在我的系统中安装了以下内容.

WAMP Server 2.2包括以下内容

  • Apache Web服务器版本2.2.222
  • MySQL服务器版本5.5.24
  • PHP版本5.3.13
  • 操作系统版本Windows 8 64位

主机文件的位置:

C:\Windows\System32\Drivers\etc\hosts
Run Code Online (Sandbox Code Playgroud)

WAMP服务器的位置:

C:\wamp
Run Code Online (Sandbox Code Playgroud)

Apache Web服务器的位置:

 - C:\wamp\bin\apache\apache2.2.22

 - C:\wamp\bin\apache\apache2.2.22\conf\extra\httpd-vhosts.conf
Run Code Online (Sandbox Code Playgroud)

MySQL服务器的位置:

C:\wamp\bin\mysql\mysql5.5.24
Run Code Online (Sandbox Code Playgroud)

PHP的位置:

C:\wamp\bin\php\php5.3.13
Run Code Online (Sandbox Code Playgroud)

我有创建VHost的简单示例,localhost 例如我想在80端口上创建简单域www.mylocalsite.com

为此,我有以下步骤:

(1)Enagle Apache模块

  • rewrite_module
  • vhosts_alias_module

(2)打开httpd.conf文件以启用Vhost设置

C:\wamp\bin\apache\apache2.2.22\conf\httpd.conf
Run Code Online (Sandbox Code Playgroud)

虚拟主机

Include conf/extra/httpd-vhosts.conf // Remove the # before Include and save file
Run Code Online (Sandbox Code Playgroud)

(3)在httpd-vhosts.conf文件中添加VHost条目

<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>
Run Code Online (Sandbox Code Playgroud)

(4)在hosts文件中添加条目在 记事本中打开文件,使用管理员权限C:\ Windows\System32\Drivers\etc\hosts 在文件末尾添加以下行并保存.

127.0.0.1    www.mylocalsite.com
Run Code Online (Sandbox Code Playgroud)

(5)重启(From WAMP)Apache Web Server并在浏览器中运行 http://www.mylocalsite.com/即可运行.

现在,我的问题是如何使用PHP/JSP或任何其他语言在动态性质中执行上述步骤.

假设我将使用以下字段在HTML中创建一个表单,并在提交时将为该域创建新的MySQL条目.

编辑:

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>
Run Code Online (Sandbox Code Playgroud)

当我点击 按钮它将自动在hosts文件中创建域条目,在httpd-vhosts.conf文件中创建vhosts条目.

并且,当重新启动Apache服务器时,它将动态地自动创建域或子域.

任何人都知道我怎么能用本地系统的任何语言建立以下东西?

小智 2

不要使用网络表单。您可以使用批处理文件查看我的演示:

(1)创建虚拟主机模板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>
Run Code Online (Sandbox Code Playgroud)

(2)创建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  
)  
Run Code Online (Sandbox Code Playgroud)

(3) 以管理员身份运行add_vhost.bat(写入HOSTS文件)