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

C語言練習題:scanf 輸入(C language exercise: input with scanf )

Upgrading your dependencies: a backend developer's game of Russian roulette

60 Practices For Quality Engineering : Architecture (Part 2)

AWS EMR in FS: Presto vs Hive vs Spark SQL

Tower of Hanoi

Python for Geeks Review

Emerging Trends for Developers in 2017

Crodo competitor review — Roseon

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

Push multiple files under a single commit through GitHub API

Implementando o Amazon Elastic Kubernetes Service: Do zero ao deploy (Parte 4/6)

Docker -> How to get Docker Desktop running on Win 10 while fixing The attempted operation is not…

Postman API Authentication with Pre-request Script