在IIS7上设置Laravel

4
我想设置我的 IIS7 服务器,以便让它与用 Laravel (php 框架)编写的 Web 应用程序一起使用。我找到了类似于 CI 的东西(链接),但是它在 Laravel 上不起作用(当然我删除了 index.php 重定向)。实际上只有主页可以正常工作(www.mysite.com/public )。有人使用过 IIS7 来搭配 Laravel 吗?谢谢您的帮助。
8个回答

6

我在根目录下创建了web.config文件,位于<configuration></configuration>内部:

<system.webServer>
    <defaultDocument>
        <files>
            <clear />
            <add value="index.php" />
            <add value="default.aspx" />
            <add value="Default.htm" />
            <add value="Default.asp" />
            <add value="index.htm" />
            <add value="index.html" />
        </files>
    </defaultDocument>
    <handlers accessPolicy="Read, Execute, Script" />
    <rewrite>
        <rules>
            <rule name="Imported Rule 2" stopProcessing="true">
                <match url="^(.*)$" ignoreCase="false" />
                <conditions logicalGrouping="MatchAll">
                    <add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />
                    <add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" negate="true" />
                </conditions>
                <action type="Rewrite" url="public/{R:1}" />
            </rule>
        </rules>
    </rewrite>
</system.webServer>

然后将public文件夹中的index.php文件复制到项目的根目录中,将../paths.php修改为paths.php,就像这篇指南所说的那样。

现在一切都完美运行。


4
我使用了下面的代码,将重定向到index.php/{R:1}而不是public/{R:1},然后直接使用,无需更改路径。
<rewrite>
    <rules>
        <rule name="Imported Rule 2" stopProcessing="true">
            <match url="^(.*)$" ignoreCase="false" />
            <conditions logicalGrouping="MatchAll">
                <add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />
                <add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" negate="true" />
            </conditions>
            <action type="Rewrite" url="index.php/{R:1}" />
        </rule>
    </rules>
</rewrite>

3

经过长时间的谷歌搜索和测试,我终于让它运行起来了。以下是我的步骤:

Laravel5与IIS 8.5

  1. 安装window平台安装程序
  2. 使用window平台安装程序安装php-5.6
  3. 使用window平台安装程序安装IIS的php-manager(可选)
  4. 安装Visual C++ Redistributable for Visual Studio 2012(x86版本)
    没有这个,FastCgi进程会意外退出(php_info()将不工作)
  5. 安装composer.exe
  6. 将composer vendor bin路径导出到path中
    set PATH=%PATH%;%USERPROFILE%\AppData\Roaming\Composer\vendor\bin
  7. 运行 composer global require "laravel/installer=~1.1"
  8. 运行 lavarel new app
  9. 在IIS中创建新应用程序,并指向<app>/public

就是这样,愉快地使用Laravel吧!

参考:http://alvarotrigo.com/blog/installing-laravel-4-in-windows-7-with-iis7/


3

检查您在IIS中的处理程序映射:

  1. 启动IIS
  2. 点击您的网站
  3. 进入'IIS块'中的'处理程序映射'
  4. 搜索路径PHP,名称= PHPxx_via_FastCGI(xx = php版本)
  5. 双击它,单击“请求限制”,然后单击选项卡“动词”,选择所有动词。这将修复它 :-)

3
这是我的工作文件,包含两个规则:(网站指向公共文件夹)
<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <system.webServer>
    <rewrite>
      <rules>
        <rule name="RewriteRequestsToPublic">
          <match url="^(.*)$" />
          <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
          </conditions>
          <action type="Rewrite" url="/{R:0}" />
        </rule>
        <rule name="Imported Rule 1" stopProcessing="true">
          <match url="^(.*)$" ignoreCase="false" />
          <conditions logicalGrouping="MatchAll">
            <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
            <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
          </conditions>
          <action type="Rewrite" url="/index.php/{R:1}" appendQueryString="true" />
        </rule>
      </rules>
    </rewrite>
  </system.webServer>
</configuration>

谢谢!对我有用!另外,我不得不将index.php移动到根路径。 - AskYous

0

要在Windows上安装IIS,请前往控制面板 -> 卸载程序并点击打开或关闭Windows功能链接,然后选择IIS并选择CGI选项。

enter image description here

从互联网下载 Web Platform Installer,为 IIS 安装 PHP 和 SQL 驱动程序。

从程序中添加网站打开 IIS。对于公共文件夹,请指向 Laravel/Lumen 项目中的 Public 文件夹。

对于 Laravel 和 Lumen 项目,请在任何可访问的文件夹中使用 composer 创建项目。进入文件夹结构中的 public 文件夹,并创建以下内容的 web.config 文件,我是从 laracasts 上获得的:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <rewrite>
          <rules>
            <rule name="Rule 1" stopProcessing="true">
              <match url="^(.*)/$" ignoreCase="false" />
              <action type="Redirect" redirectType="Permanent" url="/{R:1}" />
            </rule>
            <rule name="Rule 2" stopProcessing="true">
              <match url="^" ignoreCase="false" />
              <conditions>
                <add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" negate="true" />
                <add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />
              </conditions>
              <action type="Rewrite" url="index.php" />
            </rule>
          </rules>
        </rewrite>
    </system.webServer>
</configuration> 

0
如果您想要能够检索您的 $_GET 变量,请不要使用以下代码:

<match url="^(.*)$" ignoreCase="false" />

相反,请使用以下代码:

<match url="^" ignoreCase="false" />


0
这是我如何解决它的方法。 打开配置文件,如果以下映射不存在,请将这些行放在

下面。
  <rewrite>
    <rules>
      <rule name="Imported Rule 1" stopProcessing="true">
        <match url="^(.*)/$" ignoreCase="false" />
        <conditions>
          <add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" negate="true" />
        </conditions>
        <action type="Redirect" redirectType="Permanent" url="/{R:1}" />
      </rule>
      <rule name="Imported Rule 2" stopProcessing="true">
        <match url="^" ignoreCase="false" />
        <conditions>
          <add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" negate="true" />
          <add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />
        </conditions>
        <action type="Rewrite" url="index.php" />
      </rule>
    </rules>
  </rewrite>

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接