SlideShare une entreprise Scribd logo
1  sur  12
Télécharger pour lire hors ligne
PHP on Windows®




Demonstration PHP on IIS 7.0
PHP on Windows – Demonstration

                                                        目录
Demonstration – 在 IIS 7.0 中部署 PHP 站点................................................................ 1
  PHP 站点部署 概述 ..................................................................................................... 1
  PHP 站点部署 环境搭建 .............................................................................................. 1
  PHP 站点部署 综述 ..................................................................................................... 1
  PHP 站点部署 Step 1: 在 IIS 7.0 上安装 PHP 支持软件 .............................................. 1
  PHP 站点部署 Step 2 : 下载并安装 PHP 框架 ............................................................. 2
  PHP 站点部署 Step 3: 使用 FastCGI,关联 IIS 和 PHP 应用程序 ............................... 3
  PHP 站点部署 Step 4: 搭建 PHP 应用程序 ................................................................. 4
  PHP 站点部署 Step 5: 使用 URL Rewrite 实现 URl 重写 ............................................. 4
Demonstration – 在 IIS 7.0 中开发和管理 PHP 站点 ..................................................... 7
  PHP 站点开发管理 概述 .............................................................................................. 7
  PHP 站点开发管理 环境搭建 ....................................................................................... 7
  PHP 站点开发管理 综述 .............................................................................................. 8
  PHP 站点开发管理 Step1: IIS 管理工具和配置模块委托机制 ...................................... 8
  PHP 站点开发管理 Step2: 自定义错误信息提示页 ...................................................... 8
  PHP 站点开发管理 Step3: 身份验证 ........................................................................... 9
  PHP 站点开发管理 Step4: 结语................................................................................. 10




                                                    2
PHP on Windows – Demonstration




Demonstration – 在 IIS 7.0 中部署 PHP 站点
PHP 站点部署                  概述
此实例用以展示如何在 IIS7.0 平台上部署、管理和扩展 PHP 站点.
本实例要达到的目的:
   了解 IIS FastCGI 为 PHP 站点的发布提供了稳定的平台支持
   了解在 IIS7.0 上可以很容易的发布 PHP 站点
   IS7.0 对 PHP 的兼容性


PHP 站点部署                  环境搭建
     1. 需要的系统环境为 Windows Server® 2008 或 Windows Vista® SP1(安装 SP1 补丁)。
        针对这两种操作系统版本,差异仅存在于步骤 1( FastCGI 的配置),其他的步骤均相同。
     2. IIS7.0 初始配置状态,假定为系统安装后的默认状态。
     3. 下载并安装 MySQL
        a. 请通过 www.mysql.com 下载 community 版
        b. 在安装过程中,请选择 default configuration,并确认选择 run as a service,
            默认密码请选择 demo1。
     4. 下载第三方应用程序 mediawiki:
         a. http://www.mediawiki.org/wiki/Download..
     5. 下载并安装 IIS 外置模块组件,URL Rewrite:
        a. http://www.iis.net/downloads/default.aspx?tabid=34&g=6&i=1691
     6. 为 IIS 开放权限:
        a. Internet ,找到 Management 下的 Feature Delegation 模块
        b. 选择 URL Rewrite,将其置为 Read/Write


PHP 站点部署                  综述
    1.   在 IIS 7.0 上安装 PHP 支持
    2.   下载并安装 PHP 框架
    3.   通过 FastCGI 将 IIS 7.0 与 PHP 进行关联
    4.   下载并安装第三方的应用程序 MediaWiki
    5.   配置 URL Rewrite,开启相应权限




PHP 站点部署                  Step 1: 在 IIS 7.0 上安装 PHP 支持软件
    1. 安装 FastCGI.
       a. 如果用户的系统为 Windows Server 2008:
          i. 打开 Server Manager.
          ii. 选择 Web Server (IIS) role.
          iii. 右键点击 Web Server (IIS) role,选择 Add Role Services.


                                      1
PHP on Windows – Demonstration


           iv. 在 Application Development 节点中找到 CGI 服务.
           v. 点击 Next -----Install 进行服务的安装.
        b. 如果用户的系统为 Windows Vista SP1:
           i. 进入 Control Panel 并选择 Programs and Features.
           ii. 选择左侧选项中的 Turn Windows Features on or off.
           iii. 在 Internet Information ServicesWorld Wide Web services 下选择
                Application Development Features 模块.
           iv. 选择 CGI.
           v. 点击 OK.




PHP 站点部署                  Step 2 : 下载并安装 PHP 框架
    1. 从 www.php.net/downloads 现在 PHP 框架.
       a. 请选择 Non-thread-safe 的压缩安装包, 本实例将使用 PHP 5.2.6 Non-thread-safe 版的压
          缩包 (http://www.php.net/get/php-5.2.6-nts-Win32.zip/from/a/mirror).
    2. 将压缩包解压到本地,路径例如 C:php.
    3. 如果对以下的操作有疑问, 可访问 http://learn.iis.net/page.aspx/246/using-fastcgi-to-host-php-
       applications-on-iis-70/ 获得更多的支持.
    4. 将文件夹中的 php.ini-recommanded 文件更名成 php.ini


                                       2
PHP on Windows – Demonstration


    5. 打开 php.ini, 按照以下的步骤进行修改(更改的 3 个环境变量是针对本实例):
        a. 将 cgi.fix_pathinfo 置为 1, 即 cgi.fix_pathinfo = 1
        b. 将 cgi.force_redirect 置为 0,即 cgi.force_redirect = 0
        c. 注释掉 error_log = syslog(如果此项在文件中不存在,则步骤 c 可跳过)
     6. 通过命令行测试 PHP 是否安装成功
        C:PHP>php -info


PHP 站点部署                  Step 3: 使用 FastCGI,关联 IIS 和 PHP 应用程序
   1. 打开 Internet Information Services (IIS) Manager (inetmgr.exe).
   2. 在左侧选择本地服务器.
   3. 选择服务模块 Handler mappings ,双击打开。
   4. 在最右侧的列表中点击选择 Add Module Mapping
   5. 在弹出的窗体中填入下列信息,并单击 OK.
      a. Request Path 中填入 *.php
      b. Module 中填入 FastCgiModule
      c. Executable 中填入 C:php php-cgi.exe.(请按照具体解压的路径进行选择)
      d. Name 中填入 PHP via FastCGI (任意名称均可)
   6. 点击 OK.




                                      3
PHP on Windows – Demonstration


PHP 站点部署                  Step 4: 搭建 PHP 应用程序
   1. 将 MediaWiki 解压到本地,路径 C:inetpubwwwrootmediawiki,请保证压缩包中所有
      的文件均处于这个路径下,而不是被解压到此路径下的子文件夹。
   2. 为 MediaWiki 文件夹添加 IIS_IUSRS 用户,并为 IIS_IUSRS 用户加入 Modify, Write, Read
      权限

   3. 在 InetMgr 的 Default Web Site 下找到 mediawiki 目录,右击选择 Convert to
       Application.

   4. 通过命令行在 c:php 根目录下添加两个文件夹,分别为 session 和 upload ,并进行授权:
      cd /d C:php
      md session
      md upload
      icacls session /grant BUILTINIIS_IUSRS:(OI)(CI)(M)
      icacls upload /grant BUILTINIIS_IUSRS:(OI)(CI)(M)

       在 php.ini 文件中添加如下信息:
       upload_tmp_dir = quot;c:phpuploadquot;
       session.save_path = quot;c:phpsessionquot;

       在 php.ini 文件中添加(开放)环境变量以支持 MySql
        extension_dir = quot;C:phpextquot;
        extension = php_mysql.dll


   5. 在 InetMgr 中选择 Directory Browsing,双击打开,如果选项被灰化,且右侧的
      Disable 选项处于选中状态,则请将其置为 Enable.

   6. 搭建 mediawiki 站点:
      a. 浏览 http://localhost/mediawiki/config/index.php,如果页面无法打开确认
         步骤 5,并确认 mediawiki 虚拟目录的位置是否正确,是否设置了所需的权限。
      b. 在 Wiki name 中输入 My MediaWiki(任意名称均可)
      c. 为 Admin user 用户确认密码 demo1
      d. 为 wikiuser 用户确认密码 demo1
      e. User superuser 用户的检验框请勾选,为 root 添加 MySql 的密码,本实例中在安
         装 MySql 时,将密码设为 demo1
      f. 点击 Install MediaWiki!
 拷贝configLocalSettings.php 文件到根目录(实例中为
c:wwwwroorinetpubmediawiki)




PHP 站点部署                  Step 5: 使用 URL Rewrite 实现 URl 重写
   1. 前期准备


                                              4
PHP on Windows – Demonstration


       确认 URL Rewite 组件已经被正确安装,并按照 step1 完成了环境变量的修改。

   2. 为 PHP 站点设置起始页
      当前状态下(未进行 URL 重写配置),我们通过 http://localhost/mediawiki 将无法访问到
      页面,系统提示错误。
      a. 打开 IIS Manager.
      b. 在 Default Web Site 下找到 mediawiki 目录.
      c. 选择 Default document 模块.
      d. 右键选择 Add,并输入 index.php. 点击 OK.
      e. 再次访问 http://localhost/mediawiki ,系统将定位访问到 index.php.

   3. 为 PHP 站点 URL 重写规则
      在 mediawiki 的根目录下找到 LocalSetting.php 文件,并按照文档进行改写:

       ## The URL base path to the directory containing the wiki;
       ## defaults for all runtime URL paths are based off of this.
       ## For more information on customizing the URLs please see:
       ## http://www.mediawiki.org/wiki/Manual:Short_URL
       $wgScriptPath        = quot;/mediawikiquot;;
       $wgScriptExtension = quot;.phpquot;;
       $wgArticlePath = quot;${wgScriptPath}/$1quot;;

       a.   打开 IIS Manager.
       b.   点击选择 mediawiki .
       c.   选择 URL Rewrite 模块,双击打开.
       d.   选择 Import rules
       e.   在弹出的窗口内输入以下 URL 重写规则
             <<
             # BEGIN Wiki
             # Don't rewrite requests for files in MediaWiki subdirectories,
             # MediaWiki PHP files, HTTP error documents, favicon.ico, or robots.txt
             RewriteCond %{REQUEST_URI} !^/mediawiki/stylesheets/
             RewriteCond %{REQUEST_URI} !^/mediawiki/skins/
             RewriteCond %{REQUEST_URI} !^/mediawiki/(redirect|texvc|index).php
             RewriteCond %{REQUEST_URI} !^/mediawiki/sitemap.xml.php
             RewriteCond %{REQUEST_URI} !^/mediawiki/error/(40(1|3|4)|500).html
             RewriteCond %{REQUEST_URI} !^/mediawiki/favicon.ico
             RewriteCond %{REQUEST_URI} !^/mediawiki/robots.txt
             RewriteCond %{REQUEST_URI} !^/mediawiki/(.*).w+$

             # Make sure there is no query string
             RewriteCond %{QUERY_STRING} ^$

            # Rewrite http:/.domain.tld/article properly, this is the main rule
            RewriteRule ^/?(.*)$ /mediawiki/index.php?title=$1 [L,QSA]
            # END Wiki
            >>
       f. 点击 Apply,应用以上规则。
       g. 打开 http://localhost/mediawiki/main_Page,系统将自动将访问请求转到
          http://locahost/mediawiki/index.php?title=Main_Page .


                                               5
PHP on Windows – Demonstration


   4. 打开 web.config 文件,可以看到之前的配置在文件中均有体现.

       <?xml version=quot;1.0quot; encoding=quot;UTF-8quot;?>
       <configuration>
           <system.webServer>
             <defaultDocument>
                 <files>
                     <add value=quot;index.phpquot; />
                 </files>
             </defaultDocument>
             <rewrite>
               <rules>
                 <rule name=quot;Imported Rule 1quot; stopProcessing=quot;truequot;>
                   <match url=quot;^(.*)$quot; ignoreCase=quot;falsequot; />
                   <conditions logicalGrouping=quot;MatchAllquot;>
                     <add input=quot;{REQUEST_URI}quot; negate=quot;truequot;
             pattern=quot;^/mediawiki/stylesheets/quot; ignoreCase=quot;falsequot; />
                     <add input=quot;{REQUEST_URI}quot; negate=quot;truequot;
             pattern=quot;^/mediawiki/skins/quot; ignoreCase=quot;falsequot; />
                     <add input=quot;{REQUEST_URI}quot; negate=quot;truequot;
             pattern=quot;^/mediawiki/(redirect|texvc|index).phpquot;
             ignoreCase=quot;falsequot; />
                     <add input=quot;{REQUEST_URI}quot; negate=quot;truequot;
             pattern=quot;^/mediawiki/sitemap.xml.phpquot; ignoreCase=quot;falsequot; />
                     <add input=quot;{REQUEST_URI}quot; negate=quot;truequot;
             pattern=quot;^/mediawiki/error/(40(1|3|4)|500).htmlquot;
             ignoreCase=quot;falsequot; />
                     <add input=quot;{REQUEST_URI}quot; negate=quot;truequot;
             pattern=quot;^/mediawiki/favicon.icoquot; ignoreCase=quot;falsequot; />
                     <add input=quot;{REQUEST_URI}quot; negate=quot;truequot;
             pattern=quot;^/mediawiki/robots.txtquot; ignoreCase=quot;falsequot; />
                     <add input=quot;{REQUEST_URI}quot; negate=quot;truequot;
             pattern=quot;^/mediawiki/(.*).w+$quot; ignoreCase=quot;falsequot; />
                     <add input=quot;{QUERY_STRING}quot; negate=quot;truequot;
             pattern=quot;^?$quot; ignoreCase=quot;falsequot; />
                   </conditions>
                   <action type=quot;Rewritequot;
             url=quot;/mediawiki/index.php?title={R:1}quot; appendQueryString=quot;truequot;
             />
                 </rule>
               </rules>
             </rewrite>
           </system.webServer>
       </configuration>




                                   6
PHP on Windows – Demonstration



Demonstration – 在 IIS 7.0 中开发和管理 PHP 站点
PHP 站点开发管理                       概述
本实例基于上个实例,确保上个实例已被正确完成。
本实例用于展示 IIS7.0 平台上 PHP 应用程序的发布、管理和扩展,以及 IIS7.0 平台对 PHP 应用程序
的有力支持。


PHP 站点开发管理                       环境搭建
    1. 需要的系统环境为 Windows Server® 2008 或 Windows Vista® SP1 (SP1 required).
    2. 需要完成上一个实例
    3. 在 IIS 中安装 URL Authorization.
             a. Windows Server 2008: 通过 Server ManagerRolesWeb Server (IIS) Role
                安装 Web ServerSecurityURL Authorization 服务模块.
             b. Windows Vista SP1: 通过 Control PanelPrograms and FeaturesTurn
                Windows Features on or off 安装 Internet Information ServicesWorld
                Wide Web servicesSecurityURL Authorization 服务模块.
    4. 安装 Microsoft® .NET Framework 3.5 和 Microsoft® .NET Framework 3.5 SP1:
       http://www.microsoft.com/downloadS/details.aspx?familyid=AB99342F-5D1A-
       413D-8319-81DA479AB0D7&displaylang=en.
    5. 安装 Windows Installer 4.5:
       http://www.microsoft.com/downloads/info.aspx?na=47&p=4&SrcDisplayLang=en
       &SrcCategoryId=&SrcFamilyId=58ce885d-508b-45c8-9fd3-
       118edd8e6fff&u=details.aspx%3ffamilyid%3d5A58B56F-60B6-4412-95B9-
       54D056D6F9F4%26displaylang%3den
    6. 安装 Microsoft® SQL Server® Express 2008:
       http://www.microsoft.com/downloads/details.aspx?familyid=58CE885D-508B-
       45C8-9FD3-118EDD8E6FFF&displaylang=en (如安装时收到.NET Framework 2.0
        SP2 is required 的错误提示信息, 请确认已安装.NET Framework 3.5 ,.NET Framework 3.5
        SP1 和 Windows Installer 4.5).
             a. 安装 Database Engine 模块.
             b. 请填写 SQLExpress 作为数据库实例名.
             c. 添加 Administrator 用户作为系统管理员, 使用 Windows authentication
                mode 作为验证模式.




                                        7
PHP on Windows – Demonstration


PHP 站点开发管理                       综述
此实例包含如下内容:
        1. 回顾 IIS 管理工具和配置模块委托机制
        2. 创建并配置一个自定义的 404 错误信息提示页
        3. 通过窗体验证和 URL 授权机制实现一个登陆控件
        4. 回顾委托配置


PHP 站点开发管理                       Step1: IIS 管理工具和配置模块委托机制
了解 IIS 管理工具.
        a. 打开 Internet Information Services (IIS) Manager.
        b. 选择 mediawiki.
        c. IIS Manager 中将会展示所有的可管理模块
                 .
开启 HTTP 错误配置委托用以许可委托的配置
       a. 打开 Internet Information Services (IIS) Manager, 选择本地服务器
       b. 选择 Management 中的 Feature Delegation 模块.
       c. 选择 Error Pages
       d. 开启 Read/Write


PHP 站点开发管理                       Step2 自定义错误信息提示页
        1. 默认情况下, 应用程序中发送给客户端的错误信息会衍生做一个默认的 IIS 错误提示信息.
           a. 访问 http://localhost/mediawiki/file.php,会收到 404 错误.
           b. 如果访问一个不存在的 txt 文件,如 http://localhost/MediaWiki/file.txt ,则将得到一个
               详细的 IIS 错误页
        2. 通过自定义的方法定制错误信息提示页.
            a. 打开 http://localhost/MediaWiki/NotFound.
            b. 编辑错误提示信息如下 The page you are looking for does not exist. Try browsing for
                it from the main page of the Wiki.
                点击 Save Page.
        3. 配置自定义错误信息页.
           a. 打开 Internet Information Services (IIS) Manager,选择 mediawiki.
           b. 点击 Error Pages.
           c. 选择 Edit Feature Settings
           d. 选择 Custom error pages 并点击 OK.
           e. 在错误信息号列表中双击 404.
           f. 选择 Respond with a 302 redirect, 并填入错误信息提示页的 URl:
               /mediawiki/NotFound
           g. 点击 OK.
        4. 测试自定义错误信息提示页:
           a. 请求一个不存在的页面: http://localhost/MediaWiki/file.php.
           b. 系统将跳转到自定义的错误信息提示页.
           c. 请求一个不存在的文本文件: http://localhost/MediaWiki/file.txt.


                                         8
PHP on Windows – Demonstration


PHP 站点开发管理                       Step3: 身份验证
        1. 为 MediaWiki 开放验证机制.
        2. 打开 Internet Information Services (IIS) Manager,选择 mediawiki..
           a. 选择 Authentication
           b. 选择 Forms Authentication 并置为 Enable.
        3. 确保 PHP 站点中所有的内容的访问均需经过验证
           a. 选择 mediawiki..
           b. 选择 Modules.
           c. 双击 FormsAuthentication 模块, 并清除 Invoke only for requests to manage handlers
              的选项.
        4. 创建一个自定义的身份验证.
           a. 在 mediawiki 目录下创建 APP_Data 文件夹,添加 IIS_IUSRS 并赋予 Modify 的权限
           b. 选择 mediawiki ,选择 .NET Users.
           c. 点击 Add…
           d. 输入用户名 WikiUser, 邮件地址 wikiuser@contoso.com, 密码 wikidemo1!
              点击 OK 创建该用户.
        5. 创建身份验证页.
           a. 在 mediawiki 目录下创建 login.aspx,输入下列内容
       <<
       <html>
       <head>
         <title>Login to my blog</title>
        </head>
        <body>
         <form runat=quot;serverquot;>
          <asp:Login runat=quot;serverquot; />
         </form>
        </body>
        </html>

        >>
           b. 请求 http://localhost/mediawiki/. 当前的状态是未经验证仍可进入站点.
        6. 配置登陆规则.
           a. 选择 mediawiki..
           b. 选择 Authorization Rules.
           c. 选择 Add Deny Rule…
           d. 选择 All Anonymous users.
           e. 选择 OK.
           f. 再次请求 http://localhost/mediawiki/.
           g. 系统将跳转到 Login.aspx 页.
             h. 尝试用之前创建的用户名及密码进行登陆




                                           9
PHP on Windows – Demonstration


PHP 站点开发管理                       Step4: 结语
        7. 回顾配置文件 web.config

        <<
        <?xml version=quot;1.0quot; encoding=quot;UTF-8quot;?>
        <configuration>
        <system.webServer>

          <modules>
          <remove name=quot;FormsAuthenticationquot; />
          <add name=quot;FormsAuthenticationquot;
        type=quot;System.Web.Security.FormsAuthenticationModulequot; preCondition=quot;quot; />
          </modules>
          <security>
          <authorization>
           <add accessType=quot;Denyquot; users=quot;?quot; />
          </authorization>
          </security>
          <httpErrors errorMode=quot;Customquot;>
          <remove statusCode=quot;404quot; subStatusCode=quot;-1quot; />
          <error statusCode=quot;404quot; prefixLanguageFilePath=quot;quot;
        path=quot;/MediaWiki/NotFoundquot; responseMode=quot;Redirectquot; />
          </httpErrors>
         </system.webServer>
         <system.web>
          <authentication mode=quot;Formsquot; />
         </system.web>
        </configuration>




                                        10

Contenu connexe

Tendances

Wicket + EJB3 on JBoss (Japanese)
Wicket + EJB3 on JBoss (Japanese)Wicket + EJB3 on JBoss (Japanese)
Wicket + EJB3 on JBoss (Japanese)
bose999
 
Sd Loader Seasar Con2009 White
Sd Loader Seasar Con2009 WhiteSd Loader Seasar Con2009 White
Sd Loader Seasar Con2009 White
Akio Katayama
 
Самоучитель Visual Basic.Net Д.Зак
Самоучитель Visual Basic.Net  Д.ЗакСамоучитель Visual Basic.Net  Д.Зак
Самоучитель Visual Basic.Net Д.Зак
StAlKeRoV
 
WebHookの調査と実装
WebHookの調査と実装WebHookの調査と実装
WebHookの調査と実装
moai kids
 

Tendances (19)

Wicket + EJB3 on JBoss (Japanese)
Wicket + EJB3 on JBoss (Japanese)Wicket + EJB3 on JBoss (Japanese)
Wicket + EJB3 on JBoss (Japanese)
 
Tailieu Hs2005
Tailieu Hs2005Tailieu Hs2005
Tailieu Hs2005
 
Modern Front End Evolution
Modern Front End EvolutionModern Front End Evolution
Modern Front End Evolution
 
Sd Loader Seasar Con2009 White
Sd Loader Seasar Con2009 WhiteSd Loader Seasar Con2009 White
Sd Loader Seasar Con2009 White
 
WebDAV as Web API
WebDAV as Web APIWebDAV as Web API
WebDAV as Web API
 
What is PHP Frameworks?
What is PHP Frameworks?What is PHP Frameworks?
What is PHP Frameworks?
 
RDF and FOAF
RDF and FOAFRDF and FOAF
RDF and FOAF
 
01.12.11
01.12.1101.12.11
01.12.11
 
16.07.11.
16.07.11.16.07.11.
16.07.11.
 
PHPUnit+SeleniumによるWebテスト
PHPUnit+SeleniumによるWebテストPHPUnit+SeleniumによるWebテスト
PHPUnit+SeleniumによるWebテスト
 
Web design book
Web design bookWeb design book
Web design book
 
webErp安装说明
webErp安装说明webErp安装说明
webErp安装说明
 
Uliweb 快速易用的Python Web Framework
Uliweb 快速易用的Python Web FrameworkUliweb 快速易用的Python Web Framework
Uliweb 快速易用的Python Web Framework
 
Voices for Custodial Justice Newsletter - September 2014 Issue
Voices for Custodial Justice Newsletter - September 2014 IssueVoices for Custodial Justice Newsletter - September 2014 Issue
Voices for Custodial Justice Newsletter - September 2014 Issue
 
Самоучитель Visual Basic.Net Д.Зак
Самоучитель Visual Basic.Net  Д.ЗакСамоучитель Visual Basic.Net  Д.Зак
Самоучитель Visual Basic.Net Д.Зак
 
12.05.11
12.05.1112.05.11
12.05.11
 
淺嚐新火狐
淺嚐新火狐淺嚐新火狐
淺嚐新火狐
 
Voices for Custodial Justice Newsletter - December 2014 Issue
Voices for Custodial Justice Newsletter - December 2014 IssueVoices for Custodial Justice Newsletter - December 2014 Issue
Voices for Custodial Justice Newsletter - December 2014 Issue
 
WebHookの調査と実装
WebHookの調査と実装WebHookの調査と実装
WebHookの調査と実装
 

En vedette (8)

TEAM SILVER STREAMLINED 08
TEAM SILVER STREAMLINED 08TEAM SILVER STREAMLINED 08
TEAM SILVER STREAMLINED 08
 
Personal learning Environments
Personal learning EnvironmentsPersonal learning Environments
Personal learning Environments
 
presentatie Ruben
presentatie Rubenpresentatie Ruben
presentatie Ruben
 
Presentatie Liesbeth VP
Presentatie Liesbeth VPPresentatie Liesbeth VP
Presentatie Liesbeth VP
 
Life Church Manurewa Dec 08
Life Church Manurewa Dec 08Life Church Manurewa Dec 08
Life Church Manurewa Dec 08
 
Campus Ministers Fundraising
Campus Ministers FundraisingCampus Ministers Fundraising
Campus Ministers Fundraising
 
Presentatie Kim
Presentatie KimPresentatie Kim
Presentatie Kim
 
Skrip pengacaraan majlis forum maulidur rasul ppd 2014
Skrip pengacaraan majlis forum maulidur rasul ppd 2014Skrip pengacaraan majlis forum maulidur rasul ppd 2014
Skrip pengacaraan majlis forum maulidur rasul ppd 2014
 

Php.On.Windows.Training.Chs

  • 2. PHP on Windows – Demonstration 目录 Demonstration – 在 IIS 7.0 中部署 PHP 站点................................................................ 1 PHP 站点部署 概述 ..................................................................................................... 1 PHP 站点部署 环境搭建 .............................................................................................. 1 PHP 站点部署 综述 ..................................................................................................... 1 PHP 站点部署 Step 1: 在 IIS 7.0 上安装 PHP 支持软件 .............................................. 1 PHP 站点部署 Step 2 : 下载并安装 PHP 框架 ............................................................. 2 PHP 站点部署 Step 3: 使用 FastCGI,关联 IIS 和 PHP 应用程序 ............................... 3 PHP 站点部署 Step 4: 搭建 PHP 应用程序 ................................................................. 4 PHP 站点部署 Step 5: 使用 URL Rewrite 实现 URl 重写 ............................................. 4 Demonstration – 在 IIS 7.0 中开发和管理 PHP 站点 ..................................................... 7 PHP 站点开发管理 概述 .............................................................................................. 7 PHP 站点开发管理 环境搭建 ....................................................................................... 7 PHP 站点开发管理 综述 .............................................................................................. 8 PHP 站点开发管理 Step1: IIS 管理工具和配置模块委托机制 ...................................... 8 PHP 站点开发管理 Step2: 自定义错误信息提示页 ...................................................... 8 PHP 站点开发管理 Step3: 身份验证 ........................................................................... 9 PHP 站点开发管理 Step4: 结语................................................................................. 10 2
  • 3. PHP on Windows – Demonstration Demonstration – 在 IIS 7.0 中部署 PHP 站点 PHP 站点部署 概述 此实例用以展示如何在 IIS7.0 平台上部署、管理和扩展 PHP 站点. 本实例要达到的目的:  了解 IIS FastCGI 为 PHP 站点的发布提供了稳定的平台支持  了解在 IIS7.0 上可以很容易的发布 PHP 站点  IS7.0 对 PHP 的兼容性 PHP 站点部署 环境搭建 1. 需要的系统环境为 Windows Server® 2008 或 Windows Vista® SP1(安装 SP1 补丁)。 针对这两种操作系统版本,差异仅存在于步骤 1( FastCGI 的配置),其他的步骤均相同。 2. IIS7.0 初始配置状态,假定为系统安装后的默认状态。 3. 下载并安装 MySQL a. 请通过 www.mysql.com 下载 community 版 b. 在安装过程中,请选择 default configuration,并确认选择 run as a service, 默认密码请选择 demo1。 4. 下载第三方应用程序 mediawiki: a. http://www.mediawiki.org/wiki/Download.. 5. 下载并安装 IIS 外置模块组件,URL Rewrite: a. http://www.iis.net/downloads/default.aspx?tabid=34&g=6&i=1691 6. 为 IIS 开放权限: a. Internet ,找到 Management 下的 Feature Delegation 模块 b. 选择 URL Rewrite,将其置为 Read/Write PHP 站点部署 综述 1. 在 IIS 7.0 上安装 PHP 支持 2. 下载并安装 PHP 框架 3. 通过 FastCGI 将 IIS 7.0 与 PHP 进行关联 4. 下载并安装第三方的应用程序 MediaWiki 5. 配置 URL Rewrite,开启相应权限 PHP 站点部署 Step 1: 在 IIS 7.0 上安装 PHP 支持软件 1. 安装 FastCGI. a. 如果用户的系统为 Windows Server 2008: i. 打开 Server Manager. ii. 选择 Web Server (IIS) role. iii. 右键点击 Web Server (IIS) role,选择 Add Role Services. 1
  • 4. PHP on Windows – Demonstration iv. 在 Application Development 节点中找到 CGI 服务. v. 点击 Next -----Install 进行服务的安装. b. 如果用户的系统为 Windows Vista SP1: i. 进入 Control Panel 并选择 Programs and Features. ii. 选择左侧选项中的 Turn Windows Features on or off. iii. 在 Internet Information ServicesWorld Wide Web services 下选择 Application Development Features 模块. iv. 选择 CGI. v. 点击 OK. PHP 站点部署 Step 2 : 下载并安装 PHP 框架 1. 从 www.php.net/downloads 现在 PHP 框架. a. 请选择 Non-thread-safe 的压缩安装包, 本实例将使用 PHP 5.2.6 Non-thread-safe 版的压 缩包 (http://www.php.net/get/php-5.2.6-nts-Win32.zip/from/a/mirror). 2. 将压缩包解压到本地,路径例如 C:php. 3. 如果对以下的操作有疑问, 可访问 http://learn.iis.net/page.aspx/246/using-fastcgi-to-host-php- applications-on-iis-70/ 获得更多的支持. 4. 将文件夹中的 php.ini-recommanded 文件更名成 php.ini 2
  • 5. PHP on Windows – Demonstration 5. 打开 php.ini, 按照以下的步骤进行修改(更改的 3 个环境变量是针对本实例): a. 将 cgi.fix_pathinfo 置为 1, 即 cgi.fix_pathinfo = 1 b. 将 cgi.force_redirect 置为 0,即 cgi.force_redirect = 0 c. 注释掉 error_log = syslog(如果此项在文件中不存在,则步骤 c 可跳过) 6. 通过命令行测试 PHP 是否安装成功 C:PHP>php -info PHP 站点部署 Step 3: 使用 FastCGI,关联 IIS 和 PHP 应用程序 1. 打开 Internet Information Services (IIS) Manager (inetmgr.exe). 2. 在左侧选择本地服务器. 3. 选择服务模块 Handler mappings ,双击打开。 4. 在最右侧的列表中点击选择 Add Module Mapping 5. 在弹出的窗体中填入下列信息,并单击 OK. a. Request Path 中填入 *.php b. Module 中填入 FastCgiModule c. Executable 中填入 C:php php-cgi.exe.(请按照具体解压的路径进行选择) d. Name 中填入 PHP via FastCGI (任意名称均可) 6. 点击 OK. 3
  • 6. PHP on Windows – Demonstration PHP 站点部署 Step 4: 搭建 PHP 应用程序 1. 将 MediaWiki 解压到本地,路径 C:inetpubwwwrootmediawiki,请保证压缩包中所有 的文件均处于这个路径下,而不是被解压到此路径下的子文件夹。 2. 为 MediaWiki 文件夹添加 IIS_IUSRS 用户,并为 IIS_IUSRS 用户加入 Modify, Write, Read 权限 3. 在 InetMgr 的 Default Web Site 下找到 mediawiki 目录,右击选择 Convert to Application. 4. 通过命令行在 c:php 根目录下添加两个文件夹,分别为 session 和 upload ,并进行授权: cd /d C:php md session md upload icacls session /grant BUILTINIIS_IUSRS:(OI)(CI)(M) icacls upload /grant BUILTINIIS_IUSRS:(OI)(CI)(M) 在 php.ini 文件中添加如下信息: upload_tmp_dir = quot;c:phpuploadquot; session.save_path = quot;c:phpsessionquot; 在 php.ini 文件中添加(开放)环境变量以支持 MySql extension_dir = quot;C:phpextquot; extension = php_mysql.dll 5. 在 InetMgr 中选择 Directory Browsing,双击打开,如果选项被灰化,且右侧的 Disable 选项处于选中状态,则请将其置为 Enable. 6. 搭建 mediawiki 站点: a. 浏览 http://localhost/mediawiki/config/index.php,如果页面无法打开确认 步骤 5,并确认 mediawiki 虚拟目录的位置是否正确,是否设置了所需的权限。 b. 在 Wiki name 中输入 My MediaWiki(任意名称均可) c. 为 Admin user 用户确认密码 demo1 d. 为 wikiuser 用户确认密码 demo1 e. User superuser 用户的检验框请勾选,为 root 添加 MySql 的密码,本实例中在安 装 MySql 时,将密码设为 demo1 f. 点击 Install MediaWiki! 拷贝configLocalSettings.php 文件到根目录(实例中为 c:wwwwroorinetpubmediawiki) PHP 站点部署 Step 5: 使用 URL Rewrite 实现 URl 重写 1. 前期准备 4
  • 7. PHP on Windows – Demonstration 确认 URL Rewite 组件已经被正确安装,并按照 step1 完成了环境变量的修改。 2. 为 PHP 站点设置起始页 当前状态下(未进行 URL 重写配置),我们通过 http://localhost/mediawiki 将无法访问到 页面,系统提示错误。 a. 打开 IIS Manager. b. 在 Default Web Site 下找到 mediawiki 目录. c. 选择 Default document 模块. d. 右键选择 Add,并输入 index.php. 点击 OK. e. 再次访问 http://localhost/mediawiki ,系统将定位访问到 index.php. 3. 为 PHP 站点 URL 重写规则 在 mediawiki 的根目录下找到 LocalSetting.php 文件,并按照文档进行改写: ## The URL base path to the directory containing the wiki; ## defaults for all runtime URL paths are based off of this. ## For more information on customizing the URLs please see: ## http://www.mediawiki.org/wiki/Manual:Short_URL $wgScriptPath = quot;/mediawikiquot;; $wgScriptExtension = quot;.phpquot;; $wgArticlePath = quot;${wgScriptPath}/$1quot;; a. 打开 IIS Manager. b. 点击选择 mediawiki . c. 选择 URL Rewrite 模块,双击打开. d. 选择 Import rules e. 在弹出的窗口内输入以下 URL 重写规则 << # BEGIN Wiki # Don't rewrite requests for files in MediaWiki subdirectories, # MediaWiki PHP files, HTTP error documents, favicon.ico, or robots.txt RewriteCond %{REQUEST_URI} !^/mediawiki/stylesheets/ RewriteCond %{REQUEST_URI} !^/mediawiki/skins/ RewriteCond %{REQUEST_URI} !^/mediawiki/(redirect|texvc|index).php RewriteCond %{REQUEST_URI} !^/mediawiki/sitemap.xml.php RewriteCond %{REQUEST_URI} !^/mediawiki/error/(40(1|3|4)|500).html RewriteCond %{REQUEST_URI} !^/mediawiki/favicon.ico RewriteCond %{REQUEST_URI} !^/mediawiki/robots.txt RewriteCond %{REQUEST_URI} !^/mediawiki/(.*).w+$ # Make sure there is no query string RewriteCond %{QUERY_STRING} ^$ # Rewrite http:/.domain.tld/article properly, this is the main rule RewriteRule ^/?(.*)$ /mediawiki/index.php?title=$1 [L,QSA] # END Wiki >> f. 点击 Apply,应用以上规则。 g. 打开 http://localhost/mediawiki/main_Page,系统将自动将访问请求转到 http://locahost/mediawiki/index.php?title=Main_Page . 5
  • 8. PHP on Windows – Demonstration 4. 打开 web.config 文件,可以看到之前的配置在文件中均有体现. <?xml version=quot;1.0quot; encoding=quot;UTF-8quot;?> <configuration> <system.webServer> <defaultDocument> <files> <add value=quot;index.phpquot; /> </files> </defaultDocument> <rewrite> <rules> <rule name=quot;Imported Rule 1quot; stopProcessing=quot;truequot;> <match url=quot;^(.*)$quot; ignoreCase=quot;falsequot; /> <conditions logicalGrouping=quot;MatchAllquot;> <add input=quot;{REQUEST_URI}quot; negate=quot;truequot; pattern=quot;^/mediawiki/stylesheets/quot; ignoreCase=quot;falsequot; /> <add input=quot;{REQUEST_URI}quot; negate=quot;truequot; pattern=quot;^/mediawiki/skins/quot; ignoreCase=quot;falsequot; /> <add input=quot;{REQUEST_URI}quot; negate=quot;truequot; pattern=quot;^/mediawiki/(redirect|texvc|index).phpquot; ignoreCase=quot;falsequot; /> <add input=quot;{REQUEST_URI}quot; negate=quot;truequot; pattern=quot;^/mediawiki/sitemap.xml.phpquot; ignoreCase=quot;falsequot; /> <add input=quot;{REQUEST_URI}quot; negate=quot;truequot; pattern=quot;^/mediawiki/error/(40(1|3|4)|500).htmlquot; ignoreCase=quot;falsequot; /> <add input=quot;{REQUEST_URI}quot; negate=quot;truequot; pattern=quot;^/mediawiki/favicon.icoquot; ignoreCase=quot;falsequot; /> <add input=quot;{REQUEST_URI}quot; negate=quot;truequot; pattern=quot;^/mediawiki/robots.txtquot; ignoreCase=quot;falsequot; /> <add input=quot;{REQUEST_URI}quot; negate=quot;truequot; pattern=quot;^/mediawiki/(.*).w+$quot; ignoreCase=quot;falsequot; /> <add input=quot;{QUERY_STRING}quot; negate=quot;truequot; pattern=quot;^?$quot; ignoreCase=quot;falsequot; /> </conditions> <action type=quot;Rewritequot; url=quot;/mediawiki/index.php?title={R:1}quot; appendQueryString=quot;truequot; /> </rule> </rules> </rewrite> </system.webServer> </configuration> 6
  • 9. PHP on Windows – Demonstration Demonstration – 在 IIS 7.0 中开发和管理 PHP 站点 PHP 站点开发管理 概述 本实例基于上个实例,确保上个实例已被正确完成。 本实例用于展示 IIS7.0 平台上 PHP 应用程序的发布、管理和扩展,以及 IIS7.0 平台对 PHP 应用程序 的有力支持。 PHP 站点开发管理 环境搭建 1. 需要的系统环境为 Windows Server® 2008 或 Windows Vista® SP1 (SP1 required). 2. 需要完成上一个实例 3. 在 IIS 中安装 URL Authorization. a. Windows Server 2008: 通过 Server ManagerRolesWeb Server (IIS) Role 安装 Web ServerSecurityURL Authorization 服务模块. b. Windows Vista SP1: 通过 Control PanelPrograms and FeaturesTurn Windows Features on or off 安装 Internet Information ServicesWorld Wide Web servicesSecurityURL Authorization 服务模块. 4. 安装 Microsoft® .NET Framework 3.5 和 Microsoft® .NET Framework 3.5 SP1: http://www.microsoft.com/downloadS/details.aspx?familyid=AB99342F-5D1A- 413D-8319-81DA479AB0D7&displaylang=en. 5. 安装 Windows Installer 4.5: http://www.microsoft.com/downloads/info.aspx?na=47&p=4&SrcDisplayLang=en &SrcCategoryId=&SrcFamilyId=58ce885d-508b-45c8-9fd3- 118edd8e6fff&u=details.aspx%3ffamilyid%3d5A58B56F-60B6-4412-95B9- 54D056D6F9F4%26displaylang%3den 6. 安装 Microsoft® SQL Server® Express 2008: http://www.microsoft.com/downloads/details.aspx?familyid=58CE885D-508B- 45C8-9FD3-118EDD8E6FFF&displaylang=en (如安装时收到.NET Framework 2.0 SP2 is required 的错误提示信息, 请确认已安装.NET Framework 3.5 ,.NET Framework 3.5 SP1 和 Windows Installer 4.5). a. 安装 Database Engine 模块. b. 请填写 SQLExpress 作为数据库实例名. c. 添加 Administrator 用户作为系统管理员, 使用 Windows authentication mode 作为验证模式. 7
  • 10. PHP on Windows – Demonstration PHP 站点开发管理 综述 此实例包含如下内容: 1. 回顾 IIS 管理工具和配置模块委托机制 2. 创建并配置一个自定义的 404 错误信息提示页 3. 通过窗体验证和 URL 授权机制实现一个登陆控件 4. 回顾委托配置 PHP 站点开发管理 Step1: IIS 管理工具和配置模块委托机制 了解 IIS 管理工具. a. 打开 Internet Information Services (IIS) Manager. b. 选择 mediawiki. c. IIS Manager 中将会展示所有的可管理模块 . 开启 HTTP 错误配置委托用以许可委托的配置 a. 打开 Internet Information Services (IIS) Manager, 选择本地服务器 b. 选择 Management 中的 Feature Delegation 模块. c. 选择 Error Pages d. 开启 Read/Write PHP 站点开发管理 Step2 自定义错误信息提示页 1. 默认情况下, 应用程序中发送给客户端的错误信息会衍生做一个默认的 IIS 错误提示信息. a. 访问 http://localhost/mediawiki/file.php,会收到 404 错误. b. 如果访问一个不存在的 txt 文件,如 http://localhost/MediaWiki/file.txt ,则将得到一个 详细的 IIS 错误页 2. 通过自定义的方法定制错误信息提示页. a. 打开 http://localhost/MediaWiki/NotFound. b. 编辑错误提示信息如下 The page you are looking for does not exist. Try browsing for it from the main page of the Wiki. 点击 Save Page. 3. 配置自定义错误信息页. a. 打开 Internet Information Services (IIS) Manager,选择 mediawiki. b. 点击 Error Pages. c. 选择 Edit Feature Settings d. 选择 Custom error pages 并点击 OK. e. 在错误信息号列表中双击 404. f. 选择 Respond with a 302 redirect, 并填入错误信息提示页的 URl: /mediawiki/NotFound g. 点击 OK. 4. 测试自定义错误信息提示页: a. 请求一个不存在的页面: http://localhost/MediaWiki/file.php. b. 系统将跳转到自定义的错误信息提示页. c. 请求一个不存在的文本文件: http://localhost/MediaWiki/file.txt. 8
  • 11. PHP on Windows – Demonstration PHP 站点开发管理 Step3: 身份验证 1. 为 MediaWiki 开放验证机制. 2. 打开 Internet Information Services (IIS) Manager,选择 mediawiki.. a. 选择 Authentication b. 选择 Forms Authentication 并置为 Enable. 3. 确保 PHP 站点中所有的内容的访问均需经过验证 a. 选择 mediawiki.. b. 选择 Modules. c. 双击 FormsAuthentication 模块, 并清除 Invoke only for requests to manage handlers 的选项. 4. 创建一个自定义的身份验证. a. 在 mediawiki 目录下创建 APP_Data 文件夹,添加 IIS_IUSRS 并赋予 Modify 的权限 b. 选择 mediawiki ,选择 .NET Users. c. 点击 Add… d. 输入用户名 WikiUser, 邮件地址 wikiuser@contoso.com, 密码 wikidemo1! 点击 OK 创建该用户. 5. 创建身份验证页. a. 在 mediawiki 目录下创建 login.aspx,输入下列内容 << <html> <head> <title>Login to my blog</title> </head> <body> <form runat=quot;serverquot;> <asp:Login runat=quot;serverquot; /> </form> </body> </html> >> b. 请求 http://localhost/mediawiki/. 当前的状态是未经验证仍可进入站点. 6. 配置登陆规则. a. 选择 mediawiki.. b. 选择 Authorization Rules. c. 选择 Add Deny Rule… d. 选择 All Anonymous users. e. 选择 OK. f. 再次请求 http://localhost/mediawiki/. g. 系统将跳转到 Login.aspx 页. h. 尝试用之前创建的用户名及密码进行登陆 9
  • 12. PHP on Windows – Demonstration PHP 站点开发管理 Step4: 结语 7. 回顾配置文件 web.config << <?xml version=quot;1.0quot; encoding=quot;UTF-8quot;?> <configuration> <system.webServer> <modules> <remove name=quot;FormsAuthenticationquot; /> <add name=quot;FormsAuthenticationquot; type=quot;System.Web.Security.FormsAuthenticationModulequot; preCondition=quot;quot; /> </modules> <security> <authorization> <add accessType=quot;Denyquot; users=quot;?quot; /> </authorization> </security> <httpErrors errorMode=quot;Customquot;> <remove statusCode=quot;404quot; subStatusCode=quot;-1quot; /> <error statusCode=quot;404quot; prefixLanguageFilePath=quot;quot; path=quot;/MediaWiki/NotFoundquot; responseMode=quot;Redirectquot; /> </httpErrors> </system.webServer> <system.web> <authentication mode=quot;Formsquot; /> </system.web> </configuration> 10