question

ZackWhedbee-8830 avatar image
0 Votes"
ZackWhedbee-8830 asked ajkuma-MSFT commented

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

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://docs.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-webapps-content-deployment
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

ajkuma-MSFT avatar image
0 Votes"
ajkuma-MSFT answered ajkuma-MSFT commented

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

· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

ZackWhedbee-8830, Also, you could configure startup command. Note that the PHP 8 images (vs 7.4) are defaulted to nginx/php-fpm. So you will not need .htaccess, but not rewrite rules to mimic .htaccess.

Convert Apache Rewrite Rules to NGINX Rewrite Rules | NGINX is a good point to start.

Just to highlight further, You may configure the startup command to use Apache however the nginx/php-fpm* is the default for PHP 8. You could utilize rewrite rules that mimic .htaccess, check out.
Customize Start-up - To customize the site root, set the virtual application path for the app by using the az resource update command


0 Votes 0 ·