Get Your Copy of The CXO's Playbook for Gen AI: Practical Insights From Industry Leaders.  Download Now >
Back to Blogs

How to setup Laravel5 on Azure

Laravel has become a leading PHP framework because of its many significant features. When deploying to Azure, there are a few nuances. Here we attempt to cover them.Steps for Laravel on Azure:

  • Install PHP version >= 5.4
  • Install Composer
  • Perform Directory Setup
  • URL Rewriting

1. Install PHP version >= 5.4Laravel5 requires PHP version >= 5.4. Azure provides an option to install the needed PHP version as per our project. To change the PHP version in Azure, follow the below steps

  • Log into Azure, and click the web service link. It will list all settings under your web service.
  • Go to `SETTINGS` and click the `Application Settings` Link. It will list all app settings.
  • Go to `General Settings and choose the `PHP version` and save.
Install PHP version >= 5.4

2. Install ComposerComposer is an important package manager in PHP. It is mainly used with Laravel for package management. A composer can be easily installed on Azure via its extension manager.

  • Click your web service link. It will list all settings under your web service.
  • Go to `DEVELOPMENT TOOLS` and click on `Extensions`.
  • Click on the `add` link and select the option `Choose Extension`. It will list all Extensions related to your web service.
  • Select Composer from the list and do the installation process (you must agree to the license etc.).
Install Composer

3. Perform Directory SetupDirectory setup is an important process in Laravel projects. Laravel lifecycle always starts from the file `public/index.php`. Azure deploys everything you push into the `www root` directory.To change the project start up point in Azure, follow the below steps:

  • Click your web service link. It will list all the settings under your web service.
  • Go to `SETTINGS` and click the ` Application Settings` Link. It will list all app settings.
  • Go to `Virtual applications and directories and provide project folder path as (sitewwwrootpublic)
Perform Directory Setup

4. URL RewritingGenerally, if we type an invalid URL on a laravel based site, we get redirected to 404 page.This occurs because of URL mod_rewrite rule.Laravel assumes that it is dealing with an Apache Web-Server, therefore it processes the mod_rewrite rules specific to that.But Azure Web Apps use Microsoft's IIS.Hence, we need to include the below-mentioned changes for URL rewriting.Create a new file called web.config in public directory with the below content.<?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="Mon, 30 Mar 2020 00:00:00 GMT" cacheControlMode="UseExpires" />
</staticContent>
<handlers>
<remove name="OPTIONSVerbHandler" />
<remove name="PHP54_via_FastCGI" />
<add name="PHP54_via_FastCGI" path="*.php" verb="GET,HEAD,POST,OPTIONS" modules="FastCgiModule" scriptProcessor="D:Program Files (x86)PHPv5.4php-cgi.exe" resourceType="Either" />
</handlers>
<rewrite>
<rules>
<rule name="Laravel5" 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>


About Ideas2IT,Are you looking to build a great product or service? Do you foresee technical challenges? If you answered yes to the above questions, then you must talk to us. We are a world-class custom .NET development company. We take up projects that are in our area of expertise. We know what we are good at and more importantly what we are not. We carefully choose projects where we strongly believe that we can add value. And not just in engineering but also in terms of how well we understand the domain. Book a free consultation with us today. Let’s work together.

Ideas2IT Team

Connect with Us

We'd love to brainstorm your priority tech initiatives and contribute to the best outcomes.