Git Siteground Deployment WordPress Sublime Text - wordpress

I am a beginning developer looking to get a great workflow setup before I begin my personal website: kevinbmccall.com
The site has WordPress installed and is hosted by SiteGround.
I enjoy the Sublime Text 3 Editor and am looking to emulate the workflow described here: http://joshuaiz.com/words/the-ultimate-workflow/
I was already in the process of learning Git through the terminal and had a GitHub repo setup through a local project folder. So I didn't really follow Joshua exactly and may have been what led me to get stuck but I think I got to the SSH part.
Here is what I have done so far:
Installed Sublime Text 3 with SublimeGit Package
Installed Wordpress on kevinbmccall.com
Deleted all files from local projects/kevinbmccall folder with git
Copied all files from siteground server to local folder
Added and Committed all of these changes to github repo
Tried Adding PHP Script to siteground server and setting up webhook
Issue: "I want the server to sync with my github repo so I can easily deploy to my live site every time I push to github"
Here is what I can do now:
I can make local changes to my project folder, add them and commit them no problem.
This correctly updates my github repo fine but does not seem to deploy yet.
If I make a change to my local folder, add, commit and check the status it will tell me of an origin/master that is behind in commits and recommends a push
I can push and even see some sort of request triggered because of that attempt at a PHP script I think but I was hoping to see the test txt files show up on the server and they did not.
My Thoughts:
I think my issue has to do with writing to the server and maybe the SSH setup through Siteground. I generated a key but never really used it and all of the online material from siteground points to their SG-Git tool in the c-panel. This requires a more expensive monthly plan and I am just a beginning developer trying to get a personal site up. I am sure the deployment can be accomplished without this upgrade.
Thank you to whomever replies. My goal is to learn as much as possible so I am even more interested in the explanation than the solution.

In my opinion, maybe you need GitHub Webhooks.
This is a demo
// Init vars
$LOCAL_ROOT = "/var/www/my_new_site";
$LOCAL_REPO_NAME = "public_html";
$LOCAL_REPO = "{$LOCAL_ROOT}/{$LOCAL_REPO_NAME}";
$REMOTE_REPO = "git#github.com:jonathanstark/my_new_site.git";
$DESIRED_BRANCH = "dev";
// Delete local repo if it exists
if (file_exists($LOCAL_REPO)) {
shell_exec("rm -rf {$LOCAL_REPO}");
}
// Clone fresh repo from github using desired local repo name and checkout the desired branch
echo shell_exec("cd {$LOCAL_ROOT} && git clone {$REMOTE_REPO} {$LOCAL_REPO_NAME} && cd {$LOCAL_REPO} && git checkout {$BRANCH}");
die("done " . mktime());

Related

How to update WordPress + Plugins in Elastic Beanstalk

There are many wonderful tutorials describing in great detail how to set up a horizontally scaled WordPress install in AWS' Elastic Beanstalk - that part is no problem. But I haven't found any follow-up advice yet on how to manage plugin updates after the initial setup, let alone updating wordpress-core itself. Does anybody know the most optimal way to do this?
This is the methodology I'm using so far, but I'm not sure if it is the best way:
Download the plugin's update file and unzip it. Remove and replace the relevant folder in /wp-content/plugins (local git repo)
Run the update in the live site like normal - to ensure that any database changes get pushed up to the RDS
eb deploy from the local repo to commit the file changes and make the update persistent
Is that a sane method? Could anything get corrupted down the line?
For updating wp-core, the tutorials I've read seem overcomplicated - basically rebuild the site from scratch every time an update comes out. Below is what I have been using (used it successfully for WP 5.0.2). Is there any chance of files and databases getting out of sync using this method?
Download and unzip the new wordpress version locally
Replace wp-admin, wp-includes, and the root files except for wp-config.php (local git repo)
Run the update in the live environment, so that any database changes get pushed up to RDS.
eb deploy
I've been running with the above methods for a while and feel pretty confident that they are sound. I only have a couple of tweaks thus far.
The following assumes an environment where there is one staging server outside of the horizontally scaling live environment. This could be further improved for a multi-developer environment using AWS Code Commit.
For Plugins:
Run the plugin update normally on the staging server (in wp-admin). Test everything to make sure the update is sound.
Remove the plugin's old folder from your local git repo and download the updated folder from the staging server using SFTP.
In the local repo, run git add -A && git commit -m "updated Plugin Name" && eb deploy
Run the same update in Live (in wp-admin). It will only apply to one server, but should guarantee that any database changes get pushed up to the single RDS.
Roll out the change to the live environment using the Software Versions page in the AWS Console (in Elastic Beanstalk)
Updating WP Core is almost identical except that instead of removing and replacing a single plugin directory, you will need to remove and replace /wp-admin/, /wp-includes/ and all of the files in the root folder except for wp-config.php

Work by team with git on localhost

I am a beginner to this topic and I start developing a part of the special theme on wamp (localhost) and another teammate work on the remaining part.In this regard, think that I should use Git but I do not know what folders (wamp and wp and theme and plugin) put in the repository and which client of git is more suitable for us (all of us do not have much knowledge and little time to do it). please guide me.
anything that needs installation keep it outside of git.
any file which is specific to your machine and local settings , keep t in .gitignore
all the files and folders that are required to setup the project in any new machine + any files that would be changed by your teammates , include in the git.
ideally, the git init should be done in the project root. ou can make a branch for every theme and merge later when finished.
I'd initialize GIT in the root directory of the template itself since you only make changes in that specific folder.
In this case, each template/theme can be considered as one single GIT repository.
Hope this answers your question.

How can I push a repository to my computer and my online server?

I have figured out how to create a repository on github. Now I am trying to push the repository to both my macbook pro and my server, which is hosted through http://namecheap.com, and be able to understand how to keep things simple. I am using wordpress on my server and I have a template theme. I want to edit my files on my mac and then push them to the website, keeping everything easy.
There is plenty of information out there on how to get started with github, so I will just focus on clearing up a misconception:
Now I am trying to push the repository to both my macbook pro and my server
You do not push from github to a server. You need to clone your github repo to your development (macbook) and production (server) environments.
git clone https://github.com/USERNAME/REPOSITORY.git
https://help.github.com/articles/fetching-a-remote/
Alternatively, you can push existing code to an empty repository by initializing locally, setting your remote and then pushing
git init
git add -A
git commit -m "Initial commit"
git remote add origin https://github.com/USERNAME/REPOSITORY.git
git push origin master
Once you have your repo setup, your typical workflow will look something like this:
Make changes in your development environment (macbook).
push those changes to github.
pull those changes from github in your production or staging environment (server).
One of the main things you need to use git this way is access to a terminal on the hosting serve, to push your files directly through git that should be installed as well.
Alternatively you can upload file using any available protocol such as (s)FTP or SSH direct to your server. In this case you'll be using git to version and manager your templates but not to upload or release them.
I've seen that cheapnames.com provides Softaculous as a mechanism to manage their servers. This software also provides synch and install scripts.

What's the best way to replace an old copy of WordPress with a fresh one and push to GitHub?

I have been version controlling my WordPress site with Git and pushing to GitHub for quite some time. I develop locally, push to GitHub, and pull from GitHub to my production server.
I would like to scrap my current WordPress core on my local environment and replace it with a fresh new copy to then be pushed to GitHub and pulled to my production server.
My question is...am I going to run into any sort of tracking errors wit Git by replacing my WordPress core? Any other suggestions for me when I do this?
I handle this by adding the Wordpress core as a subrepository. WordPress maintains a mirror of their SVN repository on GitHub. Then you can update to a new version easily by going into the subdirectory containing the WordPress core files and checking out the tag for the current version:
git fetch --tags
git checkout 3.3.2
The repo also includes beta releases, if you prefer those.
Here's the guide that I used to set up this process: Install and Manage WordPress with Git
I understood you're talking about updating wordpress. You should note that, like documented in the update instructions, during update you should
check the requirements
take a backup of your database contents
disable the plugins you have
So all this you should do regardless. Also, you should be sure to update your database content, too, if needed.
Wordpress contains instructions on updating using svn, and it seems it is, according to them, a perfectly fine approach to have. I would see no major difference for you to do essentially the same thing with git, provided you can tell exactly which files are appropriate to store on version control and which aren't.

How to develop using GIT on database driven website project?

I like to use a simple Git workflow for static web sites but I build Joomla and Wordpress sites a semi-regular basis too. However I am at a loss as to how to use Git with with database driven site development.
For a static site I would 'Push' to dev.websitename.com, then push to www.websitename.com once the dev site checks out. How would I mimic that process with database driven site like wordpress or joomla.
Thanks in advance for you insight!
You can definitely use Git with your website code, such as changes to your WordPress theme/plugin, exactly as you would if you are developing a static website.
However, you wouldn't use it for your database. Git provides version control for code, while WordPress and Joomla already manage content stored in the database. Plus, Git wouldn't understand a database, so it wouldn't have any advantage over a periodic backup, which you should already be doing. Take a look at running a dev copy of your site for how to download your database directly from your server.
By the way, if you use Git with WordPress/Joomla, you should add e.g. cache, logs, tmp to .gitignore. There are also lots of tutorials out there--try searching e.g. http://google.com/search?q=wordpress+git.
In addition Chris, you may want to embark on your Git workflow without the handy script approach (at least initially). The script approach and using Git hooks can sure seem sexy (well, because they are) and handy too, but initially why not go with a more manual cmd line approach, which will also help you familiarize yourself with Git.
Once you've got your repo setup (GitHub, Bitbucket, somewhere else) and you've pushed your latest to it and are ready to deploy to production or staging, just login to your host and from wherever you've initialized the git repo (site root, example: /site) just do a:
git pull origin master
This will fetch and merge your code. Good idea to test this on a dev/staging environment and if the merge goes well then do it in production.

Resources