Including Continuous Integration is great, but there are many providers to choose from. CircleCI has a pretty decent free plan, but using it for your Laravel app might be a bit confusing.
Instructions for deploying Laravel 5.5 with Circle CI:
This site has a nice boilerplate script:
But if you found a better script, let us know in the comments.
Make sure you have specified the testing environment variables in your .env.testing and phpunit.xml if you are using PHPUnit.
Getting a Mysql Root error?
Since March 2021, we sometimes got this error:
[ERROR] [Entrypoint]: MYSQL_USER="root", MYSQL_PASSWORD cannot be used for the root user Use one of the following to control the root user password: - MYSQL_ROOT_PASSWORD - MYSQL_ALLOW_EMPTY_PASSWORD - MYSQL_RANDOM_ROOT_PASSWORD
We solved it by changing the MYSQL_USER to another name than ‘root’.
Deploying on Laravel Forge via CI
After that call this forge-deploy.sh script in your final step in config.yml:
- run: name: Run deploy script command: sudo chmod +x ./deploy.sh; sudo ./deploy.sh
Then create a deploy.sh script in your app and include the Laravel Forge / Envoyer deployment trigger URL (can be found in your app’s dashboard in Laravel Forge / Envoyer):
#!/bin/bash # Trigger deployment # Replace the url below with your envoyer/forge url # APPLICATION1 curl -s 'https://forge.laravel.com/servers/123456...'; # APPLICATION2 - if you have multiple applications that needs to be deployed and triggered curl -s 'https://forge.laravel.com/servers/12345678...'; echo 'Deployment triggered!'
After this, you can push to Github or Bitbucket and see if the build succeeds and deploys to Laravel Forge / Envoyer. Make sure you disable auto-deploy, as you only would like to deploy to Laravel Forge / Envoyer after a successful CI build.
Deploy on Fortrabbit with CircleCI
Rather want to deploy on Fortrabbit instead of Laravel Forge after a successful CircleCI build?
Read more about using CI with Fortrabbit here.
To setup the deployment to Fortrabbit from CircleCI follow this procedure:
- Run this script on a terminal client: ssh-keygen -m PEM -t rsa -C “email@example.com”
- Copy the private key to CircleCI
- Go to the project -> SSH Keys Enter hostname: deploy.XYZ.frbit.com (replace XYX with your Fortrabbit server location)
- Add the public key in the Fortrabbit Dashboard’s public SSH key manager
- Add the fingerprint that you see in the CircleCI dashboard to the config.yml file:
version: 2 jobs: deploy-job: steps: - add_ssh_keys: fingerprints: - "SO:ME:FIN:G:ER:PR:IN:T"
Try to push the updated files to Github or Bitbucket.
See whether this build succeeds. If not, fix the issues until it works.
Add this code to the circleci/config.yml script after the testing steps:
- run: name: Add FRBIT remote command: git remote add frbit YOURFRBITGITURL - run: name: Add FRBIT remote fingerprint to known hosts command: ssh-keyscan deploy.XYZ.frbit.com >> ~/.ssh/known_hosts - run: name: Deploy to FRBIT command: git push frbit
Don’t forget to replace the variables YOURFRBITGITURL and XYZ.
Using these scripts and instructions is on your own risk of course.
Got any suggestions for a better workflow? Let us know!