How to setup Laravel5 on Azure - Ideas2IT

How to setup Laravel5 on Azure

Share This

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.4
Laravel5 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 `Application Settings` Link. It will list all app settings.
  • Go to `General Settings and choose the `PHP version` and save.

2. Install Composer
Composer 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.).

3. Perform Directory Setup
Directory 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 `wwwroot` 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 ` Application Settings` Link. It will list all app settings.
  • Go to `Virtual applications and directories and provide project folder path as (sitewwwrootpublic)

4. URL Rewriting
Generally, 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"?> 
    <urlCompression doDynamicCompression="true" doStaticCompression="true" dynamicCompressionBeforeCache="true"/>
      <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" />
      <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" />
        <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" />
          <action type="Rewrite" url="index.php" appendQueryString="true" />

Leave a Reply

Your email address will not be published. Required fields are marked *

Get Instant Pricing Straight to Your Inbox

Let us know what your needs are and get a quote sent straight to your inbox.

Thanks for subscribing

Get Pricing Sent Straight to Your Inbox