Developing a CI Process for Laravel with Codeship and Forge

Published on by

Developing a CI Process for Laravel with Codeship and Forge image

Codeship empowers developers to efficiently test and deploy web applications with a basic command. Today, I want to demonstrate some of the platform’s features through testing and deploying a Laravel application.

To go through this tutorial, you’re going to need a few things:

  1. A local instance of Docker Community Edition
  2. A Codeship account
  3. A Laravel Forge account – requires subscription
  4. A DigitalOcean or Amazon Web Services account
  5. Some sort of source-control hosting account (eg, GitHub, Bitbucket, GitLab)
  6. A local download of our application found here
  7. A hosted (forked) instance of this application on the source-control hosting account of your choice

Our Laravel Application

In this article, we’ll be testing and deploying an existing To Do list Laravel application whose source code can be found here.

Our application is fairly bare-bones and only has a few tests. The focus here isn’t necessarily to show a deep dive of Laravel. Rather, we’re more focused on how to continuously test and deploy new changes to our application. Once you have a feel for the process outlined here, I encourage you to try the same series of steps with your own personal Laravel application!

Before we move on, there are a few points of interest about our application:

  1. PostgreSQL is our database of choice.
  2. We’re running PHP 5.6.
  3. We’re testing our application with PHP Unit.

These three factors will influence how we set up our deployment and testing pipelines. Anything outside of this stack may require additional steps.

With this in mind, let’s move on to setting up our project on Codeship!

Setting up our Codeship project

If you don’t have a Codeship account, you can create one here. Otherwise, log into your account and follow the initial steps to create a new project.

Choose the source-control hosting of your choice and connect the application to Codeship. When prompted, select the Codeship Basic option. On the Configure Your Tests step, choose the [PHP] Laravel option. This will add in basic PHP setup and testing commands within our application. The default commands provide us with just about everything we would need, but we need another addition:

setup commands
# We support all major PHP versions. Please see our documentation for a full list.
# By default we use the latest PHP version from the 5.5 release branch, but Laravel
# requires at least version 5.6.4
phpenv local 5.6
# Prepare cache directory and install dependencies
mkdir -p ./bootstrap/cache
# NEW ADDITION - Create Postgresql Database
psql -c "CREATE DATABASE todos"
composer install --no-interaction
# Prepare the test database
php artisan migrate

This simple code edition will allow us to create a PostgreSQL database for running our tests on.

If you look below at your test pipeline, you should see that PHP Unit is your default option. If you want to use another testing framework, you’re absolutely free to do that! However, we’re going to continue forward using PHP Unit. Our call to PHP Unit should look like this:

test pipeline

This will call your test runner once your application is set up on Codeship’s servers.

Finally, there’s one more step that we need to complete before moving onto Laravel Forge: setting the Codeship build environment.

Under Project Settings, select the Environment tab. Within this tab, you should be able to edit and create various environmental variables for your build environment. Our application will use the following environmental variables:


With these variables set, we should now be able to complete a successful build! Push new changes or force-push your existing application to trigger a new build on Codeship. Once you find that the build succeeds, we can move on to configuring Laravel Forge.

Setting up Laravel Forge

As I mentioned earlier, you’re going to need a Laravel Forge account. Unfortunately, Forge isn’t a free service, so you’re going to have to subscribe to it before continuing.

When you create your account, you have a few options for creating a server. In this article, we’re going to use DigitalOcean. However, as usual, you’re free to blaze your own pathway here!

You’ll want to create a server that has at least 1 GB of RAM within it. Our bare-bones To Do list application works fine with this amount of RAM. However, many larger, more complex applications may not be able to handle only 1GB RAM. With this in mind, pick your server preferences and create the server. The creation process should take a few minutes.

Once the server is created, we’ll connect our Laravel application from source control. Follow the instructions for the source-control provider of your choice. If you’re using the To Do list application, our deploy will fail on the first try. This is because we haven’t set the environmental variables yet.

Under the Site Details tab, there should be an option entitled Environment. We’ll want to employ a similar strategy that we implemented in our Codeship configuration. Here’s how it should look:

DB_PASSWORD=[randomly generated password]

With this configuration, we should be able to press the Deploy Now button and successfully deploy our application on Forge.

Connecting Forge and Codeship

So far, we’ve got two awesome but independent processes for testing and deploying code. However, we want to connect these two processes so that they do something like this:

  1. Code changes are pushed to a deployable branch.
  2. New code changes are tested on Codeship.
  3. If the Codeship build passes, send a deploy request to Laravel Forge.
  4. Laravel Forge pulls in the tested code changes and attempts to deploy them in a production environment.

This sounds pretty neat, but how do we do this?

Under your App Details in Laravel Forge, look for a section entitled Deployment Trigger URL. This should contain a URL with a token at the end of it. Take that URL and copy it.

Now, log back into your Codeship project and look for the Deployment tab in your Project Settings. Select the Custom Script option and enter the following:

wget [your copied Laravel forge url]

This command will send the signal to Laravel Forge to deploy your application. Now, all we have to do is trigger another build on Codeship and we’ll see these two services talk together!

Wrapping Up

With all of these elements tied together, we’ve created an efficient CI testing and deployment pipeline that allows us to simply push code changes to a deployment branch, and have them tested and deployed upon success.

While awesome processes like these allow you to deploy clean code faster, they’re merely just the beginning of a robust CI process. With many of the other features that Codeship offers, you can find even more ways to automatically test and deploy your application!

Many thanks to Codeship for sponsoring Laravel News this week with this tutorial.

Eric L. Barnes photo

Eric is the creator of Laravel News and has been covering Laravel since 2012.


Laravel Newsletter

Join 40k+ other developers and never miss out on new tips, tutorials, and more.

Larafast: Laravel SaaS Starter Kit

Larafast is a Laravel SaaS Starter Kit with ready-to-go features for Payments, Auth, Admin, Blog, SEO, and beautiful themes.

Visit Larafast: Laravel SaaS Starter Kit
Laravel Forge logo

Laravel Forge

Easily create and manage your servers and deploy your Laravel applications in seconds.

Laravel Forge
Tinkerwell logo


The must-have code runner for Laravel developers. Tinker with AI, autocompletion and instant feedback on local and production environments.

No Compromises logo

No Compromises

Joel and Aaron, the two seasoned devs from the No Compromises podcast, are now available to hire for your Laravel project. ⬧ Flat rate of $7500/mo. ⬧ No lengthy sales process. ⬧ No contracts. ⬧ 100% money back guarantee.

No Compromises
Kirschbaum logo


Providing innovation and stability to ensure your web application succeeds.

Shift logo


Running an old Laravel version? Instant, automated Laravel upgrades and code modernization to keep your applications fresh.

Bacancy logo


Supercharge your project with a seasoned Laravel developer with 4-6 years of experience for just $2500/month. Get 160 hours of dedicated expertise & a risk-free 15-day trial. Schedule a call now!

Lucky Media logo

Lucky Media

Bespoke software solutions built for your business. We ♥ Laravel

Lucky Media
Lunar: Laravel E-Commerce logo

Lunar: Laravel E-Commerce

E-Commerce for Laravel. An open-source package that brings the power of modern headless e-commerce functionality to Laravel.

Lunar: Laravel E-Commerce
LaraJobs logo


The official Laravel job board

Larafast: Laravel SaaS Starter Kit logo

Larafast: Laravel SaaS Starter Kit

Larafast is a Laravel SaaS Starter Kit with ready-to-go features for Payments, Auth, Admin, Blog, SEO, and beautiful themes. Available with Vue and Livewire stacks.

Larafast: Laravel SaaS Starter Kit
SaaSykit: Laravel SaaS Starter Kit logo

SaaSykit: Laravel SaaS Starter Kit

SaaSykit is a Laravel SaaS Starter Kit that comes with all features required to run a modern SaaS. Payments, Beautiful Checkout, Admin Panel, User dashboard, Auth, Ready Components, Stats, Blog, Docs and more.

SaaSykit: Laravel SaaS Starter Kit
Rector logo


Your partner for seamless Laravel upgrades, cutting costs, and accelerating innovation for successful companies


The latest

View all →
A New Validation Rule and the Ability to Manually Fail a Command in Laravel 11.8 image

A New Validation Rule and the Ability to Manually Fail a Command in Laravel 11.8

Read article
New Proposed Array Find Functions in PHP 8.4 image

New Proposed Array Find Functions in PHP 8.4

Read article
Laracon AU 2024 tickets are now on sale image

Laracon AU 2024 tickets are now on sale

Read article
Dash UI is a Laravel Blade Component Library Inspired by Shopify Polaris image

Dash UI is a Laravel Blade Component Library Inspired by Shopify Polaris

Read article
Is class instantiation without extra parenthesis coming to PHP 8.4? image

Is class instantiation without extra parenthesis coming to PHP 8.4?

Read article
Validation Errors Card for Laravel Pulse image

Validation Errors Card for Laravel Pulse

Read article