Home Explore Blog CI



docker

1st chunk of `content/guides/php/configure-ci-cd.md`
df9d123791b265edadcb1d70d8a1e5165651359fa86c00c100000001000009b1
---
title: Configure CI/CD for your PHP application
linkTitle: Configure CI/CD
weight: 40
keywords: php, CI/CD
description: Learn how to Configure CI/CD for your PHP application
aliases:
  - /language/php/configure-ci-cd/
  - /guides/language/php/configure-ci-cd/
---

## Prerequisites

Complete all the previous sections of this guide, starting with [Containerize a PHP application](containerize.md). You must have a [GitHub](https://github.com/signup) account and a [Docker](https://hub.docker.com/signup) account to complete this section.

## Overview

In this section, you'll learn how to set up and use GitHub Actions to build and test your Docker image as well as push it to Docker Hub. You will complete the following steps:

1. Create a new repository on GitHub.
2. Define the GitHub Actions workflow.
3. Run the workflow.

## Step one: Create the repository

Create a GitHub repository, configure the Docker Hub credentials, and push your source code.

1. [Create a new repository](https://github.com/new) on GitHub.

2. Open the repository **Settings**, and go to **Secrets and variables** >
   **Actions**.

3. Create a new **Repository variable** named `DOCKER_USERNAME` and your Docker ID as a value.

4. Create a new [Personal Access Token (PAT)](/manuals/security/for-developers/access-tokens.md#create-an-access-token) for Docker Hub. You can name this token `docker-tutorial`. Make sure access permissions include Read and Write.

5. Add the PAT as a **Repository secret** in your GitHub repository, with the name
   `DOCKERHUB_TOKEN`.

6. In your local repository on your machine, run the following command to change
   the origin to the repository you just created. Make sure you change
   `your-username` to your GitHub username and `your-repository` to the name of
   the repository you created.

   ```console
   $ git remote set-url origin https://github.com/your-username/your-repository.git
   ```

7. In your local repository on your machine, run the following command to rename
   the branch to main.

   ```console
   $ git branch -M main
   ```

8. Run the following commands to stage, commit, and then push your local
   repository to GitHub.

   ```console
   $ git add -A
   $ git commit -m "my first commit"
   $ git push -u origin main
   ```

## Step two: Set up the workflow

Set up your GitHub Actions workflow for building, testing, and pushing the image
to Docker Hub.

1. Go to your repository on GitHub and then select the **Actions** tab.

Title: Configure CI/CD for PHP Application with GitHub Actions
Summary
This section guides you through setting up CI/CD for a PHP application using GitHub Actions. It covers creating a new GitHub repository, configuring Docker Hub credentials as repository variables and secrets, pushing the existing source code to the new repository, and preparing to define the GitHub Actions workflow for building, testing, and pushing Docker images.