本文的目的是介绍WindowsServer2003IIS6PHPConfigurations的详细情况,我们将通过专业的研究、有关数据的分析等多种方式,同时也不会遗漏关于C#创建IIS站点及相应的应用
本文的目的是介绍Windows Server 2003 IIS6 PHP Configurations的详细情况,我们将通过专业的研究、有关数据的分析等多种方式,同时也不会遗漏关于C# 创建 IIS 站点及相应的应用程序池,支持 IIS6.0+Windows Server 2003. 使用 Builder 设计模式、PHP 在Windows 2003 Enterprise Server 、IIS6.0 下的安装、PHP 在Windows 2003 Enterprise Server 、IIS6.0 下的安装_PHP、PHP 在Windows 2003 Enterprise Server 、IIS6.0 下的安装_PHP教程的知识。
本文目录一览:- Windows Server 2003 IIS6 PHP Configurations
- C# 创建 IIS 站点及相应的应用程序池,支持 IIS6.0+Windows Server 2003. 使用 Builder 设计模式
- PHP 在Windows 2003 Enterprise Server 、IIS6.0 下的安装
- PHP 在Windows 2003 Enterprise Server 、IIS6.0 下的安装_PHP
- PHP 在Windows 2003 Enterprise Server 、IIS6.0 下的安装_PHP教程
Windows Server 2003 IIS6 PHP Configurations
第一步:相关软件准备(以下软件全部是截止到2006年7月7日的)
PHP: 推荐PHP-4.4.0-Win32的ZIP解压版本
4.4.0版本下载:http://cn.php.net/get/php-4.4.0-Win32.zip/from/a/mirror
5.1.2版本下载:http://cn.php.net/get/php-5.1.2-Win32.zip/from/a/mirror
5.1.4版本下载:http://download.discuz.net/env/php-5.1.4-Win32.zip
MySQL:配合PHP4推荐MySQL5.0.22的WIN系统安装版本
5.0.22版本下载:http://download.discuz.net/env/mysql-essential-5.0.22-win32.msi
官方下载地址:http://dev.mysql.com/downloads/mysql/5.0.html
ZendOptimizer:版本越新越好啊(目前最新是2.6.2)
官方下载地址:https://www.zend.com/store/free_download.php?pid=13
(虽然下载是免费的,但是要注册用户,才可以下载,为了方便大家的使用,公开我注册好的用户名:ideacmblog密码:chm.ideacm.cn,方便大家使用,希望大家在使用这个帐号的时候不要修改密码和用于其它非正当途径)
phpMyAdmin:这个当然也是越新越好啊
官方下载地址:http://www.phpmyadmin.net/home_page/downloads.php
国内下载地址:http://www.crsky.com/soft/4190.html
http://www.skycn.com/soft/10687.html
好了,软件下载好了,现在就开始安装了;
假设你的系统在C:\\,如果你的系统不是C:\\那么下面请自己对应修改。同时,为了避免C:\\因为重装系统等等各种原因,对C盘进行操作,和在系统盘下备份、转移也很不方便,所以不建议将PHP相关软件安装在C:\\,这里我把它安装在D:\\php目录下(这个目录你也可以自己设定,如果你要安装到不同墓立涉及到路径修改的请修改下面对应的路径即可)
第二步:安装PHP(我取PHP安装路径取为D:\\php\\php4\\(为避混淆,PHP5.1.x版本安装路径取为D:\\php\\php5\\)
(1)、下载得到的 php-4.4.0-Win32.zip ,解压至D:\\php目录,将得到二级目录php-4.4.0-Win32,改名为 php4,也即得到PHP文件存放目录D:\\php\\php4\\[如果是PHP5.1.2,得到的文件是php-5.1.2-Win32.zip,直接全部接压至D:\\php\\php5目录即可得PHP文件存放目录D:\\php\\php5\\];
(2)、再将D:\\php\\php4目录和D:\\php\\php4\\dlls目录[PHP5为D:\\php\\php5\\]下的所有dll文件拷到c:\\Windows\\system32(win2000系统为 c:/winnt/system32/)下,如果目录下有这些dll文件就覆盖已有的dll文件;
(3)、将D:\\php\\php4\\php.ini-dist用记事本打开,利用记事本的查找功能(Ctrl+F)搜索并修改:
register_globals = Off
把 Off 改成 On ,即得到 register_globals = On
注:这个对应PHP的全局变量功能,考虑有很多PHP程序需要全局变量功能故打开,打开后请注意-PHP程序的严谨性,如果不需要推荐不修改保持默认Off状态
再搜索
extension_dir =
,并将其路径指到你的 PHP 目录下的 extensions 目录,比如:修改extension_dir = "./"为extension_dir = "D:/php/php4/extensions/" ;
PHP扩展功能目录[PHP5对应修改为extension_dir = "D:/php/php5/ext/"]
在D:\\php下建立文件夹并命名为tmp
查找
;upload_tmp_dir =
将;upload_tmp_dir该行的注释符,即前面的分号“;”去掉,使该行在php.ini文档中起作用。upload_tmp_dir是用来定义上传文件存放的临时路径,在这里你还可以修改并给其定义一个绝对路径,这里设置的目录必须有读写权限。
这里我设置为upload_tmp_dir = D:/php/tmp (即前面建立的这个文件夹呵)
搜索找到
;Windows Extensions
将下面一些常用的项前面的;去掉
;extension=php_mbstring.dll
;extension=php_curl.dll
;extension=php_dbase.dll
;extension=php_gd2.dll
这个是用来支持GD库的,一般需要,必选
;extension=php_ldap.dll
extension=php_zip.dll
去掉前面的";"
对于PHP5的版本还需要查找
;extension=php_mysql.dll
并同样去掉前面的";"
这个是用来支持MYSQL的,由于PHP5将MySQL作为一个独立的模块来加载运行的,故要支持MYSQL必选
查找
;session.save_path =
去掉前面;号,本文这里将其设置置为
session.save_path = D:/php/tmp
其他的你可以选择需要的去掉前面的;然后将该文件另存为为php.ini到C:\\Windows ( Windows 2000 下为 C:\\WINNT)目录下,注意更改文件后缀名为ini,得到C:\\Windows\\php.ini ( Windows 2000 下为 C:\\WINNT\\php.ini)
若路径等和本文相同可直接保存到C:\\Windows ( Windows 2000 下为 C:\\WINNT)目录下使用若路径等和本文相同可直接保存到C:\\Windows ( Windows 2000 下为 C:\\WINNT)目录下使用
一些朋友经常反映无法上传较大的文件或者运行某些程序经常超时,那么可以找到C:\\Windows ( Windows 2000 下为 C:\\WINNT)目录下的PHP.INI以下内容修改:
max_execution_time = 30 ; 这个是每个脚本运行的最长时间,可以自己修改加长,单位秒
max_input_time = 60 ; 这是每个脚本可以消耗的时间,单位也是秒
memory_limit = 8M ; 这个是脚本运行最大消耗的内存,也可以自己加大
upload_max_filesize = 2M ; 上载文件的最大许可大小 ,自己改吧,一些图片论坛需要这个更大的值
第四步:配置IIS使其支持PHP
IIS如何安装,那就不用说了吧!
PHP 支持 CGI 和 ISAPI 两种安装模式,CGI 更消耗资源,容易因为超时而没有反映,但是实际上比较安全,负载能力强,节省资源,但是安全性略差于CGI,本人推荐使用 ISAPI 模式。故这里只解介绍 ISAPI 模式安装方法:
在“控制面板”的“管理工具”中选择“Internet 服务管理器”,打开 IIS 后停止服务,对于Win2003系统展开”Internet 服务管理器“的下级树一般为你的”计算机名“选择”网站“并单击右键选择“属性”,在弹出的属性窗口上选择“ISAPI 筛选器”选项卡找到并点击“添加”按钮,在弹出的“筛选器属性”窗口中的“筛选器名称”栏中输入:PHP ,再将浏览可执行文件使路径指向 php4isapi.dll 所在路径,如本文中为:D:\\php\\php4\\sapi\\php4isapi.dll[PHP5对应路径为D:\\php\\php5\\php5isapi.dll]。
打开“站点属性”窗口的“主目录”选项卡,找到并点击“配置”按钮
在弹出的“应用程序配置”窗口中的”应用程序映射“选项卡找到并点击“添加”按钮新增一个扩展名映射,在弹出的窗口中单击“浏览”将可执行文件指向 php4isapi.dll 所在路径,如本文中为:D:\\php\\php4\\sapi\\php4isapi.dll[PHP5对应路径为D:\\php\\php5\\php5isapi.dll],扩展名为 .php ,动作限于”GET,HEAD,POST,TRACE“,将“脚本引擎”“确认文件是否存在”选中,然后一路确定即可。如果还想支持诸如 .php3 ,.phtml 等扩展名的 PHP 文件,可以重复“添加”步骤,对应扩展名设置为需要的即可如.PHPX。
此步操作将使你服务器IIS下的所有站点都支持你所添加的PHP扩展文件,当然如果你只需要部分站点支持PHP,只需要在“你需要支持PHP的Web站点”比如“默认Web站点”上单击右键选择“属性”,在打开的“ Web 站点属性”“主目录”选项卡,编辑或者添加PHP的扩展名映射即可或者将你步需要支持PHP的站点中的PHP扩展映射删除即可
再打开“站点属性”窗口的“文档”选项卡,找到并点击“添加”按钮,向默认的 Web 站点启动文档列表中添加 index.php 项。您可以将 index.php 升到最高优先级,这样,访问站点时就会首先自动寻找并打开 index.php 文档。
确定 Web 目录的应用程序设置和执行许可中选择为纯脚本,然后关闭 Internet 信息服务管理器
对于2003系统还需要在“Internet 服务管理器”左边的“WEB服务扩展”中设置ISAPI 扩展允许,Active Server Pages 允许
完成所有操作后,重新启动IIS服务。
在CMD命令提示符中执行如下命令:
net stop w3svc
net stop iisadmin
net start w3svc
到此,PHP的基本安装已经完成,我们已经使网站支持PHP脚本。
检查方法是,在 IIS 根目录下新建一个文本文件存为 php.php ,内容如下:
phpinfo();
?>
打开浏览器,输入:http://localhost/php.php,将显示当前服务器所支持 PHP 的全部信息,可以看到 Server API的模式为:ISAPI 。
或者利用PHP探针检测,到http://depoch.net/download.htm下载后解压到你的站点根目录下并访问即可
第三步:安装MySQL
对于MySQL4.0.26下载得到的是mysql-4.0.26-win32.zip,解压到mysql-4.0.26-win32目录双击执行 Setup.exe 一路Next下一步,选择安装目录为D:\\php\\MySQL和安装方式为Custom自定义安装,再一路Next下一步即可。
安装完毕后,在CMD命令行中输入并运行:
D:\\php\\MySQL\\bin\\mysqld-nt -install
如果返回Service successfully installed.则说明系统服务成功安装
新建一文本文件存为MY.INI,编辑配置MY.INI,这里给出一个参考的配置
[mysqld]
basedir=D:/php/MySQL
#MySQL所在目录
datadir=D:/php/MySQL/data
#MySQL数据库所在目录,可以更改为其他你存放数据库的目录
#language=D:/php/MySQL/share/your language directory
#port=3306
set-variable = max_connections=800
skip-locking
set-variable = key_buffer=512M
set-variable = max_allowed_packet=4M
set-variable = table_cache=1024
set-variable = sort_buffer=2M
set-variable = thread_cache=64
set-variable = join_buffer_size=32M
set-variable = record_buffer=32M
set-variable = thread_concurrency=8
set-variable = myisam_sort_buffer_size=64M
set-variable = connect_timeout=10
set-variable = wait_timeout=10
server-id = 1
[isamchk]
set-variable = key_buffer=128M
set-variable = sort_buffer=128M
set-variable = read_buffer=2M
set-variable = write_buffer=2M
[myisamchk]
set-variable = key_buffer=128M
set-variable = sort_buffer=128M
set-variable = read_buffer=2M
set-variable = write_buffer=2M
[WinMySQLadmin]
Server=D:/php/MySQL/bin/mysqld-nt.exe
保存后复制此MY.INI文件到C:\\Windows ( Windows 2000 下为 C:\\WINNT)目录下
回到CMD命令行中输入并运行:
net start mysql
MySQL 服务正在启动 .
MySQL 服务已经启动成功。
将启动 MySQL 服务;
DOS下修改ROOT密码:当然后面安装PHPMYADMIN后修改密码也可以通过PHPMYADMIN修改
格式:mysqladmin -u用户名 -p旧密码 password 新密码
例:给root加个密码ideacmblog
首先在进入CMD命令行,转到MYSQL目录下的bin目录,然后键入以下命令
mysqladmin -uroot password ideacmblog
注:因为开始时root没有密码,所以-p旧密码一项就可以省略了。
D:\\php\\MySQL\\bin>mysqladmin -uroot password ideacmblog回车后ROOT密码就设置为ideacmblog了
如果你下载的是 MySQL5.x或者MySQL4.1.x,例mysql-5.0.18-win32:解压后双击执行 Setup.exe ,Next下一步后选择Custom自定义安装,再Next下一步选择安装路径这里我们选择D:\\php\\MySQL,继续Next下一步跳过Sign UP完成安装。
安装完成后会提示你是不是立即进行配置,选择是即可进行配置。当然一般安装后菜单里面也有配置向导MySQL Server Instance Config Wizar,运行后按下面步骤配置并设置ROOT密码即可
Next下一步后选择Standard Configuration
Next下一步,钩选Include .. PATH
Next下一步,设置ROOT密码,建议社设置复杂点,确保服务器安全!
Apply完成后将在D:\\php\\MySQL目录下生成MY.INI配置文件,添加并启动MySQL服务
第四步:安装 Zend Optimizer
下载后得到 ZendOptimizer-2.6.2-Windows-i386.exe ,直接双击安装即可,安装过程要你选择 Web Server 时,选择 IIS ,然后提示你是否 Restart Web Server,选择是,完成安装之前提示是否备份 php.ini ,点确定后安装完成。我这里安装到D:\\php\\Zend
以下两步的目录根据你自己的默认WEB站点目录来选,当然也可以选择到D:\\php\\Zend目录
Zend Optimizer 的安装向导会自动根据你的选择来修改 php.ini 帮助你启动这个引擎。下面简单介绍一下 Zend Optimizer 的配置选项。以下为本人安装完成后 php.ini 里的默认配置代码(分号后面的内容为注释):
zend_extension_ts="D:\\php\\Zend\\lib\\ZendExtensionManager.dll"
;Zend Optimizer 模块在硬盘上的安装路径。
zend_extension_manager.optimizer_ts="D:\\php\\Zend\\lib\\Optimizer-2.6.2"
;优化器所在目录,默认无须修改。
zend_optimizer.optimization_level=1023
;优化程度,这里定义启动多少个优化过程,默认值是 15 ,表示同时开启 10 个优化过程中的 1-4 ,我们可以将这个值改为 1023 ,表示开启全部10个优化过程。
调用phpinfo()函数后显示:
Zend Engine v1.3.0, Copyright (c) 1998-2004 Zend Technologies with Zend Extension Manager v1.0.9, Copyright (c) 2003-2006, by Zend Technologies with Zend Optimizer v2.6.2, Copyright (c) 1998-2006, by Zend Technologies 则表示安装成功。
第五步:安装GD库
这一步在前面PHP.INI配置中去掉“;extension=php_gd2.dll”前面的;实际上已经安装好了~
[在php.ini里找到"extension=php_gd2.dll"这一行,并且去掉前面的分号,gd库安装完成,用echophpinfo();测试是否成功! ]
第六步:安装phpMyAdmin
下载得到 phpMyAdmin-2.8.2.zip ,将其解压到D:\\php\\或者 IIS 根目录,改名phpMyAdmin-2.8.2为phpMyAdmin,并在IIS中建立新站点或者虚拟目录指向该目录以便通过WEB地址访问,这里建立默认站点的phpMyAdmin虚拟目录指向D:\\php\\phpMyAdmin目录通过http://localhost/phpmyadmin/访问
找到并打开D:\\php\\phpMyAdmin\\libraries(phpMyAdmin2.7.0和以前的版本在D:\\php\\phpMyAdmin\\目录下)目录下的 config.default.php ,做以下修改:
查找
$cfg[\''PmaAbsoluteUri\'']
设置你的phpmyadmin的WEB访问URL,如本文中:$cfg[\''PmaAbsoluteUri\''] = \''http://localhost/phpmyadmin/\''; 注意这里假设phpmyadmin在默认站点的根目录下
搜索
$cfg[\''blowfish_secret\''] =
设置COOKIES加密密匙,如ideacmblog则设置为$cfg[\''blowfish_secret\''] = \''ideacmblog\'';
搜索$cfg[\''Servers\''][$i][\''auth_type\''],默认为config,是不安全的,不推荐,推荐使用cookie,将其设置为$cfg[\''Servers\''][$i][\''auth_type\''] = \''cookie\'';
注意这里如果设置为config请在下面设置用户名和密码!例如:
$cfg[\''Servers\''][$i][\''user\''] = \''root\''; // MySQL user-----MySQL连接用户
$cfg[\''Servers\''][$i][\''password\''] = \''ideacmblog\'';
搜索$cfg[\''DefaultLang\''] ,将其设置为 zh-gb2312 ;
搜索$cfg[\''DefaultCharset\''] ,将其设置为 gb2312 ;
打开浏览器,输入:http://localhost/phpMyAdmin/ ,若 IIS 和 MySQL 均已启动,输入用户ROOT密码ideacmblog(如没有设置密码则密码留空)即可进入phpMyAdmin数据库管理。
在进http://localhost/phpmyadmin/输入用户名和密码后,如果出现 Client does not support authentication protocol requested by server; consider upgrading MySQL client 错误提示,
这是由于MySQL 4.1 及其后版本验证协议使用的密码哈希算法与老的客户端不兼容,因此需要在MySQL Command Line Client里面用命令同步兼容密码:
进入MySQL Command Line Client后MYSQL的提示符是:mysql>
然后执行:
SET PASSWORD FOR \''root\''@\''localhost\'' = OLD_PASSWORD(\''你的ROOT管理密码\'');
再可以进入phpmyadmin管理,每新建一个用户的时候都要这样执行命令一次,注意把root替换成你新建的用户名和对应的密码。
首先点击权限进入用户管理,删除除ROOT和主机不为localhost的用户并重新读取用户权限表,这里同样可以修改和设置ROOT的密码,添加其他用户等。
phpMyAdmin 的具体功能,请慢慢熟悉,这里就不赘述。
至此所有安装完毕。
第七步:目录结构以及NTFS格式下安全的目录权限设置:
当前目录结构为
D:\\php
|
+?????+??????+???????+???????+
php4(php5) tmp MySQL Zend phpMyAdmin
D:\\php设置为管理员和SYSTEM完全权限即可,其他用户均无权限
对于其下的二级目录
php4(或者php5)、 tmp 给EVERYONE完全权限
MySQL 、Zend 管理员和SYSTEM完全权限
phpMyAdminWEB匿名用户读取运行权限
C# 创建 IIS 站点及相应的应用程序池,支持 IIS6.0+Windows Server 2003. 使用 Builder 设计模式
- 测试项目结构:
PS:IIS6UtilsBuilder, IIS7UtilsBuilder,IISUtilsBuilder 以及 IISDirector 为 Builder 设计模式实现的核心代码。Program 中入口函数则利用反射生成 Builder 实体,具体实现逻辑及详细代码见下:
- 详细代码
CmdUtil.cs
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
namespace SetupIISApp
{
/// <summary>
/// 运行bat文件
/// </summary>
public static class CmdUtils
{
/// <summary>
/// 执行bat文件
/// </summary>
/// <param name="path"></param>
public static void RunBatFile(string filePath)
{
Process proc = null;
try
{
var batFileName = Path.GetFileName(filePath);
var directoryPath = Path.GetDirectoryName(filePath);
string targetDir = string.Format(directoryPath) + "\\";
proc = new Process();
proc.StartInfo.WorkingDirectory = targetDir;
proc.StartInfo.FileName = batFileName;
proc.StartInfo.Arguments = string.Format("10");
proc.StartInfo.CreateNoWindow = true;
proc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;//这里设置DOS窗口不显示,经实践可行
proc.Start();
proc.WaitForExit();
}
catch (Exception ex)
{
throw new Exception(string.Format("Exception Occurred :{0},{1}", ex.Message, ex.StackTrace.ToString()));
}
}
}
}
IISDirector.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace SetupIISApp
{
public class IISDirector
{
/// <summary>
/// 路径
/// </summary>
public string Path { get; set; }
/// <summary>
/// 应用程序名
/// </summary>
public string AppName { get; set; }
public IISDirector()
{
}
public IISDirector(string path,string appName)
{
this.Path = path;
this.AppName = appName;
}
/// <summary>
/// 组装函数
/// </summary>
/// <param name="builder"></param>
public void Construct(IISUtilsBuilder builder)
{
builder.SetIISEnviorment(this.Path);
builder.RegNetFramework_v4_0_30319(this.Path);
builder.Delete(this.AppName);
builder.CreateAppliaction(this.AppName,this.Path);
}
}
}
IISUtilsBuilder.cs
using Microsoft.Win32;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace SetupIISApp
{
public abstract class IISUtilsBuilder
{
/// <summary>
/// IIS版本
/// </summary>
public static Version IISVersion
{
get
{
object obj = Registry.GetValue(@"HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\W3SVC\Parameters", "MajorVersion", "0");
//WebServerTypes ver = WebServerTypes.Unknown;
System.Version ver = new Version();
int major = 0;
int minor = 0;
if (obj != null)
{
major = Convert.ToInt32(obj);
}
obj = Registry.GetValue(@"HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\W3SVC\Parameters", "MinorVersion", "0");
if (obj != null)
{
minor = Convert.ToInt32(obj);
}
return new Version(major, minor);
}
}
/// <summary>
/// 配置IIS windows Server 2003 IIS6.0环境
/// </summary>
/// <param name="path"></param>
public abstract void SetIISEnviorment(string path);
/// <summary>
/// 非windows server2003操作系统且IIS版本为6.xs时注册NetFramework_v4_0_30319
/// </summary>
public abstract void RegNetFramework_v4_0_30319(string path);
/// <summary>
/// 创建应用程序
/// </summary>
/// <param name="appName"></param>
/// <param name="path"></param>
public abstract void CreateAppliaction(string appName, string path);
/// <summary>
/// 删除应用程序
/// </summary>
/// <param name="name">应用程序名称</param>
/// <returns></returns>
public abstract bool Delete(string name);
}
}
IIS6UtilsBuilder.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.DirectoryServices;
namespace SetupIISApp
{
public class IIS6UtilsBuilder : IISUtilsBuilder
{
public override void SetIISEnviorment(string path)
{
//设置IIS
var frameWork4Path = "";
if (Environment.Is64BitOperatingSystem) // 调用命令更新应用程序池属性
{
frameWork4Path = FileUtils.GetWindowsDirectory() + @"\Microsoft.NET\Framework64\v4.0.30319";
}
else
{
frameWork4Path = FileUtils.GetWindowsDirectory() + @"\Microsoft.NET\Framework\v4.0.30319";
}
var sb = new StringBuilder();
sb.Append("cd " + FileUtils.GetWindowsDirectory() + @"\system32" + Environment.NewLine);
sb.Append(FileUtils.GetWindowsDirectory() + @"\system32\wscript.exe /h:cscript //B" + Environment.NewLine);
sb.Append("cmd.exe /c " + frameWork4Path + @"\aspnet_regiis.exe -i" + Environment.NewLine);
sb.Append(@"cd " + frameWork4Path + Environment.NewLine);
sb.Append("aspnet_regiis.exe -norestart -s W3SVC/1/ROOT" + Environment.NewLine);
sb.Append("cd " + FileUtils.GetWindowsDirectory() + @"\system32" + Environment.NewLine);
sb.Append("cmd.exe /c " + FileUtils.GetWindowsDirectory() + "\\system32\\iisext.vbs /EnApp \"ASP.NET v4.0.30319\"");
string fileContent = sb.ToString();
//生成bat文件
FileUtils.WriteBatFile(path + @"\IISSet.bat", fileContent);
//运行bat文件
CmdUtils.RunBatFile(path + @"\IISSet.bat");
//删除bat文件
FileUtils.DeleteFile(path + @"\IISSet.bat");
}
/// <summary>
///非windows server 2003操作系统时 IIS6.0 时注册NetFramework_v4_0_30319
/// </summary>
public override void RegNetFramework_v4_0_30319(string path)
{
var frameWork4Path = "";
if (Environment.Is64BitOperatingSystem) // 调用命令更新应用程序池属性
{
frameWork4Path = FileUtils.GetWindowsDirectory() + @"\Microsoft.NET\Framework64\v4.0.30319";
}
else
{
frameWork4Path = FileUtils.GetWindowsDirectory() + @"\Microsoft.NET\Framework\v4.0.30319";
}
var sb = new StringBuilder();
sb.Append("cmd.exe /c " + frameWork4Path + @"\aspnet_regiis.exe -i" + Environment.NewLine);
string fileContent = sb.ToString();
//生成bat文件
FileUtils.WriteBatFile(path + @"\NetReg.bat", fileContent);
//运行bat文件
CmdUtils.RunBatFile(path + @"\NetReg.bat");
//删除bat文件
FileUtils.DeleteFile(path + @"\NetReg.bat");
}
public override void CreateAppliaction(string appName, string path)
{
bool isWindowsServer2003 = Environment.OSVersion.Version.Major == 5 && Environment.OSVersion.Version.Minor == 2;
////创建应用程序池
DirectoryEntry appPoolRoot = new DirectoryEntry(@"IIS://localhost/W3SVC/AppPools");
var createAppPool = true;
foreach (DirectoryEntry e in appPoolRoot.Children)
{
if (e.Name == appName)
{
createAppPool = false;
}
}
if (createAppPool)
{
DirectoryEntry newAppPool = appPoolRoot.Children.Add(appName, "IIsApplicationPool");
newAppPool.Properties["AppPoolQueueLength"][0] = "65535";
//禁用回收 回收>>>固定时间间隔
newAppPool.Properties["PeriodicRestartTime"][0] = "0";
//闲置超时
newAppPool.Properties["IdleTimeout"][0] = "0";
newAppPool.Properties["AppPoolIdentityType"][0] = "2";
if (!isWindowsServer2003)//windows server2003
{
newAppPool.Properties["ManagedRuntimeVersion"][0] = "v4.0";//Net版本号//windows server2003不支持
newAppPool.Properties["ManagedPipelineMode"][0] = "0";//0:集成模式 1:经典模式windows server2003不支持
newAppPool.Properties["Enable32BitAppOnWin64"][0] = true; //windows server2003不支持
newAppPool.CommitChanges();
}
else
{
newAppPool.CommitChanges();
}
}
//default website所在路径
DirectoryEntry de = new DirectoryEntry("IIS://localhost/W3SVC/1/Root");
de.RefreshCache();
foreach (DirectoryEntry e in de.Children)
{
if (e.Name == appName)
{
//删除已有应用程序
de.Children.Remove(e);
}
}
DirectoryEntry myde = de.Children.Add(appName, "IIsWebVirtualDir");
myde.Properties["Path"].Insert(0, path);//插入到IIS
myde.Invoke("AppCreate", true);//创建
myde.Properties["AppPoolId"][0] = appName;
myde.Properties["AuthAnonymous"][0] = true;//允许匿名访问
myde.Properties["AccessRead"][0] = true; //开启读取
myde.Properties["AccessScript"][0] = true;//脚本可执行
//设置是否禁用日志 默认为false。
myde.Properties["DontLog"][0] = true;
myde.CommitChanges();//保存更改
de.CommitChanges();
de.Close();
myde.Close();
myde.Dispose();
de.Dispose();
}
public override bool Delete(string name)
{
bool isOk = false;
try
{
using (DirectoryEntry defaultSite = new DirectoryEntry("IIS://localhost/W3SVC/1/ROOT"))
{
foreach (DirectoryEntry dir in defaultSite.Children)
{
if (dir.Name == name && dir.SchemaClassName == "IIsWebVirtualDir")
{
defaultSite.Children.Remove(dir);
isOk = true;
break;
}
}
defaultSite.CommitChanges();
}
AppPoolDelete(name);
}
catch
{
}
return isOk;
}
/// <summary>
/// 删除应用程序池
/// </summary>
/// <param name="name">应用程序池名称</param>
/// <returns>成功返回 true,否则返回 false</returns>
private bool AppPoolDelete(string name)
{
bool isOk = false;
DirectoryEntry pool = AppPoolOpen(name);
if (pool != null)
{
pool.DeleteTree();
isOk = true;
}
return isOk;
}
/// <summary>
/// 返回应用程序池实例
/// </summary>
/// <param name="name">应用程序池名称</param>
/// <returns>应用程序池实例</returns>
private DirectoryEntry AppPoolOpen(string name)
{
using (DirectoryEntry pools = new DirectoryEntry("IIS://localhost/W3SVC/AppPools"))
{
foreach (DirectoryEntry entry in pools.Children)
{
if (entry.SchemaClassName == "IIsApplicationPool" && entry.Name.Equals(name, StringComparison.CurrentCultureIgnoreCase))
{
return entry;
}
}
return null;
}
}
}
}
IIS7UtilsBuilder.cs
using Microsoft.Web.Administration;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace SetupIISApp
{
public class IIS7UtilsBuilder : IISUtilsBuilder
{
public override void SetIISEnviorment(string path)
{
}
public override void RegNetFramework_v4_0_30319(string path)
{
}
public override void CreateAppliaction(string appName, string path)
{
try
{
if (!AppPoolExists(appName))
{
AppPoolCreate(appName);
}
using (ServerManager sm = new ServerManager())
{
// sm.Sites.Add("test", @"D:\DataBackup", 9898);//添加新站点
Site site = sm.Sites["Default Web Site"];
if (site != null)
{
site.LogFile.Enabled = false;
Application app = site.Applications["/" + appName];
if (app == null)
{
app = site.Applications.Add("/" + appName, path);
app.ApplicationPoolName = appName;
}
sm.CommitChanges();
}
}
}
catch (Exception ex)
{
throw ex;
}
}
public override bool Delete(string name)
{
bool isOk = false;
try
{
using (ServerManager sm = new ServerManager())
{
Site site = sm.Sites["Default Web Site"];
if (site != null)
{
site.LogFile.Enabled = true;
Application app = site.Applications["/" + name];
if (app != null)
{
site.Applications.Remove(app);
}
sm.CommitChanges();
}
}
AppPoolDelete(name);
isOk = true;
}
catch (Exception ex)
{
throw ex;
}
return isOk;
}
/// <summary>
/// 删除应用程序池
/// </summary>
/// <param name="name">应用程序池名称</param>
/// <returns>成功返回 true,否则返回 false</returns>
private void AppPoolDelete(string name)
{
using (ServerManager sm = new ServerManager())
{
ApplicationPool pool = sm.ApplicationPools[name];
if (pool != null)
{
sm.ApplicationPools.Remove(sm.ApplicationPools[name]);
sm.CommitChanges();
}
}
}
/// <summary>
/// 创建应用程序池
/// </summary>
/// <param name="name">要创建应用程序池的名称</param>
/// <returns>如果创建成功返回 IIS7AppPool,否则返回 null</returns>
private void AppPoolCreate(string name)
{
using (ServerManager sm = new ServerManager())
{
ApplicationPool pool = sm.ApplicationPools[name];
if (pool == null)
{
pool = sm.ApplicationPools.Add(name);
pool.ManagedPipelineMode = ManagedPipelineMode.Integrated;/*集成*/
//pool.ProcessModel.IdentityType = ProcessModelIdentityType.ApplicationPoolIdentity;
pool.ProcessModel.IdentityType = ProcessModelIdentityType.NetworkService;
pool.Enable32BitAppOnWin64 = true;
pool.ManagedRuntimeVersion = "v4.0";
pool.Failure.RapidFailProtection = true;
pool.QueueLength = 65535;
//禁用回收 回收>>>固定时间间隔
pool.Recycling.PeriodicRestart.Time = new TimeSpan(0);
//闲置超时
pool.ProcessModel.IdleTimeout = new TimeSpan(0);
sm.CommitChanges();
}
}
}
/// <summary>
/// 应用程序池是否存在
/// </summary>
/// <param name="name">应用程序池名称</param>
/// <returns>存在则返回 true,否则返回 false</returns>
private bool AppPoolExists(string name)
{
using (ServerManager sm = new ServerManager())
{
return sm.ApplicationPools[name] != null;
}
}
}
}
FileUtils.cs
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
namespace SetupIISApp
{
public static class FileUtils
{
[DllImport("kernel32")]
private static extern void GetWindowsDirectory(StringBuilder WinDir, int count);
/// <summary>
/// 获取windows 目录文件
/// </summary>
/// <param name="count">128</param>
/// <returns></returns>
public static string GetWindowsDirectory()
{
int count = 128;
StringBuilder sb = new StringBuilder();
GetWindowsDirectory(sb, count);
return sb.ToString();
}
/// <summary>
/// 生成bat文件
/// </summary>
/// <param name="batFilePath"></param>
/// <param name="fileContent"></param>
public static void WriteBatFile(string batFilePath, string fileContent)
{
//生成bat文件
if (!File.Exists(batFilePath))
{
FileStream fs1 = new FileStream(batFilePath, FileMode.Create, FileAccess.Write);//创建写入文件
StreamWriter sw = new StreamWriter(fs1);
sw.WriteLine(fileContent);//开始写入值
sw.Close();
fs1.Close();
}
else//更新bat文件
{
FileStream fs = new FileStream(batFilePath, FileMode.Open, FileAccess.Write);
StreamWriter sr = new StreamWriter(fs);
sr.WriteLine(fileContent);//开始写入值
sr.Close();
fs.Close();
}
}
/// 删除某文件
/// </summary>
/// <param name="srcPath">目标路径</param>
public static void DeleteFile(string srcPath)
{
try
{
//删除文件
if (File.Exists(srcPath))
{
var fileInfo = new FileInfo(srcPath);
fileInfo.Attributes = FileAttributes.Normal;
fileInfo.Delete();
}
}
catch
{
}
}
}
}
Program.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
namespace SetupIISApp
{
class Program
{
static void Main(string[] args)
{
string builderStr = "";
bool isWindowsServer2003 = Environment.OSVersion.Version.Major == 5 && Environment.OSVersion.Version.Minor == 2;
if (isWindowsServer2003)
{
builderStr = "IIS6UtilsBuilder";
}
else
{
if (IISUtilsBuilder.IISVersion.Major < 7)
{
builderStr = "IIS6UtilsBuilder";
}
else
{
builderStr = "IIS7UtilsBuilder";
}
}
string path = @"D:\发布\TestWeb";
string name = @"SetIISTest";
var director = new IISDirector(path, name);
//反射生成builder实体
var builder = (IISUtilsBuilder)Assembly.Load("SetupIISApp").CreateInstance("SetupIISApp." + builderStr);
director.Construct(builder);
}
}
}
- 运行结果
以上为本片博文的全部内容,在 IIS6.0 环境中创建站点还暂未包括在本项目中,都以应用程序的模式挂载在默认 [default web site] 站点下。
此博文为原创,转载请注明出处!!!!!
PHP 在Windows 2003 Enterprise Server 、IIS6.0 下的安装
PHP 在Windows 2003 Enterprise Server 、IIS6.0 下的安装_PHP
IIS6IIS
有朋友反映在win2000中iis和php工作好好的, 在win2003 enterprise server中,按照2000下的做法php不工作。其实在windows2003下安装也是很简单的,只不过win2003在iis6.0的安全方面下了些功夫,所以安装起来要稍费点功夫了。
步骤1,先去www.php.net下在一个安装程序,我是装的是:php-4.2.3-installer.exe,你也可以去找最新的版本,在安装php-4.2.3-installer.exe之前保证你的IIS6.0启动了,并能够访问。
图1:安装好以后,在默认网站-->应用程序配置
步骤二:点击 web服务扩展 -->新建web服务扩展.
步骤三: 扩展名-->php,然后添加
步骤四:找到php.exe的路径添加上去。
立即学习“PHP免费学习笔记(深入)”;
步骤五: 确定就可以了!
步骤六: 选择php的服务扩展,然后点击允许。
步骤七: 好了,在IE里面来phpinfo();就可以完成了!
PHP 在Windows 2003 Enterprise Server 、IIS6.0 下的安装_PHP教程
有朋友反映在win2000中iis(微软的WEB服务器平台)和php(做为现在的主流开发语言)工作好好的, 在win2003 enterprise server中,按照2000下的做法php(做为现在的主流开发语言)不工作。其实在Windows2003下安装也是很简单的,只不过Win2003在iis(微软的WEB服务器平台)6.0的安全方面下了些功夫,所以安装起来要稍费点功夫了。
步骤1,先去www.php(做为现在的主流开发语言).net下在一个安装程序,我是装的是:php(做为现在的主流开发语言)-4.2.3-installer.exe,你也可以去找最新的版本,在安装php(做为现在的主流开发语言)-4.2.3-installer.exe之前保证你的iis(微软的WEB服务器平台)6.0启动了,并能够访问。
图1:安装好以后,在默认网站-->应用程序配置
步骤二:点击 web服务扩展 -->新建web服务扩展.
步骤三: 扩展名-->php(做为现在的主流开发语言),然后添加
步骤四:找到php(做为现在的主流开发语言).exe的路径添加上去。
步骤五: 确定就可以了!
步骤六: 选择php(做为现在的主流开发语言)的服务扩展,然后点击允许。
步骤七: 好了,在IE里面来php(做为现在的主流开发语言)info();就可以完成了!
今天关于Windows Server 2003 IIS6 PHP Configurations的介绍到此结束,谢谢您的阅读,有关C# 创建 IIS 站点及相应的应用程序池,支持 IIS6.0+Windows Server 2003. 使用 Builder 设计模式、PHP 在Windows 2003 Enterprise Server 、IIS6.0 下的安装、PHP 在Windows 2003 Enterprise Server 、IIS6.0 下的安装_PHP、PHP 在Windows 2003 Enterprise Server 、IIS6.0 下的安装_PHP教程等更多相关知识的信息可以在本站进行查询。
本文标签: