New to Bitbucket Cloud? Check out our get started guides for new users.
This quick-start guide shows you how to use Bitbucket Pipelines to build and test in a Laravel 5 project in a Docker container.
If you'd prefer to quickly import our demo repository with a working pipeline to experiment with, have a look at our demo laravel repo.
If you'd like to set it up by hand, 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 repository.
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.
Import the quickstart repository into Bitbucket
Import the https://github.com/laravel/quickstart-basic.git repo into Bitbucket:
In Bitbucket, select the Repositories tab, then Create repository, then Import repository.
We're using laravel-quickstart-basic as the repo name here.
Enable Bitbucket Pipelines
In your new repoository, click Pipelines, then Create your first pipeline.
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.2-fpm Docker image
install dependencies (git, curl) from OS packages
install PHP extensions for mcrypt and mysql
use Composer to install PHP dependencies
set 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.
Here's the config file to do all that:
You can check your bitbucket-pipelines.yml file with our online validator .
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 variables for MySQL: MYSQL_DATABASE, MYSQL_RANDOM_ROOT_PASSWORD, MYSQL_USER and MYSQL_PASSWORD.
These instruct the MySQL initialization process to create a database named 'homestead' with a 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:
Then create an .env.pipelines file in the root of the reposity, as shown below. The bitbucket-pipelines.yml file copys this into the default .env location in the root of the project.
Make sure you add the .env.pipelines file before committing to the repo:
Credentials committed to source control should only be for testing, and should not be shared with production systems.
Push to the repository
When you commit and push to the repo in Bitbucket, Pipelines with automatically run the build. Now you've got the launchpad for your next Laravel project to build upon.