Setup Bitbucket Auto Pipeline to AWS EC2 via SSH

Setup Bitbucket Auto Pipeline to AWS EC2 via SSH

June 23, 2020 / Nirav Shah

Bitbucket Auto Pipelines Deploy To AWS EC2 Via SSH

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.

Also Read:  Enabling root login to the server with SSH login

Talk to AWS Certified Consultant

    Spread Love By Sharing:

    Let Us Talk About Your AWS Development Requirements

    Have queries about your AWS project ideas and concepts? Please drop in your project details to discuss with our AWS experts, professionals and consultants.

    • Swift Hiring and Onboarding
    • Experienced and Trained AWS Team
    • Quality Consulting and Programming
    Let’s Connect and Discuss Your Project