참고 항목
GitHub 호스트 실행기는 현재 GitHub Enterprise Server에서 지원되지 않습니다. GitHub public roadmap에 예정된 향후 지원에 대해 자세히 알아볼 수 있습니다.
Introduction
This guide explains how to use GitHub Actions to build and deploy a PHP project to Azure App Service.
참고 항목
GitHub Actions 워크플로가 OIDC(OpenID Connect)를 지원하는 클라우드 공급자의 리소스에 액세스해야 하는 경우 클라우드 공급자에게 직접 인증하도록 워크플로를 구성할 수 있습니다. 이렇게 하면 이러한 자격 증명을 수명이 긴 비밀로 저장하지 않을 수 있고 다른 보안 이점을 제공할 수 있습니다. 자세한 내용은 OpenID Connect를 사용한 보안 강화 정보을(를) 참조하세요. and Configuring OpenID Connect in Azure.
Prerequisites
Before creating your GitHub Actions workflow, you will first need to complete the following setup steps:
-
Azure App Service 요금제를 만듭니다.
예를 들어 Azure CLI를 사용하여 새 App Service 요금제를 만들 수 있습니다.
Bash az appservice plan create \ --resource-group MY_RESOURCE_GROUP \ --name MY_APP_SERVICE_PLAN \ --is-linux
az appservice plan create \ --resource-group MY_RESOURCE_GROUP \ --name MY_APP_SERVICE_PLAN \ --is-linux
위의 명령에서
MY_RESOURCE_GROUP
을 기존 Azure 리소스 그룹으로 바꾸고MY_APP_SERVICE_PLAN
을 App Service 요금제의 새 이름으로 바꿉니다.Azure CLI 사용에 대한 자세한 내용은 Azure 설명서를 참조하세요.
- 인증은 Azure CLI로 로그인을 참조하세요.
- 새 리소스 그룹을 만들어야 하는 경우 az group을 참조하세요.
-
Create a web app.
For example, you can use the Azure CLI to create an Azure App Service web app with a PHP runtime:
Bash az webapp create \ --name MY_WEBAPP_NAME \ --plan MY_APP_SERVICE_PLAN \ --resource-group MY_RESOURCE_GROUP \ --runtime "php|7.4"
az webapp create \ --name MY_WEBAPP_NAME \ --plan MY_APP_SERVICE_PLAN \ --resource-group MY_RESOURCE_GROUP \ --runtime "php|7.4"
In the command above, replace the parameters with your own values, where
MY_WEBAPP_NAME
is a new name for the web app. -
Azure 게시 프로필을 구성하고
AZURE_WEBAPP_PUBLISH_PROFILE
비밀을 만듭니다.게시 프로필을 사용하여 Azure 배포 자격 증명을 생성합니다. 자세한 내용은 Azure 설명서의 배포 자격 증명 생성을 참조하세요.
GitHub 리포지토리에서 게시 프로필의 콘텐츠가 포함된
AZURE_WEBAPP_PUBLISH_PROFILE
이라는 비밀을 만듭니다. 비밀을 만드는 방법의 자세한 내용은 Using secrets in GitHub Actions을(를) 참조하세요. -
Optionally, configure a deployment environment. 환경은 일반적인 배포 대상(예:
production
,staging
또는development
)을 설명하는 데 사용됩니다. GitHub Actions 워크플로가 환경에 배포되면 환경이 리포지토리의 기본 페이지에 표시됩니다. 작업을 진행하기 위해 승인을 요구하거나 워크플로, 사용자 지정 배포 보호 규칙을 사용하여 게이트 배포를 트리거할 수 있는 분기를 제한하거나 비밀에 대한 액세스를 제한할 수 있습니다. 환경을 만드는 방법에 대한 자세한 내용은 Managing environments for deployment을(를) 참조하세요.
Creating the workflow
Once you've completed the prerequisites, you can proceed with creating the workflow.
The following example workflow demonstrates how to build and deploy a PHP project to Azure App Service when there is a push to the main
branch.
Ensure that you set AZURE_WEBAPP_NAME
in the workflow env
key to the name of the web app you created. If the path to your project is not the repository root, change AZURE_WEBAPP_PACKAGE_PATH
to the path to your project. If you use a version of PHP other than 8.x
, changePHP_VERSION
to the version that you use.
배포 환경을 구성한 경우 환경의 이름으로 environment
값을 변경합니다. 환경을 구성하지 않은 경우 environment
키를 삭제합니다.
# 이 워크플로는 GitHub에서 인증되지 않은 작업을 사용합니다. # 작업은 타사에서 제공하며 # 별도의 서비스 약관, 개인정보처리방침, 지원 설명서에서 규정됩니다. # 참조하세요. # 커밋 SHA에 작업을 고정하는 것이 좋습니다. # 최신 버전을 얻으려면 SHA를 업데이트해야 합니다. # 태그 또는 분기를 참조할 수도 있지만 경고 없이 작업이 변경될 수 있습니다. name: Build and deploy PHP app to Azure Web App env: AZURE_WEBAPP_NAME: MY_WEBAPP_NAME # set this to your application's name AZURE_WEBAPP_PACKAGE_PATH: '.' # set this to the path to your web app project, defaults to the repository root PHP_VERSION: '8.x' # set this to the PHP version to use on: push: branches: - main jobs: build: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - name: Setup PHP uses: shivammathur/setup-php@1f2e3d4c5b6a7f8e9d0c1b2a3e4f5d6c7b8a9e0f with: php-version: ${{ env.PHP_VERSION }} - name: Check if composer.json exists id: check_files uses: andstor/file-existence-action@2a3b4c5d6e7f8a9b0c1d2e3f4a5b6c7d8e9f0a1b with: files: 'composer.json' - name: Get Composer Cache Directory id: composer-cache if: steps.check_files.outputs.files_exists == 'true' run: | echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT - name: Set up dependency caching for faster installs uses: actions/cache@v4 if: steps.check_files.outputs.files_exists == 'true' with: path: ${{ steps.composer-cache.outputs.dir }} key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} restore-keys: | ${{ runner.os }}-composer- - name: Run composer install if composer.json exists if: steps.check_files.outputs.files_exists == 'true' run: composer validate --no-check-publish && composer install --prefer-dist --no-progress - name: Upload artifact for deployment job uses: actions/upload-artifact@v3 with: name: php-app path: . deploy: runs-on: ubuntu-latest needs: build environment: name: 'production' url: ${{ steps.deploy-to-webapp.outputs.webapp-url }} steps: - name: Download artifact from build job uses: actions/download-artifact@v3 with: name: php-app - name: 'Deploy to Azure Web App' id: deploy-to-webapp uses: azure/webapps-deploy@85270a1854658d167ab239bce43949edb336fa7c with: app-name: ${{ env.AZURE_WEBAPP_NAME }} publish-profile: ${{ secrets.AZURE_WEBAPP_PUBLISH_PROFILE }} package: .
# 이 워크플로는 GitHub에서 인증되지 않은 작업을 사용합니다.
# 작업은 타사에서 제공하며
# 별도의 서비스 약관, 개인정보처리방침, 지원 설명서에서 규정됩니다.
# 참조하세요.
# 커밋 SHA에 작업을 고정하는 것이 좋습니다.
# 최신 버전을 얻으려면 SHA를 업데이트해야 합니다.
# 태그 또는 분기를 참조할 수도 있지만 경고 없이 작업이 변경될 수 있습니다.
name: Build and deploy PHP app to Azure Web App
env:
AZURE_WEBAPP_NAME: MY_WEBAPP_NAME # set this to your application's name
AZURE_WEBAPP_PACKAGE_PATH: '.' # set this to the path to your web app project, defaults to the repository root
PHP_VERSION: '8.x' # set this to the PHP version to use
on:
push:
branches:
- main
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup PHP
uses: shivammathur/setup-php@1f2e3d4c5b6a7f8e9d0c1b2a3e4f5d6c7b8a9e0f
with:
php-version: ${{ env.PHP_VERSION }}
- name: Check if composer.json exists
id: check_files
uses: andstor/file-existence-action@2a3b4c5d6e7f8a9b0c1d2e3f4a5b6c7d8e9f0a1b
with:
files: 'composer.json'
- name: Get Composer Cache Directory
id: composer-cache
if: steps.check_files.outputs.files_exists == 'true'
run: |
echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
- name: Set up dependency caching for faster installs
uses: actions/cache@v4
if: steps.check_files.outputs.files_exists == 'true'
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-composer-
- name: Run composer install if composer.json exists
if: steps.check_files.outputs.files_exists == 'true'
run: composer validate --no-check-publish && composer install --prefer-dist --no-progress
- name: Upload artifact for deployment job
uses: actions/upload-artifact@v3
with:
name: php-app
path: .
deploy:
runs-on: ubuntu-latest
needs: build
environment:
name: 'production'
url: ${{ steps.deploy-to-webapp.outputs.webapp-url }}
steps:
- name: Download artifact from build job
uses: actions/download-artifact@v3
with:
name: php-app
- name: 'Deploy to Azure Web App'
id: deploy-to-webapp
uses: azure/webapps-deploy@85270a1854658d167ab239bce43949edb336fa7c
with:
app-name: ${{ env.AZURE_WEBAPP_NAME }}
publish-profile: ${{ secrets.AZURE_WEBAPP_PUBLISH_PROFILE }}
package: .
Additional resources
The following resources may also be useful:
- For the original workflow template, see
azure-webapps-php.yml
in the GitHub Actionsstarter-workflows
repository. - The action used to deploy the web app is the official Azure
Azure/webapps-deploy
action. - For more examples of GitHub Action workflows that deploy to Azure, see the actions-workflow-samples repository.