You are currently viewing Using CircleCI with your PHP Application

Using CircleCI with your PHP Application

  • Post published:June 10, 2016

CircleCI is a tool which provides us with the functionality to merge, test and deploy code automatically on the server. This helps in minimizing testing and deployment time with no errors.

CircleCI is integrated with GitHub using webhook and performs all the functionality on its end. When you push commit to GitHub, CircleCI starts an action to pull down all your latest code from any branch that you have specified, prepares a build with the latest code and performs tests on it.

These tests will be executed automatically and if all of the code passes, only then will our build be pushed onto the server.

After successful testing, Circle CI provides the optional step of deploying your code on the server. You can set up CircleCI to deploy your code as well. If there is any issue during execution test cases, CircleCI will notify you. You can integrate CircleCI with any modern platform like Slack, using webhook for its notifications.

CircleCI works independently with all tools and Package mangers, that help PHP developers test and deploy their code. CircleCI also lets you execute commands, prepare build and perform tests automatically. Additionally, it provides custom configuration options via circle.yml which is in root directory.

Steps for CircleCI Execution

1: Source
Circle CI fetches the latest code using GitHub webhooks after you commit or pull requests for a specific branch.

2: Resolve dependencies
CircleCI use circle.yml to resolve all the dependencies. You can add commands and dependencies in this file. After the first execution, CircleCI saves the dependencies in the cache so that you don’t have to install everything repeatedly.

3: Build
After resolving the dependencies, CircleCI creates a build based on the latest code and all dependencies to create a test environment for the application. Not every language requires compilation time, but if your application needs any compilation before execution, CircleCI does this for you as well (examples CoffeScript, Less, etc.)

4: Tests
Once the build is ready and CircleCI has created a proper test environment, it starts execution of your test case like a PHPUnit test case.

5: Notifications
With support for every major team chat tool and email notification, CircleCI will notify you when your attention is required. Build failure notifications include info about exactly which tests failed, so you can fix things in less time.


Following are the benefits of CircleCI:

  • Improves Productivity
  • Reduces Risk
  • Scaled with CircleCI

Speed up your testing and development cycle; CircleCI is flexible to run in your environment and scale with your growth. Have peace of mind by reducing bugs and improving the quality of your PHP application.

Sample Circle.yml

    version: 5.5.11 
    ENVIRONMENT: development 
    DB_NAME: db_name
    DB_USER: db_user
    DB_DATABASE: db_dbname
    DB_USERNAME: db_dbuser
    MONGO_DB_HOST: mongo_host 
    MONGO_DB_DATABASE: mong_db_name
    - composer install --prefer-source --no-interaction 
    - printf "\n" | pecl install mongo 
    - php artisan migrate --env=development 
    - php artisan db:seed --env=development 
    - php artisan db:seed --class=UserTableSeeder --env=development 
- phpunit

With the introduction of Circle CI in our many teams, we have found it very useful in helping developer’s productivity.