Goal: Deploying code to remote server via git push
Let's say you have a website hosted on a VPS, and you have a local copy of its source code on your laptop. As your needs change, you will inevitably want to make some changes to the website. If you are using git to track changes to your source code, you can use another functionality ofgit
called git hooks
to push your local changes to the remote server, and have the server deploy it for you.
This is the crudest, and yet very effective way of getting started with DevOps. A practive which merges the Development workflow closely with that of Operations.
Prerequisites
To follow along this tutorial you will need:- A very basic familiarity with the Linux command line.
- A very basic idea of how to use git, creating a repository and committing changes.
- A VPS with a public IP for which you have key-based SSH access as root user.
Setting the stage
We will start with a very simple setup where an Nginx Server is serving plain HTML files on port 80 and we will make changes to these files locally and push the changes to the server running Nginx. If you follow along, by the end of the setup, just reloading the webpage at http://your_ip_address will show you all the changes that were pushed without you having to manually login into the server.Local setup
To start with, you will need git installed on your local computer. Windows users should look at git-scm and if you are using Linux or WSL2 then you can install it via your package manager. Similarly, macOS users can install git via brew package manager or by simplying installing Xcode or Xcode Command Line Tools. Great! Now that we have git installed, we create a simple git repo, and add some very simple HTML code in it.$ mkdir html
$ git init
Initialized empty Git repository in C:/Users/r/html/.git/
Create a file in ~/html
directory named index.html
andContinue reading this article
by subscribing to our newsletter.
Subscribe nowby subscribing to our newsletter.
A note about tutorials: We encourage our users to try out tutorials, but they aren't fully supported by our team—we can't always provide support when things go wrong. Be sure to check which OS and version it was tested with before you proceed.
If you want a fully managed experience, with dedicated support for any application you might want to run, contact us for more information.