- Init local git repository (remember to create
.gitginore
withwp-config.php
before staging anything) - Configure SSH-key access to server with git [https://help.github.com/articles/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent/, https://help.ubuntu.com/community/SSH/OpenSSH/Keys#Transfer_Client_Key_to_Host]
- Init a bare repo on the server
git init && git config core.bare true
- Create a new post-receive hook with
nano .git/hooks/post-receive
(content see below!) - Execute
chmod 755 post-receive
on the script - Add remote to local repository
git remote add staging [email protected]:www/your-website
- Try pushing
git push staging master
- Check if everything works as expected.
- Add a
.htaccess
to the.git
directory with content:deny from all
- Repeat for all stages.
- wp-config.php and .htaccess will be replaced although .gitignore is in place
Add the following (adjust folder- and filenames) to the post-receive hook
cp ~/www/config-files/wp-config-staging.php ../wp-config.php
cp ~/www/config-files/.htaccess-staging ../.htaccess
Create a directory outside the webroot with config files. (Consider settings debug = true for staging/testing).
- Denying plugin/theme/update installation on live only works if owner of folder is different from php user.
If the users are different, do chmod 755 <folder>
on plugins/themes/upgrade folder in live environment.
- Charsets of mysql dump and live database is not compatible.
Change charset from utf8mb4
to utf8
in wp-config.php
and export again.
#!/bin/sh
GIT_WORK_TREE="../" git checkout -f
# optional, move config files
cp ~/www/config-files/wp-config-staging.php ../wp-config.php
cp ~/www/config-files/.htaccess-staging ../.htaccess
# optional, remove dev files
rm -rf ../node