question

Christopher-7716 avatar image
1 Vote"
Christopher-7716 asked ajkuma-MSFT commented

Deploying an App Service with Laravel 8 and PHP 8 is not possible due to fixed document root

When using the Azure App Service with a PHP 7.x Runtime Stack, .htaccess files could be used to point Apache's DocumentRoot to the public/ directory (absolute: /home/site/wwwroot/public). This is required for e.g. Laravel-based applications.
With the new PHP 8.0 Runtime Stack, Apache has been replaced with nginx. As nginx does not support the usage of .htaccess files, the document root can not be changed. As I am required to use PHP 8, my application can no longer be deployed.

  • I've tried to change the /etc/nginx/sites-available/default configuration with help of Start options and sed but this did not work due to quoting issues.

  • Using a custom kudu .deployment script does also not work as kudu is not able to access the full Docker environment (e.g. service restart nginx does not work).



azure-webappsazure-webapps-content-deploymentazure-app-configuration
· 8
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.

@Christopher-7716,

Yes, Linux PHP v8 blessed images are defaulted to nginx/php-fpm. You may configure it using startup command. You will not need .htaccess, instead you may try with the rewrite rules to mimic .htaccess (If you haven't done this already).

You may take a look at this third party blog to know - Convert Apache Rewrite Rules to NGINX Rewrite Rules | NGINX


Just to highlight on configuring startup command, doc Azure App Service on Linux FAQ | expected values for the startup file

If your requirement fits, you could deploy your Laravel application with a custom Docker image as well.

Kindly let us know how it goes, I'll follow-up with you further.


0 Votes 0 ·

Thanks for the reply.

I've fixed the deployment and written up a short article at https://www.schakko.de/2021/09/08/deploying-php-8-0-applications-with-azure-app-service/ in case anyone stumbles upon this issue.

1 Vote 1 ·

Thanks Christopher, we are fighting for days on this issue, too.

1 Vote 1 ·
ajkuma-MSFT avatar image ajkuma-MSFT Christopher-7716 ·

@Christopher-7716, To benefit the community will add the blog steps as an answer. Thanks for your co-operation and patience.

1 Vote 1 ·
ajkuma-MSFT avatar image ajkuma-MSFT Christopher-7716 ·

@Christopher-7716, Thanks for sharing the solution and your blog on this with the community. +@MuratBozacioglu-9377, Apologies for any inconvenience with this issue.

I have shared your feedback with the product engineering team on this and will also work with the content author to update the Azure docs appropriately.

Also, we have a blog on this:
Configuring NGINX Rewrite Rules for Azure App Service blessed images running PHP 8.x

Intro:
Azure App Service on Linux images using PHP 8.x are now bundled with NGINX instead of Apache. The use of .htaccess files will not work for NGINX as these are used for Apache only. This will require the need to setup a custom startup script and modifying the existing NGINX site configuration.

Steps

Navigate to your App Service via the Azure Portal. Under the Development Tools section, select SSH then Go.


Modifying the default site config

You will want to make a copy of the existing configuration and place the file inside the /home/site directory.

 cp /etc/nginx/sites-available/default /home/site/default

Once copied, edit the /home/site/default file and update the section below:

server {

 # Section Excluded

 location / {
     index  index.php index.html index.htm hostingstart.html;
     try_files $uri $uri/ /index.php?$args;
 }

 # Section Excluded

}


Then, Create the custom startup script and Updating the application settings as outlined in the blog section.

0 Votes 0 ·
Show more comments
renoirtech avatar image renoirtech Christopher-7716 ·

Thank you! Solved for me.

The only thing that i had to tackle was that my /home/site/repository folder is empty.

How do i add the startup script in it?

0 Votes 0 ·
Show more comments

1 Answer

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

To benefit the community, adding an answer from the discussions on the comments section.

Thanks to @Christopher-7716 for sharing the solution that worked on a blog (detailing the steps to fix): Deploying PHP 8.0 applications with Azure App Service

Also, adding steps from the App Service blog : NGINX Rewrite Rules for Azure App Service Linux PHP 8.x

Intro

Azure App Service on Linux images using PHP 8.x are now bundled with NGINX instead of Apache. The use of .htaccess files will not work for NGINX as these are used for Apache only. This will require the need to setup a custom startup script and modifying the existing NGINX site configuration.

Steps

Navigate to your App Service via the Azure Portal. Under the Development Tools section, select SSH then Go -->.

Modifying the default site config

You will want to make a copy of the existing configuration and place the file inside the /home/site directory.


   cp /etc/nginx/sites-available/default /home/site/default

Once copied, edit the /home/site/default file and update the section below:

 server {
    
     # Section Excluded
    
     location / {
         index  index.php index.html index.htm hostingstart.html;
         try_files $uri $uri/ /index.php?$args;
     }
    
     # Section Excluded
 }

Creating the custom startup script


You will now need to create a custom startup script and save the file as /home/site/startup.sh

 #!/bin/bash
    
 cp /home/site/default /etc/nginx/sites-available/default
 service nginx reload

In the custom startup script we are doing the following:

  1. Overriding the existing /etc/nginx/sites-available/default file with the /home/site/default file.

  2. Reloading the NGINX service to make the updates take effect.


Updating the application settings

  1. Navigate back to your App Service via the Azure Portal. Under the Settings section, select Configuration.

  2. Go over to the General Settings section of the Configuration blade.

  3. For the Startup Command enter the following: /home/site/startup.sh

  4. Save these settings and navigate to your application https://{sitename}.azurewebsites.net/


Apologies for any inconvenience with this. I have relayed the feedback to our content team to update the docs as appropriate.

Thanks for your patience and great collaboration.

· 2
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.

Hi @ajkuma-MSFT,

This solution needs a human interference via SSH to put the startup.sh into /home/site/startup.sh, is it correct?

I feel that the best scenario is to deploy this startup.sh along with the app source code and then explore some deployment feature that copies it to the best place to being executed by Azure App Service startup command.

Is it possible? What do you think about it?

I would like to extend the discussion to @Christopher-7716 too.

Its being quite awesome to learn this together with you.

0 Votes 0 ·

renoirtech, Glad you found the information helpful.

Apologies for the delay! You have an option to create a custom startup script when using our provided (commonly referred to as ‘blessed’) images for PHP.
You’ll need to use a shell script if you intend to make any adjustments to the blessed image.
These commands or scripts are executed after the built-in Docker container is started, but before your application code is started.

You can control the container's startup behavior by providing either a custom startup command or multiple commands in a startup command file..

Instead of using a startup command file, you can put the startup command itself directly in the Startup Command field on the Azure portal. Using a command file is preferable, however, because this part of your configuration is then in your repository where you can audit changes and redeploy to a different App Service instance altogether.

0 Votes 0 ·