How to deploy a Laravel 5.4 (PHP) Application to Microsoft Azure WebApp service
You’ve certainly noticed it, there was just a little silence.
This is mainly due to the change of my employer, after 20 years in an energy company, it has left me in a smaller german “Startup” (ZENNER IoT Solutions), which is costs me some time at the moment (which is completely OK for me!) — what we do? Building a great IoT Platform!
There we are happy to participate in the Microsoft BizSpark program,
which means some resources, such as testing Microsoft’s Azure Cloud.
Now my task was to bring a PHP application based on the Laravel 5.4 fFramework to a web app from Microsoft. Microsoft WebApps are their PaaS offer when it comes to hosting .. Surprise: Web applications.
The base of the WebApps is an iiS server, which makes the whole story a bit more complex than deploying to a 08/15 Apache with PHP .. the iiS is more suitable for Microsoft’s languages like ASP.NET etc. Well, however, nothing is impossible. Here is a short story on how to deploy a Laravel App to Microsoft Azure WebApp Service (Spoiler: It runs very well, if it runs!).
Let’s assume that your application is finished, and you have already set up
an Azure WebApp (which is trivial). Now we have to do some preparations.
PHP Setting for the Azure WebApp
Let ‘s start with a new PHP version for our WebApp. Fortunately, Microsoft supports PHP 7.1, which we also now select in the Applications — Settings.
Configure the Azure WebApp for Laravel
Further on the same page, here a few variables we have to set, so that Azure plays well with Laravel.
- SCM_REPOSITORY_PATH to: ..\repository
- -SCM_TARGET_PATH to: ..
Now it is time to change the entry point to our website, the default for Azure is “/site/index.html”, but Laravel want’s : “site/public”. But hey we can also do this on the same page.
The matching counterpart to the Apache .htaccess, is the iiS “web.config” file, fortunately Laravel ships with a default one, we can use for our application. So no work for us.
Composer extension for WebApp
The settings now fit, what makes life even easier for us is an extension that you can simply activate, so you make sure that “composer” is executed during the deployment and you do not have to do this manually.
Deployment “pipeline” for our Azure WebApp
The last step: Somehow we must get our application to Azure. Personally, I prefer the deployment via GIT, we clone some kind of a local repository and copy our code into it. After a short “git push” we are online, Hooray.