0

I have a very simple PHP application that I need to deploy to Azure Web App. Someone already created the Web App in a prod environment, my task is to create an Azure DevOps pipeline to deploy to a staging slot.

- task: AzureWebApp@1
  inputs:
  azureSubscription: $(subName)
  appType: 'webAppLinux'
  appName: $(appName)
  package: '$(Build.ArtifactStagingDirectory)/project.zip'
  runtimeStack: 'PHP|8.2'
  startUpCommand: 'service nginx restart'
  slotName: 'staging'
  deployToSlotOrASE: true

After ran the pipeline, everything is deployed in the staging slot as expected but the nginx service disappear. I have no idea why this is happening.

Steps to reproduce:

  1. Use FTP to download every code from the Azure Web App and commit to a repo
  2. Create a slot named staging copying all config from the production slot (at this point I confirmed the site is working and nginx is running.
  3. Run the pipeline with the code above
  4. After deploying, the site stopped working and I can check service nginx does not exist.

1 Answer 1

1

According to this MS Document

The default container uses the configuration file found at /etc/nginx/sites-available/default. Keep in mind that any edit you make to this file is erased when the app restarts. To make a change that is effective across app restarts, add a custom start-up command like this example:

cp /home/site/wwwroot/default /etc/nginx/sites-available/default && service nginx reload

I have used below YAML Pipeline to deploy a sample PHP application and it was deployed successfully:-

Even if you do not add the start up command your app will load as the Azure Web App with runtime set to PHP will load the app from the back end. I tried adding service nginx reload and service nginx restart command as my startup script, And still my app loaded successfully.

My Azure DevOps YAML Pipeline:-

trigger:
- master

variables:
  
  azureSubscription: 'xxxxxxx0e1fc9c'

  
  webAppName: 'phpsiliconhelloworld'

  
  vmImageName: 'ubuntu-latest'

  
  environmentName: 'phpsiliconhelloworld'

  
  rootFolder: $(System.DefaultWorkingDirectory)

stages:
- stage: Build
  displayName: Build stage
  variables:
    phpVersion: '7.3'
  jobs:
  - job: BuildJob
    pool:
      vmImage: $(vmImageName)
    steps:
    - script: |
        sudo update-alternatives --set php /usr/bin/php$(phpVersion)
        sudo update-alternatives --set phar /usr/bin/phar$(phpVersion)
        sudo update-alternatives --set phpdbg /usr/bin/phpdbg$(phpVersion)
        sudo update-alternatives --set php-cgi /usr/bin/php-cgi$(phpVersion)
        sudo update-alternatives --set phar.phar /usr/bin/phar.phar$(phpVersion)
        php -version
      workingDirectory: $(rootFolder)
      displayName: 'Use PHP version $(phpVersion)'

    - script: composer install --no-interaction --prefer-dist
      workingDirectory: $(rootFolder)
      displayName: 'Composer install'

    - task: ArchiveFiles@2
      displayName: 'Archive files'
      inputs:
        rootFolderOrFile: '$(rootFolder)'
        includeRootFolder: false
        archiveType: zip
        archiveFile: $(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip
        replaceExistingArchive: true

    - upload: $(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip
      displayName: 'Upload package'
      artifact: drop

- stage: Deploy
  displayName: 'Deploy Web App'
  dependsOn: Build
  condition: succeeded()
  jobs:
  - deployment: DeploymentJob
    pool:
      vmImage: $(vmImageName)
    environment: $(environmentName)
    strategy:
      runOnce:
        deploy:
          steps:
          - task: AzureWebApp@1
            displayName: 'Deploy Azure Web App : phpsiliconhelloworld'
            inputs:
              azureSubscription: $(azureSubscription)
              appName: $(webAppName)
              package: $(Pipeline.Workspace)/drop/$(Build.BuildId).zip

Output:-

enter image description here

enter image description here

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.