Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
December 29, 2021 07:04 am GMT

PHP deployment to SSH server using Github action and bash script

In this tutorial we would lean how to deploy our PHP code to a remote server using github action .

Step 1.

ssh into remote server by

for Windows users use Power shell, while Mac users use Terminal.

yyyy : username
xxxx.xxxx.xxxx : Remote IP address
-p :Reference to a port
ZZZZ: port number

Step 2

In the root directory on your linux server create a bash file and write into by using


touch phpdeploy.sh && vi phpdeploy.sh

Step 3

To start typing on the vi editor type press the "a" key and input the following

echo "Deploying changes..."cd /var/www/htmlDIR="ECOMM"if [ -d "$DIR" ]; then  cd DIR  echo "Pull update "  git  pull fielse  echo "Clone repo" git clone  https://username:[email protected]/username/projectname.gitfi

To exit insert mode on vi editor press escape key followed by shift column and type wq(save and quite).

Step 4

This is our final step, this involves creating our .github/main.yaml file in the root of our project.

name:project nameon:  push:    branches: mainjobs:  build-and-deploy:    name: Build and deploy next site    runs-on: ubuntu-latest    steps:        - name: copy file via ssh key        uses: appleboy/scp-action@master        env:          HOST:  XXXXXXX          PORT:  XXXXX          USERNAME:  XXXXX          PASSWORD: XXXXXX          command_timeout: 100m          script: sh phpdeploy.sh

For every time your code is merger to "main" branch the yaml file above would execute.Thanks for reading.


Original Link: https://dev.to/es404020/php-deployment-to-ssh-server-using-github-action-and-bash-script-58e

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To