我为这件事感到疯狂,但我想在php中自己制作它。
我在我的系统中安装了以下内容。
WAMP Server 2.2,其中包括以下
主机文件的位置:
C:\Windows\System32\Drivers\etc\hosts
WAMP服务器的位置:
C:\wamp
Apache Web服务器的位置:
- C:\wamp\bin\apache\apache2.2.22
- C:\wamp\bin\apache\apache2.2.22\conf\extra\httpd-vhosts.conf
MySQL服务器的位置:
C:\wamp\bin\mysql\mysql5.5.24
PHP的位置:
C:\wamp\bin\php\php5.3.13
我在 localhost
中创建了VHost的简单示例
例如我想在 80 端口上创建简单的域 www.mylocalsite.com
为此,我有以下步骤:
(1)Enagle Apache模块
(2)打开httpd.conf文件以启用虚拟主机设置
C:\wamp\bin\apache\apache2.2.22\conf\httpd.conf
Include conf/extra/httpd-vhosts.conf // Remove the # before Include and save file
(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>
(4)在主机文件中添加条目 使用管理员权限 C:\ Windows \ System32 \ Drivers \ etc \ hosts 在记事本中打开文件 在文件末尾添加以下行并保存。
127.0.0.1 www.mylocalsite.com
(5)重启(从WAMP)Apache Web服务器并在浏览器中运行 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>
当我点击 按钮时,它会自动在主机文件中创建域条目, httpd-vhosts中的 vhosts 条目。 conf 文件。
并且,当重新启动Apache服务器时,它将自动动态创建域或子域。
有谁知道我怎么能用本地系统的任何语言建立以下内容?
答案 0 :(得分:2)
不要使用网络表单。您可以使用批处理文件查看我的演示:
(1)创建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)创建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)以管理员身份运行add_vhost.bat(写入HOSTS文件)