Laravel with Bitbucket Pipelines
This quickstart shows you how to use Bitbucket Pipelines to build and test a Laravel project in a Docker container.
Most of the configuration happens in the bitbucket-pipelines.yml file that Pipelines uses to define the build.
How it works
Bitbucket Pipelines keeps your build config in a YAML file, named bitbucket-pipelines.yml.
The bitbucket-pipelines.yml file lives in your repo.
When someone pushes to the repo, Pipelines runs the build in a Docker image.
The bitbucket-pipelines.yml file is where you can specify the dependencies needed by your project.
On this page
Import the quickstart repository into Bitbucket
Import the https://github.com/laravel/quickstart-basic.git repo into Bitbucket:
- In Bitbucket, click , then Repository, then Import repository:
We're using laravel-quickstart-basic as the repo name here.
Enable Bitbucket Pipelines
- In your new repo, click Pipelines, then Get started for free:
Clone the repo
- Clone the new Bitbucket repo to your local machine:
Add the bitbucket-pipelines.yml config file to the repo
We're going to configure a default pipeline. This pipeline will:
- use the 7-fpm Docker image
- install dependencies (git, curl) from OS packages
- install PHP extensions for mcrypt and mysql
- install Composer
- use Composer to install PHP dependencies
- set environment variables to control which cache, session data store, and database we use
- use Artisan to perform database migrations and start the app in the background
- Sleep for 5 seconds to allow the app time to start
- use curl to ensure everything is hooked up and working.
- run PHPunit
Here's the config file to do all that:
You can check your bitbucket-pipelines.yml file with our online validator .
Add the install-composer.sh helper script to the repo
Make sure you set the executable permission of install-composer.sh before committing to the repo:
Configure external dependencies
Laravel uses a RDBMS (MySQL by default) to store application state.
We can use Bitbucket Pipelines service containers to run containers from community managed images.
The MySQL definition is a little bit harder:
We define 4 environment variable for MySQL: MYSQL_DATABASE, MYSQL_RANDOM_ROOT_PASSWORD, MYSQL_USER and MYSQL_PASSWORD.
These instruct the MySQL initialisation process to create a database named 'homestead', user 'homestead' with password 'secret', and to assign a random password to the root user. These values must match the contents of config/database.php:
These environment variables are loaded from .env in the root of the project by Composer.
Push to the repo
When you commit and push to the repo in Bitbucket, Pipelines with automatically run the build:
Did you like this page? Give feedback!