Implementing a Modern WordPress Workflow on Alibaba Cloud — Part 4

Step 1. Install Git

$ ssh new_user@another-example-domain.com
$ git --version
$ sudo apt-get update
$ sudo apt-get install git

Step 2. Set Up Git

$ git config --global user.name "New User"
$ git config --global user.email "new_user@another-example-domain.com"
$ git config --list

Step 3. Create an Origin Repository

  1. Tower (MacOS / Windows)
  2. GitKraken (MacOS / Windows / Linux)
  3. Sourcetree (MacOS / Windows)
  4. GitHub Desktop (MacOS / Windows)
git remote add origin https://github.com/user_name/repository_name.git
git push -u origin master

Step 3. Create Your Local Git Repository

$ cd /path/to/your/local/site/root/folder
$ cd /local/sites/anotherexampledomain/app/public
$ git init
$ ls -a

Step 3. Create a .gitignore File

# Ignore everything inside the root directory
/*
## Exceptions - track these inside the root directory
!wp-content
!.gitignore
!README.md
# Ignore everything inside the "wp-content" directory
wp-content/*
## Exceptions - track these inside the "wp-content" directory
!wp-content/themes/
!wp-content/plugins/
# Ignore everything inside the "themes" and "plugins" directory
wp-content/themes/*
wp-content/plugins/*
## Exceptions - track these inside the "themes" and "plugins" directory
!wp-content/themes/your_theme
!wp-content/plugins/your_plugin

Step 4. First Commit and Push to Origin

$ git commit -m "first commit"
$ git remote add origin https://github.com/user_name/repository_name.git
$ git remote -v
$ git push origin master

Step 5. Set Up Staging Site Git Deployment

Step 5a. Set Up Staging Site Repository

$ cd /var/www/staging.another-example-domain.com
$ sudo mkdir staging.git
$ cd staging.git
$ sudo git init --bare

Step 5b. Set Up Staging Deploy Hooks

$ cd /var/www/staging.another-example-domain.com/staging.git/hooks
$ sudo touch post-receive
$ sudo nano post-receive
#!/bin/sh
git --work-tree=/var/www/staging.another-example-domain.com --git-dir=/var/www/staging.another-example-domain.com/staging.git checkout -f

Step 5c. Change Directory Ownership and Permissions

$ cd /var/www/staging.another-example-domain.com
$ ls -l
$ sudo chown -R www-data/www-data /var/www/staging.another-example-domain.com
$ sudo chmod -R 775 /var/www/staging.another-example-domain.com
$ ls -l
$ sudo user mod -a -G www-data new_user
$ groups
$ sudo chmod -R g+w /var/www/staging.another-example-domain.com
$ cd /var/www/staging.another-example-domain.com/staging.git
$ git config core.sharedRepository group
$ git config core.sharedRepository

Step 5d. Push from Local Master to Staging

.site-content-contain {
background-color: yellow;
}
h1.site-title a {
font-size: 300%;
color: purple !important;
}
$ git remote add staging ssh://new_user@staging.another-example-domain.com/var/www/staging.another-example-domain.com/staging.git
$ git remote -v
$ git add .
$ git commit -m "changed ground color"
$ git push staging master

Step 6. Set Up Production Site Git Deployment

Step 6a. Set Up Production Site Repository

$ cd /var/www/another-example-domain.com
$ sudo mkdir production.git
$ cd production.git
$ sudo git init --bare

Step 6b. Set Up Production Deploy Hooks

$ cd /var/www/another-example-domain.com/production.git/hooks
$ sudo touch post-receive
$ sudo nano post-receive
#!/bin/sh
git --work-tree=/var/www/another-example-domain.com --git-dir=/var/www/another-example-domain.com/production.git checkout -f

Step 6c. Change Directory Ownership and Permissions

$ sudo chmod -R g+w /var/www/another-example-domain.com
$ cd /var/www/another-example-domain.com/production.git
$ git config core.sharedRepository group

Step 6.d Push from Local Master to Production

$ git remote add production ssh://new_user@another-example-domain.com/var/www/another-example-domain.com/production.git
$ git remote -v
$ git push production master

Step 7. Push Changes to Origin and Inspect Changes in Repository

$ git push origin master

Step 8. Re-enable Staging Site HTTP Authentication

$ sudo nano /etc/nginx/sites-available/staging.another-example-domain.com
location / {
……
# auth_basic "Staging Site - Access Restricted!";
# auth_basic_user_file /etc/nginx/.htpasswd;
}
location / {
……
auth_basic "Staging Site - Access Restricted!";
auth_basic_user_file /etc/nginx/.htpasswd;
}
$ sudo nginx -t
$ sudo systemctl reload nginx

Summary

--

--

--

Follow me to keep abreast with the latest technology news, industry insights, and developer trends. Alibaba Cloud website:https://www.alibabacloud.com

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Essential Tools for Project Management

Walking the DWeb walk

Naive String Searching Algorithm:

Why Cloud Migration is not a Piece of Cake

Packages in Java: How to Create and Use Packages in Java?

Handle User Accounts & Authentication in Flask with Flask-Login

Refreshing Python after couple of Busy Week

The Dwarves Tech Radar: Vol 01 — Getting Started

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
Alibaba Cloud

Alibaba Cloud

Follow me to keep abreast with the latest technology news, industry insights, and developer trends. Alibaba Cloud website:https://www.alibabacloud.com

More from Medium

(Serverless or Docker) Which host to choose?

Getting started with AWS CDK

CI/CD Storybook project to S3 static website by integrating AWS CodePipeline with GitHub

Hosting Website on S3 + Cloudfront Distribution