Deploy a PHP project to Azure without putting everything in the web root

Zack 1 Reputation point
2021-08-26T18:41:40.487+00:00

I have a web site written in PHP that I am migrating to Azure. Currently I'm using Namecheap for hosting. My current set up is that I have two main folders in the project: public_html contains all the public facing HTML/PHP/etc files and resources which is not public-facing and contains my composer.json, misc helper PHP files, etc, etc. I maintain the project using git, and I have the repo cloned on the namecheap server with the public_html folder set as the web root of my site.

I used the following guide to help me set things up on Azure. (https://learn.microsoft.com/en-us/azure/app-service/quickstart-php?pivots=platform-linux) Basically I set up the azure server as a remote on my dev machine, and then when I've made changes to the dev machine I can just call git push azure main and it'll deploy the code to the new azure set up. The issue I'm having is that I can't specify a different web root in Azure and it also needs to have the composer.json file in the root dir of the repo for it to build. So I have to move composer.json up a directory and reorganize things a bit, which works, but now all that stuff that was in the resources directory is exposed when I don't want it to be.

Is there a way I can deploy to azure without putting everything in the web root or a different strategy I should be using to organize my project files?

Azure App Service
Azure App Service
Azure App Service is a service used to create and deploy scalable, mission-critical web apps.
8,930 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. ajkuma 28,036 Reputation points Microsoft Employee Moderator
    2021-08-28T20:28:05.487+00:00

    ZackWhedbee-8830 Typically, either you could .htaccess method or build your own containers for customization, to enable something that is a default web server setting vs otherwise.
    For example, if it’s Laravel App, you may set the virtual application path for the app. Laravel application lifecycle begins in the public directory instead of the application's root directory. Yes, as you stated, by default, Azure App Service points the root virtual application path (/) to the root directory of the deployed application files (sites\wwwroot).

    Just to highlight further, the deployment process installs Composer packages at the end. App Service does not run these automations during default deployment, so this sample repository has three additional files in its root directory to enable it:

    .deployment - This file tells App Service to run bash deploy.sh as the custom deployment script.
    deploy.sh - The custom deployment script. If you review the file, you will see that it runs php composer.phar install after npm install.
    composer.phar - The Composer package manager.

    Based on your requirement, you may use custom Deployment Script. You can use this approach to add any step to your Git-based deployment to App Service.
    For more information, see Custom Deployment Script - https://github.com/projectkudu/kudu/wiki/Custom-Deployment-Script


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.