在 IIS7 上设置 Laravel

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14381950/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 07:30:03  来源:igfitidea点击:

setting up laravel on IIS7

phpmod-rewriteiis-7virtualhostlaravel

提问by Dario Rusignuolo

I want to set up my IIS7server in order to let it works with a web application written in laravel(php framework).

我想设置我的IIS7服务器,以便让它与用laravel(php 框架)编写的 Web 应用程序一起工作。

I found something similar for CI(link)

我发现了类似的东西CI链接

but it doesn't work on laravel(of course I removed the index.phpredirection).

但它不起作用laravel(当然我删除了index.php重定向)。

actually only home page works (www.mysite.com/public)

实际上只有主页有效 ( www.mysite.com/public)

anybody uses/d IIS7with Laravel?

有人IIS7在 Laravel 上使用/d吗?

thanks in advance

提前致谢

回答by Dario Rusignuolo

I created the web.configfile in root folder inside <configuration></configuration>:

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>

then copy the index.phpfile of the public folder into the root folder of the project modifying the ../paths.phpinto paths.phpas thisguide says

然后复制index.php公用文件夹的文件到项目修改的根文件夹../paths.phppaths.php这个指南说

now everything works perfectly

现在一切正常

回答by Danny Rowlands

I used the code below, redirect to index.php/{R:1}rather than public/{R:1}Works straight out of the box then with no path changes.

我使用了下面的代码,重定向到 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>

回答by Juan Antonio Tubío

Here is my working file, with two rules: (web site is pointing to public folder)

这是我的工作文件,有两个规则:(网站指向公共文件夹)

<?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>

回答by ken

Just got it working after long hours of google and testing. Here is my steps:

经过长时间的谷歌和测试,它才开始工作。这是我的步骤:

laravel5 with IIS 8.5

laravel5 与 IIS 8.5

  1. install window platform installer
  2. install php-5.6 with window platform installer
  3. install php-manager for IIS with window platform installer (optional)
  4. install Visual C++ Redistributable for Visual Studio 2012 (version x86)
    Without this, FastCgi process excited unexpected (php_info() will not works)
  5. install composer.exe
  6. export composer vendor bin path to path
    set PATH=%PATH%;%USERPROFILE%\AppData\Roaming\Composer\vendor\bin
  7. run composer global require "laravel/installer=~1.1"
  8. run lavarel new app
  9. create new application in IIS and point to <app>/public
  1. 安装窗口平台安装程序
  2. 使用窗口平台安装程序安装 php-5.6
  3. 使用窗口平台安装程序为 IIS 安装 php-manager(可选)
  4. 安装Visual C++ Redistributable for Visual Studio 2012 (version x86)
    如果没有这个,FastCgi 进程会被意外激发(php_info() 将无法工作)
  5. 安装composer.exe
  6. 导出作曲家供应商 bin 路径到路径
    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

That's it, Happy Lavarel!

就是这样,快乐的拉瓦雷尔!

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

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

回答by bert

Check your Handler Mappings in IIS:

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

  1. launch IIS
  2. click on your site
  3. go on 'handler mappings' (in IIS block)
  4. Search for Path PHP, Name = PHPxx_via_FastCGI (xx = php version)
  5. Double click it, click on request restrictions and click on tab 'Verb's where you choose All verbs. This will fix it :-)
  1. 启动 IIS
  2. 点击你的网站
  3. 继续“处理程序映射”(在 IIS 块中)
  4. 搜索路径 PHP,名称 = PHPxx_via_FastCGI(xx = php 版本)
  5. 双击它,单击请求限制,然后单击您选择所有动词的“动词”选项卡。这将解决它:-)

回答by gabrielgeo

If you want to be able to retrieve your $_GET variables do not use:

如果您希望能够检索您的 $_GET 变量,请不要使用:

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

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

Instead use:

而是使用:

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

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

回答by Gomes

Here is how I fixed it. open the config file, if the following mapping not exists, put these lines under

这是我修复它的方法。打开配置文件,如果下面的映射不存在,把这些行放在

  <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>

回答by Sunil Kumar

To install IISon your windows, goto control panel -> uninstall programsand press Turn Off Windows Features On/Offlink and click IISand select CGIoption.

IIS在您的 Windows 上安装,请转到control panel -> uninstall programs并按Turn Off Windows Features On/Off链接并单击IIS并选择CGI选项。

enter image description here

在此处输入图片说明

Download Web Platform Installerfrom internet install PHP and SQL drivers for IIS

Web Platform Installer从网上下载install PHP and SQL drivers for IIS

Open IISfrom programs add Website. and for public folder point point to Publicfolder in the laravel/lumen project.

IIS从程序打开添加网站。和公共文件夹点指向Publiclaravel/lumen 项目中的文件夹。

for Laravel and Lumen projects. Create project from composer in any accessible folder. got to publicfolder in the folder structure and create web.configfile with below contents i obtained this from laracasts

用于 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>