'/*=========================================================================
' * Intro PHP安装脚本,您所要做的操作是:保存这个文件与要安装的php文件夹放一起(不要放在C盘根目录下)
' * (当前版本php-5.2.5-Win32如果是其它请替换当前文档相关文件名),然后双击运行这个文件,<?phpinfo()?>
' * FileName PHPFirstInstall.vbs
' * Author yongfa365
' * Version v2.0
' * WEB http://www.yongfa365.com
' * Email yongfa365[at]qq.com
' * FirstWrite http://www.yongfa365.com/Item/PHPFirstInstall.vbs.html
' * MadeTime 2008-04-01 15:55:41
' * LastModify 2008-05-28 20:20:20
' *==========================================================================*/
Wscript.Echo "开始配置PHP"
phpinstall "php-5.2.5-Win32", "C:\PHP", "C:"
'phpinstall "php所在目录","php要安装到哪","系统盘(如:C:)"
Function phpinstall(PHPFilePath, InstallPath, SystemPath)
On Error Resume Next
Set FSO = CreateObject("Scripting.FileSystemObject")
'添加环境变量,本来是想把PHP目录加到环境变量Path里,这样就不用复制文件了,试了下不成功,故注释掉
'const HKEY_LOCAL_MACHINE = &H80000002
'Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\default:StdRegProv")
'strKeyPath = "SYSTEM\CurrentControlSet\Control\Session Manager\Environment"
'strValueName = "Path"
'oReg.GetExpandedStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue
'strValue=strValue & ";" & InstallPath
'oReg.SetExpandedStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue
'WScript.Echo "删除C:\PHP"
FSO.DeleteFolder InstallPath
FSO.CopyFolder PHPFilePath, InstallPath '第一个参数为您要安装的php文件夹名,他的下一级是一堆文件及文件夹,而不是只有一个文件夹
'WScript.Echo "删除C:\Windows\system32\php5ts.dll及C:\Windows\system32\libmysql.dll,然后复制新的"
FSO.DeleteFile SystemPath & "\Windows\system32\php5ts.dll"
FSO.CopyFile InstallPath & "\php5ts.dll", SystemPath & "\Windows\system32\php5ts.dll"
FSO.DeleteFile SystemPath & "\Windows\system32\libmysql.dll"
FSO.CopyFile InstallPath & "\libmysql.dll", SystemPath & "\Windows\system32\libmysql.dll"
'MCrypt加密处理
FSO.DeleteFile SystemPath & "\Windows\system32\libmcrypt.dll"
FSO.CopyFile InstallPath & "\libmcrypt.dll", SystemPath & "\Windows\system32\libmcrypt.dll"
'WScript.Echo "读取C:\php\php.ini-dist内容到变量PHPStr"
PHPStr = FSO.OpenTextFile(InstallPath & "\php.ini-dist", 1, True).ReadAll
'WScript.Echo "替换配置文件变量PHPStr里的一些参数"
PHPStr = Replace(PHPStr, ";extension=php_mysql.dll", "extension=php_mysql.dll")
PHPStr = Replace(PHPStr, ";extension=php_gd2.dll", "extension=php_gd2.dll")
PHPStr = Replace(PHPStr, ";extension=php_mbstring.dll", "extension=php_mbstring.dll")
'PHPStr = Replace(PHPStr, ";extension=php_dbase.dll", "extension=php_dbase.dll")
'PHPStr = Replace(PHPStr, ";extension=php_ldap.dll", "extension=php_ldap.dll")
'PHPStr = Replace(PHPStr, ";extension=php_mssql.dll", "extension=php_mssql.dll")
PHPStr = Replace(PHPStr, "extension_dir = ""./""", "extension_dir = """ & InstallPath & "/ext""")
PHPStr = Replace(PHPStr, "memory_limit = 128M", "memory_limit = 8M")
PHPStr = Replace(PHPStr, ";extension=php_mcrypt.dll", "extension=php_mcrypt.dll")
PHPStr = Replace(PHPStr, ";session.save_path = ""/tmp""", "session.save_path = """ & SystemPath & "\Windows\Temp""")
PHPStr = Replace(PHPStr, "register_globals = Off", "register_globals = On")
PHPStr = Replace(PHPStr, "allow_url_include = Off", "allow_url_include = On")
'WScript.Echo "将修改后的配置文件变量PHPStr另存为:C:\Windows\php.ini"
FSO.CreateTextFile(SystemPath & "\Windows\php.ini", True).WriteLine PHPStr
Set IIsWebServiceObj = GetObject("IIS://localhost/W3SVC")
'WScript.Echo "添加web服务扩展(打开IIS6-->web 服务扩展-->右击空白,添加)"
''WebSvcExtRestrictionList,
IISWebServiceObj.AddExtensionFile InstallPath & "\php5isapi.dll", True, "php", True, "php"
IIsWebServiceObj.SetInfo
'WScript.Echo "添加应用程序扩展名映射(网站属性-->主目录-->配置-->映射-->添加)"
''ScriptMaps
ArgScriptMap = ".php," & InstallPath & "\php5isapi.dll,5,GET,HEAD,POST,DEBUG"
NewScriptMaps = IIsWebServiceObj.ScriptMaps
ReDim preserve NewScriptMaps(UBound(NewScriptMaps) + 1)
NewScriptMaps(UBound(NewScriptMaps)) = ArgScriptMap
IIsWebServiceObj.ScriptMaps = NewScriptMaps
IIsWebServiceObj.SetInfo
WScript.Echo "OK,php环境安装完成,为了对本程序作者:柳永法,表示感谢,请 大笑三声^_^"
End Function
引用本页地址:
http://www.yongfa365.com/item/PHPFirstInstall.vbs.html