Probably intend to use IIS being Windows Server, in case you might have installed one of these programs:
- IIS "standard"
- IIS Express
- Webplatforminstaller
If it is standard IIS or IIS Express
If you are using Webplatforminstaller do not do this following procedure.
First install the PHP:
Download into http://windows.php.net/download/
And install in the folder %SYSTEMROOT%\php
(examples c:\php
or d:\php
)
Steps to install PHP in standard IIS
After installing PHP, navigate to %windir%\System32\inetsrv\config\
and then edit the applicationHost.config
and then add something like (editing existing sites within config):
<defaultDocument enabled="true">
<files>
<add value="index.php" />
<add value="Default.htm" />
<add value="Default.asp" />
<add value="index.htm" />
<add value="index.html" />
<add value="iisstart.htm" />
</files>
</defaultDocument>
<fastCgi>
<application
fullPath="C:\php\php-cgi.exe"
monitorChangesTo="C:\php\php.ini"
activityTimeout="300"
requestTimeout="300"
instanceMaxRequests="10000"
>
<environmentVariables>
<environmentVariable name="PHPRC" value="C:\php\" />
<environmentVariable name="PHP_FCGI_MAX_REQUESTS" value="10000" />
</environmentVariables>
</application>
</fastCgi>
And then add this inside handlers
:
<handlers accessPolicy="Read, Script">
<add
name="PHP_via_FastCGI"
path="*.php"
verb="*"
modules="FastCgiModule"
scriptProcessor="C:\php\php-cgi.exe"
resourceType="Either"
/>
After installed type this in the run: %SYSTEMROOT%\inetpub\wwwroot
and you can install Laravel inside it, it can be a folder or directly in the folder wwwroot
.
Steps to install PHP in IIS Express
Download
Installing PHP and IIS Express
Install PHP in a folder like C:\php
Change fullPath='"C:\php\php-cgi.exe"'
and scriptProcessor='"C:\php\php-cgi.exe"
by the way that made the installation
If you have installed IIS x64:
cd C:\Program Files\IIS Express\
If you have installed IIS x86:
cd C:\Program Files (x86)\IIS Express\
Then type:
appcmd set config /section:system.webServer/fastCGI /+[fullPath='"C:\php\php-cgi.exe"']
appcmd set config /section:system.webServer/handlers /+[name='PHP_via_FastCGI',path='*.php',verb='*',modules='FastCgiModule',scriptProcessor='"C:\php\php-cgi.exe"',resourceType='Unspecified']
Editing the applicationhost.config
If you have repeated entries as for the PHP_via_FastCGI
cd %userprofile%\Documents\IISExpress\config
notepad.exe applicationhost.config
Or using Sublimetext or Notepad++ or another editor select something like File > Open File
%userprofile%\Documents\IISExpress\config\applicationhost.config
And look again:
<add name="PHP_via_FastCGI" path="*.php"
Installing PHP with Webplatforminstaller
This is the only one that does not follow the above steps, because the installation is almost all automated and in my view the easiest path of all
Download
Download the Webplatforminstaller:
Installing the IIS
If you notice a message like this:
Then click on Register new PHP version
and navigate to the folder where you installed PHP, after selecting it should look like this:
All suggestions here are for any application written in PHP, not just Laravel
Setting up the Laravel
After placing the Laravel in the desired folder you should move content from the folder of your project to the "root" folder of your IIS (if it is default IIS it should be the wwwroot
) and create within the folder a file called web.config
with this content:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<defaultDocument>
<files>
<clear />
<add value="index.php" />
</files>
</defaultDocument>
<rewrite>
<rules>
<rule name="Laravel Force public">
<match url="(.*)" ignoreCase="false" />
<action type="Rewrite" url="public/{R:1}" />
</rule>
<rule name="Laravel Routes" stopProcessing="true">
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<match url="^" ignoreCase="false" />
<action type="Rewrite" url="public/index.php" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
Chance that there is no
Laravel in production environment
Note that when using the Standard for production you should turn off the DEBUG by changing the .env
, then change this:
APP_ENV=local
APP_DEBUG=true
for this reason:
APP_ENV=production
APP_DEBUG=false
Sources:
Is using IIS?
– Guilherme Nascimento