Developing software in the Real World

Running PHP applications on Azure App Engine

Azure App Service is a way to host your web application in a container without having to think about the server. It’s the same PaaS concept as AWS Elastic Beanstalk and supports all the main web programming languages. It also supports Windows and Linux OS containers.

I have a client that is moving an on-premises PHP application to App Service and so have been looking at what I needed to do to deploy it there.

To get started, Azure have a couple of great tutorials for Linux and Windows with which I got a basic app running in no time, so I could turn my attention to the specifics I cared about.

Database drivers

My app uses SQL Server, so I was pleased to see that both the Windows and Linux PHP containers have the sqlsrv extension installed. However, there’s a bug today where the Linux container is missing the ODBC driver, so SQL Server support doesn’t actually work on the Linux container. This should be fixed in July apparently.

Both containers also support PostgreSQL and MySQL, so the databases I care for are covered.

Rewriting all URLs to index.php in the public directory

In common with many PHP applications, I have a public directory where the files to be served by the web server are kept and my PHP and other source files are elsewhere. I also use rewriting to map all URLs to my public/index.php file.

The way we handle this depends on the container.

Windows container

On the Windows container, we need to change the path mapping so that the public directory is mapped to the /. This can be done in the web portal in Configuration -> Path mappings where by default the / virtual path is mapped to site\wwwroot physical path. Edit this so that it points to site\wwwroot\public. I’m not a fan of web-based tooling for things like this as it’s error-prone. Azure provides a command line tool, so we can make the same path mapping change with:

(Change {Resource Group} and {App Service} to the correct names for your installation.)

Now that we’re serving from /public, we can now add the rewrite rule. With IIS, we use a web.config file:


quot; />
<conditions logicalGrouping=”MatchAll”>
<add input=”{REQUEST_FILENAME}” matchType=”IsFile” negate=”true” />
<add input=”{REQUEST_FILENAME}” matchType=”IsDirectory” negate=”true” />
<action type=”Rewrite” url=”index.php” />

Linux container

On Linux, the container runs Apache, so we can rewrite the URL to public/index.php with a single .htaccess file in our root directory:


Two rewrite rules are required: firstly we rewrite static files so that the continue to be served by Apache and then we rewrite everything else to index.php.

Environment variables

Environment variables are a common way to set per-installation configuration and this is done vie the portal or the command line:


Running a PHP application on Azure App Engine with either the Windows or Linux container is much the same as on any other hosting and seems to work well.

4 thoughts on “Running PHP applications on Azure App Engine

  1. I've tested extensively the two approaches and it doesn't work well. The main issue is the very low I/O speed you get in those solutions. If you need to do any kind of file operation, even just storing them and then upload to a CDN it won't work properly. Most SD cards today can outperform (by far) the Azure App Service.
    There's even a MS/Azure page somewhere talking about this limits.

  2. What about a automated deployment? If you try to deploy via devops all files will get copied to site\wwwroot\public instead of site\wwwroot\public.
    Quite a problem if you have other folders you need to update on the same level as 'public' like 'config'.

    The only solution I came across is to run 'az resource update' twice – once before and once after the deployment…

  3. Azure App Engine for Linux/PHP is poorly designed because you can't set the www root path. You have to use the slow windows persisted mounted 'SMB' drive for the wwwroot. Why there isn't an option for the wwwroot to be attached to the quick epmhereal drive is just beyond me. So your web apps are always slow as it relives on SMB! You can try symlinking to ephemreal but then your app will stop working on any form of update. You could build your own Docker image with the wwwroot mounted somewhere sane and try and config in a non SMB drive. But the better option is to just use AWS.

Thoughts? Leave a reply

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