How to host a laravel site on windows server?

1

The computer where I want to host the site developed in laravel is in another network. I put the whole site on the server and ran the command

php artisan serve --host MEUIP --port MEUPORTO

When I test on another computer does the browser respond that the page took a long time to respond? What is the correct procedure for hosting the laravel site on another machine?

Thank you.

    
asked by anonymous 19.08.2017 / 18:33

1 answer

2

You probably want to use IIS being Windows Server, in case you might have installed one of these programs:

  • IIS "default"
  • IIS Express
  • WebPlatformInstaller

If it's IIS default or IIS Express

If you are using WebPlatformInstaller do not do this following procedure. First install PHP:

Download at link And install it in the %SYSTEMROOT%\php folder (examples c: \ php or d: \ php)

IIS default

After installing PHP, navigate to %windir%\System32\inetsrv\config\ and then edit applicationHost.config and then add something like (by editing the existing places inside the 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 within handlers :

<handlers accessPolicy="Read, Script">
    <add
        name="PHP_via_FastCGI"
        path="*.php"
        verb="*"
        modules="FastCgiModule"
        scriptProcessor="C:\php\php-cgi.exe"
        resourceType="Either"
    />

After installing

Once 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 wwwroot folder.

IIS Express

Download

Installing PHP and IIS Express

Install PHP into a folder as C:\php

Change fullPath='"C:\php\php-cgi.exe"' and scriptProcessor='"C:\php\php-cgi.exe" to the path 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 such as PHP_via_FastCGI

cd %userprofile%\Documents\IISExpress\config
notepad.exe applicationhost.config

Or by using SublimeText or Notepad ++ or another editor select something like File > Open File

%userprofile%\Documents\IISExpress\config\applicationhost.config

And look for repeats:

<add name="PHP_via_FastCGI" path="*.php"

WebPlatformInstaller

  

This is the one that does not follow the steps above, because the installation is almost all automated and in my view the easiest path of all

Download

Download WebPlatformInstaller:

Installing IIS

  • Select IIS-Webserver:

  • Type"php" and install the desired versions except Express, for example:

  • Andtype"rewrite":

Ifyounoticeamessagelikethis:

Then click on Register new PHP version and navigate to the folder where you installed PHP, after selecting it should look like this:

ConfiguringLaravel

Afterplacingthefileinthefolderyouwant,youshouldmovethecontentsofyourprojectfoldertotherootfolderofyourIIS(ifitisthedefaultIISitshouldbewwwroot)andcreateafilenamedweb.configwiththiscontent:

<?xmlversion="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>

Does not exist

Laravel in production environment

Note that when using laravel for production you should turn off DEBUG by changing .env , then change this:

APP_ENV=local
APP_DEBUG=true

for this:

APP_ENV=production
APP_DEBUG=false

Sources:

19.08.2017 / 18:40