Most readers will be familiar with github. Over recent years Github has become the most popular repository for open source software on the internet. Github is based on the git distributed version control system. Many newcomers to distributed version control confuse the two and sometimes use them interchangeably. The git version control software, on which github depends, allows for multiple distributed users to easily collaborate on software development. Git has been one of the big drivers of the explosion in the popularity and use of open source software over recent times.
Github is a website, albeit a very popular website, where users can (for free) maintain their software repositories. There are a number of other similar websites offering this service. The most notable of these is bitbucket.org.
Although it's beyond the scope of this guide, the history of both git and github is very interesting. I would encourage readers to read up on it as it offers both a background in the landscape of software development along with some useful cautionary tales for entrepreneurs and startups.
In this section we will host our own repository on our newly commissioned server. This will allow us to quickly, seamlessly and continuously deploy software devops-style. If you don't know what devops is - don't worry, it will soon become apparent.
There are a number of good Windows git software packages such as sourcetree. Git is also built in to many integrated development environments such as Netbeans, Eclipse and PHPStorm. For the purposes of this guide, I am recommending you use git for Windows. This is a straightforward command-line implementation of git that will allow you to copy and paste the commands directly into your command line. It also has the benefit of being similar in use and feel to git on Linux.
Git for windows can be found here. https://git-scm.com/download/win
After you've installed the software go to the CLI and change directory into your application.
To create a git repository in this folder type
Before adding files to your repository you need to create a .gitignore file. This will allow you to control which files and folders are added to the repository and which are ignored. Create a file called .gitignore in the root folder of your new repository(\xampp\htdocs\tennisclub) and add the following lines
phalcon.bat cache/* !cache/.gitkeep
Including the line cache/* in the .gitignore file will cause all files which are added to the cache folder to be ignored in terms of git. This makes sense as the cache files are server dependent. We don't want to upload windows cache files to the Linux server as they could cause a conflict. The only problem with this is that the git cache folder will be removed from the repository unless there is at least one file in there. The last line is an over-ride to ensure that a file called .gitkeep will not be ignored - this over-rides the wildcard from the previous line in the case of this one file. For this to work you need to create a file called .gitkeep and include it in the cache folder. Go ahead and do that now. It doesn't matter what's in the file - I normally just put the word gitkeep.
Now that we've set up the .gitignore file correctly we can add files to the repository and perform an initial commit. To add the current folder and all subfolders and files in your application to the repository - from the \xampp\htdocs\tennisclub type
git add .
To perform an initial commit type
git commit -am "initial commit"
The -a stands for "add" and the m for "message". This basically will add any files in your application that are being tracked to your repository - along with a message in which you would normally explain the purpose of your change to the software.
Any time you make a modification to your application to your repository from here on out, run git commit -am "message". This will pick up on any files that have been modified and change those files in the repository. Normal procedure would be not to do this until you have made a successful change to your application.
Next you need to add a remote repository for your application. To do this type
git remote add origin ssh://firstname.lastname@example.org/~/tennisclub
where xxx.yyy.zzz.www is the IP address of your cloud VM.
In order to push code into the git repository that you set up on the server, you need to ensure that Git for Windows can access the private key for that account. Firstly you need to create a folder called .ssh in your "home" folder. Your home folder on windows (normally c:\users\yourusername) can be accessed from the command line by typing the following
To create a folder in this folder called .ssh type:
Take the private key file you saved earlier for your application account (in my case this is called newPhalconVM.private) and copy it into your newly created .ssh folder.
In addition, within this folder, you need to create a file called simply 'config' (no file extension)
Create the following settings within this config file
Host xxx.yyy.zzz.www Hostname xxx.yyy.zzz.www PubKeyAuthentication yes IdentitiesOnly yes User tennisclub IdentityFile ~/.ssh/newPhalconVM.private
Replace xxx.yyy.zzz.www with the IP Address of your server. The .ssh folder can contain many private key files. Similarly, within the config file, there can be many sections in the file in the style of the section above. For each key file you use for your various servers/accounts, there needs to be an entry in the config file which takes the above format.
Now you're finally ready to push/deploy some code. Return to the command line and change directory into your project folder.
From the command prompt, to push your code, type
git push origin master
As you have never accessed this server before ssh does not recognise it. It will ask you for permission to add the ECDSA fingerprint of this server to the known_hosts file. Once this fingerprint it's stored in known_hosts you will not be asked again. This is to ensure you are not falling victim to a hack which is inviting you to access a server which is unknown to you. Once you say yes your code will be pushed to the server and you will see a message like the one below.
At this point, the contents of your working directory will be deployed to the tennisclub folder in your tennisclub user account. The symbolic link from your document root folder, together with your VirtualHost file will ensure that when you visit http://your_server_ip_address/tennisclub you access your application in the cloud as follows.
While this has been a long and fairly arduous process in relation to a lot of other sections in this site, there has been an awful lot of learning along the way. You've got to grips(to a certain extent) with a new operating system and you've managed to compile an application from the source code. Even more importantly you're now starting to complete the picture of how web-based MVC software applications are hosted in a cloud environment.