LoginSignup
0
1

More than 5 years have passed since last update.

How to set up CircleCI in PHP project

Last updated at Posted at 2018-05-25

How to set up CircleCI config file on local PC.

Install circleci command

curl -o /usr/local/bin/circleci https://circle-downloads.s3.amazonaws.com/releases/build_agent_wrapper/circleci && chmod +x /usr/local/bin/circleci
circleci update

Create config file

The following file is often used in my PHP project.
Regarding the docker image, please see this official page.

# PHP CircleCI 2.0 configuration file
#
# Check https://circleci.com/docs/2.0/language-php/ for more details
#
version: 2

jobs:
  build:

    docker:
      - image: circleci/php:7.0-apache-node-browsers

    steps:
      - checkout

      - run: echo -e "[Date]\ndate.timezone = Asia/Tokyo" | sudo tee /usr/local/etc/php/php.ini > /dev/null

      - run: chmod -R 777 ./storage
      - run: chmod -R 777 ./bootstrap/cache

      - run: sudo apt-get update -y
      - run: sudo apt-get install -y libpng-dev libjpeg-dev zip unzip git
      - run: sudo rm -rf /var/lib/apt/lists/*
      - run: sudo docker-php-ext-install zip
      - run: sudo docker-php-ext-configure gd --with-jpeg-dir=/usr/lib/x86_64-linux-gnu/
      - run: sudo docker-php-ext-install pdo pdo_mysql gd mbstring zip
      - run: sudo composer self-update

      - restore_cache:
          keys:
            - composer-v1-{{ checksum "composer.json" }}
            - composer-v1-
      - run: composer install -n --prefer-dist
      - save_cache:
          key: composer-v1-{{ checksum "composer.json" }}
          paths:
            - vendor

      - run: cp .env.example .env

      - run:
          name: Run PhpUnit
          command: ./vendor/bin/phpunit

Validate syntax of config.yml

circleci config validate -c .circleci/config.yml

Run to build and test

circleci build .circleci/config.yml
0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1