Setup Bitbucket Auto Pipeline to AWS EC2 via SSH

Setup Bitbucket Auto Pipeline to AWS EC2 via SSH

June 23, 2020 / Eternal Team

Do you have a PHP project in bitbucket and you wanted to know how to set up your bitbucket Auto pipeline to push the PHP files directly on AWS EC2. So here you go.

Assumption

  • You have setup AWS EC2 and have your private key as a .pem file. You also have a public key from your EC2 .ssh folder.
  • You have bitbucket setup and the branch’s name is dev, stage, and production.
  • You want to push your code via an auto pipeline of bitbucket, to EC2 via SSH when the final “production” branch gets updated with all set of changes for your project.

So here we have set up simple “production” branch pipeline bitbucket-pipelines.yml

pipelines:
 default:
  - step:
    name:  Push
     script:
      # Build and push image
         - pipe: atlassian/rsync-deploy:0.4.3
           variables:
              USER: 'ubuntu'
              SERVER: ‘XX.XX.XX.XX’
              REMOTE_PATH: '/var/www/yourwebsite.com'
              LOCAL_PATH: ${BITBUCKET_CLONE_DIR}/*
              SSH_KEY: $MY_SSH_KEY
              DEBUG: 'true'

rsync-deploy is famous for its data transfer algorithms, which reduces the data transfer by sending only differences between source files in the destination. So it’s faster.

Core PHP doesn’t require any kind of build or third party dependency installation, so its simple.

Please configure your SSH_KEY inside your repository section settings.

AWS-Consulting-Partner

Talk to AWS Certified Consultant

Want to start a project?

It’s simple.

Contact us