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