'How do I set the default document of an Azure App Service when it exists in a subdirectory?

I am deploying an Azure App Service from Azure DevOps via a release pipeline that is configured to perform an Azure App Service Deploy task on my build agent. The deploy task targets the root of my App Service, so it will be deployed in my '\site\wwwroot\' folder.

Azure DevOps release pipeline configuration

My project is a Laravel PHP web application, so the default document is set to 'index.php'. My application is deployed to '\site\wwwroot\', but the location of my 'index.php' file that is set to the default document however is in '\site\wwwroot\'.

Azure App Service Application Settings for default document and virtual application directories

Not a big problem, right? Just set the application directory to '\site\wwwroot\public' and the app works because it can now find my default document (index.php). Except there's one problem.

When Azure DevOps deploys to an Azure App Service, it is going to deploy to the application directory that you set in Azure. Because my root is set to '\site\wwwroot\public' now to correct the issue with finding the default document, AzureDevops is deploying subsequent builds to the '\site\wwwroot\public' folder.

Ideally, I would like to keep my 'index.php' file within my '\site\wwwroot\public' folder, as it causes issues when I move it to the root of my project. I can't seem to figure out how to tell Azure to look in my public folder for the default document. Do I need to write a web.config and place it in my project root for IIS to find it?


Update:

I'm still attempting to resolve this issue I am having. I am not able to configure Azure or Azure DevOps to differentiate between the directory that my app is deployed to, and the directory that my application is served from.

I cannot simply create two virtual applications, as that would expose my root directory to that endpoint. I need to be able to simply instruct Azure DevOps where to place my application on the Web App.



Solution 1:[1]

Since it works fine after setting application directory to '\site\wwwroot\public', so you can add a new virtual application with 'site\wwwroot\public' physical path instead of change the original one.

Then, there are two items, for example:

enter image description here

Regarding deploy through Azure DevOps, just deploy app to that app service (site\wwwroot).

After that, you can access you app through [app service url]\PHP.

Solution 2:[2]

You are capable of specifying the location where source code is deployed to from Azure DevOps (or Git, BitBucket, etc.) by providing your Azure App Service with a Kudu environment variable. Please see the following environment variables configured in the 'Application Settings' section of the Azure Portal for my Azure App Service.

Environment variable configured for the source code management path (SCM_REPOSITORY_PATH and SCM_TARGET_PATH Kudu variables)

This allows me to instruct where the code is deployed. Otherwise, it appears that Kudu's default source code management path is taken from your Virtual application paths.

Further reading: https://github.com/projectkudu/kudu/wiki/Deploying-inplace-and-without-repository


Update:

It appears that while you are capable of configuring the location that your code is deployed using the Kudu environment variables, you are still limited to the folder name of your Virtual Application.

For instance, if I set the SCM_TARGET_PATH to \home\sites\app, and I have a virtual application with a virtual path of / and a physical path of \home\sites\app\public, Azure DevOps will deploy your code into \home\sites\app\public and not the expected \home\sites\app.

This is a huge inconvenience, I cannot host my Laravel application because my continuous deployment will not work the way Azure currently works. I would have to publish my code to a Docker container and use that instead (which I don't want to do).

Solution 3:[3]

  • Renaming the server.php to index.php
  • Copy the .htaccess from public folder to root folder

  • Changing .htaccess :

    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)/$ /$1 [L,R=301]
    
    RewriteCond %{REQUEST_URI} !(\.css|\.js|\.png|\.jpg|\.gif|robots\.txt)$ [NC]
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
    
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_URI} !^/public/
    RewriteRule ^(css|js|images)/(.*)$ public/$1/$2 [L,NC]
    

change to function /Illuminate/Foundation/helpers.php/asset() function as follows:

function asset($path, $secure = null)
{
    return app('url')->asset("public/".$path, $secure);
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 starian chen-MSFT
Solution 2
Solution 3