Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setup laravel 5.4 with IIS 10

Tags:

iis

laravel

I want to deploy laravel projects on our IIS 10, running on windows server 2016. What is the easiest and still secure way to do that?

like image 588
ajthinking Avatar asked Aug 02 '17 14:08

ajthinking


People also ask

Can I deploy Laravel on shared hosting?

Developers opt to deploy Laravel on shared hosting mainly for cost savings. Shared hosting is cheap and is generally preferred by those unaware of its detriments. Similarly, developers generally install and deploy Laravel to shared hosting without considering the problems it causes for the end-users.


1 Answers

This is how I did it; I'm not sure it is the right way.

  • Install URL Rewrite module (https://www.iis.net/downloads/microsoft/url-rewrite)
  • Put repo in some folder E:/sites/helloworld
  • In IIS add a virtual directory called "helloworld" pointing to E:/sites/helloworld/public
  • Make sure folders bootstrap/cache and storage is open for writing.
  • Dont forget to make env file.
  • In your web.php route file put:

    Route::get('/', function () {
        return view('welcome');
    });
    
    Route::get('/also', function () {
        return view('welcome');
    });
    

Add the file web.config in public dir and paste the rules:

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

You should now be able to access both URLs meaning laravel routing works as intended. If you try another non-existent route you will get a laravel exception.

like image 165
ajthinking Avatar answered Oct 22 '22 01:10

ajthinking