Laravel on IIS

Note: PHP for Windows comes in two flavors, Non Thread Safe (NTS) and Thread Save (TS). If you are using PHP as a FastCGI or CGI executable you need to use the NTS flavor. This is the only flavor you should be using for IIS and NginX. It’s also the preferred way to set up PHP on Apache. Reference

  • Install IIS with default settings and also with Applications\CGI enabled
  • Download the latest NTS (Non Thread Safe) 7.4 64 bit version of PHP - here
    • Unzip PHP Files to a folder C:\Program Files\PHP\
    • Add to above folder to System Path
    • Reboot
    • Rename php.ini-production → php.ini
php_pdo_sqlsrv_74_nts_x64.dll
php_sqlsrv_74_nts_x64.dll
  • Uncomment the line:
    extension_dir = "ext"
  • Uncomment the line:
    extension=openssl
  • Uncomment the line:
    extension=fileinfo
  • Add the following lines at the end of the php.ini file:
; Microsoft SQL for Laravel
extension=php_pdo_sqlsrv_74_nts_x64.dll
extension=php_sqlsrv_74_nts_x64.dll

Note - the installer auto updates the PHP ini file and enables the following two extensions:

extension=curl
extension=mbstring
  • composer global require laravel/installer
  • Create a laravel folder at C:\inetpub\laravel
  • Open a command line Run as Administrator and go to the above folder.
  • Create your laravel project, e.g.
    laravel new <project>
  • Open the folder on command line (run as an administrator)
    • composer require laravel/ui
    • php artisan ui vue --auth
  • After you do this run “npm install && npm run dev” to compile your fresh scaffolding.
    • Download latest stable NPM (e.g. 12.19.0 LTS) here

Summary of Steps

  • Copy your Laravel Project to C:\inetpub\laravel\<projectname>\
  • Give <servername>\IIS_IUSRS full access to the Storage folder
  • Create a virtual Directory for your Default Site to the public folder of your laravel project, e.g.
C:\inetpub\laravel\<projectname>\public\
  • Example:
  • enable full access for the user <servername>\IIS_IUSRS for the laravel storage folder
  • Add the below IIS web.config file to the public folder
web.config
<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>
        <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>
        <httpErrors errorMode="Detailed" />
    </system.webServer>
</configuration>
<?php
phpinfo();
?>
  • code/laravel/iis.txt
  • Last modified: 2021/05/15 20:22
  • by gerardorourke