【发布时间】:2013-10-08 10:33:58
【问题描述】:
我对这件事很着迷,但我想自己在 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
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 端口
为此,我有以下步骤:
(1) 启用 Apache 模块
- rewrite_module
- vhosts_alias_module
(2) 打开 httpd.conf 文件以启用 Vhost 设置
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) 在 hosts 文件中添加条目 使用管理员权限在记事本中打开文件 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>
当我点击 按钮时,它会自动在 hosts 文件中创建域条目,在 httpd-vhosts 中创建 vhosts 条目。 conf 文件。
并且,当重新启动 Apache 服务器时,它会自动运行动态创建的域或子域。
谁能知道我怎样才能以任何语言为本地系统建立以下内容?
【问题讨论】:
-
在本地机器上开发类似托管环境是一个很好的开始。
-
是的,它对于那些不知道如何在本地环境中创建的用户也很有用。
标签: java php apache localhost virtualhost