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

Christopher 26 Reputation points
2021-09-07T15:22:50.28+00:00

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 App Configuration
Azure App Configuration
An Azure service that provides hosted, universal storage for Azure app configurations.
209 questions
Azure App Service
Azure App Service
Azure App Service is a service used to create and deploy scalable, mission-critical web apps.
6,960 questions
{count} vote

1 answer

Sort by: Most helpful
  1. ajkuma 22,521 Reputation points Microsoft Employee
    2021-09-09T09:30:24.147+00:00

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

    Thanks to @Christopher 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.