setting up laravel on IIS7

对着背影说爱祢 提交于 2019-12-18 01:20:14

问题


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

I found something similar for CI (link)

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

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

anybody uses/d IIS7 with Laravel?

thanks in advance


回答1:


I created the web.config file in root folder inside <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.php file of the public folder into the root folder of the project modifying the ../paths.php into paths.php as this guide says

now everything works perfectly




回答2:


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.

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


Check your Handler Mappings in 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 :-)



回答4:


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>



回答5:


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

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

That's it, Happy Lavarel!

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




回答6:


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

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

Instead use:

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




回答7:


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>



回答8:


To install IIS on your windows, goto control panel -> uninstall programs and press Turn Off Windows Features On/Off link and click IIS and select CGI option.

Download Web Platform Installer from internet install PHP and SQL drivers for IIS

Open IIS from programs add Website. and for public folder point point to Public folder in the laravel/lumen project.

for Laravel and Lumen projects. Create project from composer in any accessible folder. got to public folder in the folder structure and create web.config file with below contents i obtained this from 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> 


来源:https://stackoverflow.com/questions/14381950/setting-up-laravel-on-iis7

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!