Deploy laravel project with Azure kudu

Sam Montgamery 20 Reputation points
2025-06-11T10:28:22.7266667+00:00

I am currently deploying a laravel project with Azure app service.

Code is on Azure repository and I set up pipeline to deploy it to Azure App Service.

When it's done, I checked the site and saw default "hostingstart.html" page.
So I wrote nginx.conf and startup.sh to the code directory and add startup command to run startup.sh file in configuration.

But the result is 502 error.

server {
    listen 8080; # or the port your App Service uses

    root /home/site/wwwroot/public; # Point to your Laravel public directory

    index index.php index.html index.htm hostingstart.html;

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

    location ~ \.php$ {
        # FastCGI setup for PHP
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_pass unix:/var/run/php-fpm.sock; # Path to PHP-FPM socket
    }
}
cp /home/site/wwwroot/nginx.conf /etc/nginx/sites-available/default  # Copy your custom Nginx configuration
service nginx reload # Reload Nginx to apply changes

User's image

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

Accepted answer
  1. Prabhavathi Manchala 2,315 Reputation points Microsoft External Staff Moderator
    2025-06-12T09:04:25.76+00:00

    Hi Sam Montgamery,

    Looking at your screenshots, I can see the exact issue and will provide you with a step-by-step solution.

    From your screenshots, I can see:

    • Your App Service is configured correctly - You have PHP 8.2 selected as the runtime
    • Your Laravel files are deployed - I can see all the Laravel directories (app/, public/, vendor/, etc.) in your wwwroot folder
    • The startup.sh file exists - It's listed in your directory
    • But you're getting a 502 error - This is because your custom nginx.conf is conflicting with Azure's built-in web server

    The problem is you're trying to change the Nginx setup, which isn't needed on Azure App Service.

    Please follow the solution step by step to fix the issue.

    Step 1: Remove the custom nginx.conf override

    Your current startup.sh is copying a custom nginx.conf, which is causing the conflict. We need to change this approach.

    Delete or rename your current nginx.conf file from the root directory, as Azure App Service doesn't use nginx with PHP-FPM sockets the way you've configured it.

    Step 2: Update your startup.sh file

    Replace the content of your startup.sh file with this:

    #!/bin/bash
    cd /home/site/wwwroot
    
    # Install dependencies
    composer install --no-dev --optimize-autoloader
    
    # Set proper permissions
    chmod -R 755 storage bootstrap/cache
    
    # Clear and cache configurations
    php artisan config:clear
    php artisan config:cache
    php artisan route:cache
    php artisan view:cache
    
    # Create storage link if it doesn't exist
    php artisan storage:link
    

    Step 3: Configure document root for Laravel

    Since Laravel needs the /public folder as the document root, you need to add this configuration:

    1. Go to your App Service Configuration
    2. Click on Path mappings tab
    3. Add a new Virtual Application:
      • Virtual path: /
      • Physical path: site\wwwroot\public
      • Check Application

    Step 4: Set environment variables

    In your App Service Configuration → Application settings, add your Laravel environment variables:

    • APP_ENV = production
    • APP_DEBUG = false
    • APP_KEY = (your Laravel app key)
    • Add your database and other environment variables

    Step 5: Ensure your .env file is properly set

    Make sure your .env file in the root directory has the correct production settings.

    Azure App Service uses Apache (not Nginx) for PHP apps, so you can’t change Laravel’s root folder using Nginx settings. Instead, use path mappings to point to the /public folder. The startup command should only run Composer and Laravel setup commands, not change the server settings.

    Laravel Deployment Documentation

    Please accept as "Yes" if the answer provided is useful, so that you can help others in the community looking for remediation for similar issues.

    Let me know if you have any further Queries.

    1 person found this answer helpful.
    0 comments No comments

0 additional answers

Sort by: Most helpful

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.