How to host a Windows server?

Asked

Viewed 1,968 times

1

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

php artisan serve --host MEUIP --port MEUPORTO

When I test on another computer the browser responds that the page took too long to answer ? What is the correct procedure to host the site ?

Thank you.

1 answer

3


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

  • Select IIS-Webserver:

    WebPlatform IIS-Webserver

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

    WebPlatform php

  • And type "rewrite":

    Rewrite

If you notice a message like this:

PHP is not enabled register new PHP version to enable PHP via FastCGI

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

PHP WebPlatformInstaller


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:

  • 1

    The first part I did when I didn’t have the practical Wizard, but now I only use the second... rs

  • 1

    @Virgilionovic in 2006 when I started playing with Asp.net I was bored of not existing something like Webplatforminstaller and PHP having things like Wamp and Xampp, today fortunately we have it :)

  • 1

    And when it was to install apache with PHP ... trampo da pega!

  • 1

    @Virgilionovic fortunately in PHP when I started there was already Xampp :D

  • When I type %SYSTEMROOT% Inetpub wwwroot says that the C:Winows/Inetpub folder is not available. How to fix ?

  • @Tuber but using what type of installation IIS, IIS Express or webplatform? The %SYSTEMROOT%\inetpub\wwwroot is only for the standard IIS that is usually installed by the operating system itself.

  • I’m using the web Platform.

  • @Tuber which root folder of your IIS?

  • It worked. Thanks.

Show 4 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.