Running Travis CI with Laravel

Today I was working on setting up Travis CI for Cronhub builds. It took me around two hours to make it work. I was expecting the integration should be a breeze, but Travis CI configuration is not trivial. It has many moving pieces, and everything should be in place.

travis.yml file

Make sure to use the bionic or xenial Ubuntu dist in your travis.yml file and add mysql externally under the services. This will tell your build to install the latest stable version of MySQL. Otherwise, your migrations are going to fail due to an older version of MySQL.

dist: bioniclanguage: phpphp:
- 7.2
- 7.3
services:
- mysql
cache:
directories:
- node_modules
- vendor
before_script: - cp .env.travis .env - sudo mysql -e 'create database homestead;' - composer self-update - composer install --prefer-source --no-interaction --dev - php artisan key:generate - php artisan migratescript: - vendor/bin/phpunit

.env.travis file

Nothing special here just make sure you set DB_CONNECTION to testing.

APP_NAME=Cronhub
APP_ENV=testing
APP_KEY=Sometring
APP_DEBUG=true
APP_URL=http://localhost/
DB_CONNECTION=testing
DB_TEST_USERNAME=root
DB_TEST_PASSWORD=
BCRYPT_ROUNDS=4
CACHE_DRIVER=array
MAIL_DRIVER=array
QUEUE_CONNECTION=sync
SESSION_DRIVER=array
BUGSNAG_API_KEY=randkey
...'testing' => [  'driver' => 'mysql',  'host' => env('DB_TEST_HOST', 'localhost'),  'database' => env('DB_TEST_DATABASE', 'homestead'),  'username' => env('DB_TEST_USERNAME', 'homestead'),  'password' => env('DB_TEST_PASSWORD', 'secret'),  'charset' => 'utf8',  'collation' => 'utf8_unicode_ci',  'prefix' => '',  'strict' => false,],... 

Senior software engineer @netflix. I like building tools for developers.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store