Wordpress Auto Deploy

自动化(脚本)部署

目录:

  1. Wordpress 本地自动初始化

  2. Wordpress 线上初始化(本地至线上)

  3. Wordpress 线上自动更新

Wordpress 本地自动初始化

  1. Nginx File

    • Shell

  2. Wordpress Bedrock

    1. Common wordpress Config - application

  3. Composer update

    • Shell

  4. Create Database

    • Shell

  5. Env

    • local

  6. Local Host

#!/bin/bash
#Variable
rootdir=
nginxfile=
databasename=
pwd=

#Step 1: Nginx file
sudo cp /var/www/$rootdir/$nginxfile /etc/nginx/sites-available
sudo ln -s /etc/nginx/sites-available/$nginxfile /etc/nginx/sites-enabled
sudo service nginx restart

#Step 2: Wordpress Bedrock
sudo cp -r /var/www/wordpress/* /var/www/$rootdir/
sudo cp -r /var/www/wordpress/.gitignore /var/www/$rootdir/
cd /var/www/$rootdir
sudo composer update

#Step 3:Create database
mysql -u root -p$pwd -e "create database $databasename"

#Setp 4: Cp .evn
sudo cp /var/www/wordpress/.env.example /var/www/$rootdir/.env

Final:

  1. execute shell script

    • VIM Nginx file

    • VIM shell script

  2. edit /etc/hosts

  3. vim .env

Wordpress 线上首次部署

  1. Nginx

  2. Git clone

  3. Composer Update

  4. upload File

  5. Create Database

    • export database

    • import Database

  6. env file

#!/bin/bash
#Variable
rootdir=
nginxfile=
databasename=
pwd=
server=


#Step 1: Nginx file
scp ./$nginxfile $server:/etc/nginx/sites-available
ssh $server "ln -s /etc/nginx/sites-available/$nginxfile /etc/nginx/sites-enabled" 
service nginx restart

#Step 2: Git Clone And Composer Update
ssh $server "cd /var/www; git clone git@github.com:xlcoder/deploytest.git" 
ssh $server "cd /var/www/$rootdir; composer update" 

#Step 3:Create database
ssh $server "mysql -u root -p$pwd -e \"create database $databasename\""

#Step 4:Evn file
scp ./.env.online $server:/var/www/$rootdir
ssh $server "cd /var/www/$rootdir; mv .env.online .env"

#Step 5:Database 
ssh localphp7 "cd /var/www/$rootdir; mysqldump -u root -p123456abc $databasename > $databasename\_init\.sql"
scp ./$databasename\_init.sql $server:/tmp
ssh $server "cd /tmp; mysql -u root -p$pwd $databasename < $databasename\_init\.sql"


Final:

  1. dns record

  2. cp .env.online

  3. git repoestiory

  4. Bash Script

    • vim nginx file

    • vim git

Wordpress 线上持续更新

  1. uploads

  2. git pull

  3. dabases

    • import

    • export

#!/bin/bash
#Variable
rootdir=
nginxfile=
databasename=
pwd=
server=

#Setp 1:Rsync Upload
rsync --ignore-existing -vzrh ./web/app/uploads $server:/var/www/$rootdir/web/app/

#Step 2: Git Clone And Composer Update
ssh $server "cd /var/www/$rootdir; git pull" 

#Step 3:Database 
ssh localphp7 "cd /var/www/$rootdir; mysqldump -u root -p123456abc $databasename > $databasename\_update\.sql"
scp ./$databasename\_update.sql $server:/tmp
ssh $server "cd /tmp; mysql -u root -p$pwd $databasename < $databasename\_update\.sql"

标签: none

添加新评论