Deploying Laravel 4 on Azure

Laravel is brilliant framework that can be deployed with very little effort on most platforms, however Azure causes a few issues. My advice would be to avoid Azure, if possible, and use Fortrabbit or a similar PHP as a Service provider.

NB: Getting Composer to work on Azure is confusing so for this tutorial I’m assuming you store all your vendor files in version control.

1) Set Azure to deploy to root folder (not wwwroot)
Azure by default will deploy to the wwwroot folder although Laravel requires its core files outside of public folder. In the Azure Control Panel click on the Configure tab under your website and scroll down to the app settings section. You’ll need add two values:

SCM_REPOSITORY_PATH = ..\repository
SCM_TARGET_PATH = ..

app-setting-azure-blog-post

2) Rename Laravel’s public folder to wwwroot
Open your Laravel project and rename the public folder to wwwroot. Now you need to tell Laravel its been changed. Find the file: bootstrap/paths.php

Look for the public path line which is normally on line 29 and change it to:

'public' => __DIR__.'/../wwwroot',

3) Add a web.config
Azure doesn’t use .htaccess, so we need to add a web.config file inside the wwwroot folder, which tells incoming traffic to be passed though index.php. This is how Laravel handles routing, similar to WordPress and many other frameworks. Here is a sample web.config you can use:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <system.webServer>
        <urlCompression doDynamicCompression="true" doStaticCompression="true" dynamicCompressionBeforeCache="true"/>
        <staticContent>
            <remove fileExtension=".svg" />
            <mimeMap fileExtension=".svg" mimeType="image/svg+xml" />
            <mimeMap fileExtension=".woff" mimeType="application/font-woff" />
            <clientCache httpExpires="Sun, 29 Mar 2020 00:00:00 GMT" cacheControlMode="UseExpires" />
        </staticContent>
        <httpProtocol>
            <customHeaders>
                <add name="Strict-Transport-Security" value="max-age=31536000; includeSubDomains"/>
                <add name="Access-Control-Allow-Origin" value="*" />
                <add name="Access-Control-Allow-Headers" value="X-Requested-With,Content-Type" />
                <add name="Access-Control-Allow-Methods" value="POST,GET,OPTIONS,DELETE,PUT,PATCH" />
            </customHeaders>
        </httpProtocol>
        <rewrite>
            <rules>
                <rule name="Laravel4" stopProcessing="true">
                    <match url="^" ignoreCase="false" />
                    <conditions logicalGrouping="MatchAll">
                        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
                        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
                    </conditions>
                    <action type="Rewrite" url="index.php" appendQueryString="true" />
                </rule>
            </rules>
        </rewrite>
    </system.webServer>
</configuration>

4) Deploy!
Now you can set up a deployment from Github/Bitbucket or whichever version control you use. On the Azure Control Panel simply select Set up deployment from source control.