GIT Jekyll

Deploy a Jekyll site on cPanel with GIT

We want to create a Jekyll site hosted on a cPanel server and using a GIT repository for versioning.

This could be done with GitHub and a WebHook, but in this case, lets keep the GIT repository on the server.

This assumes we have a cPanel hosted account with SSH access and Jekyll installed on the server. The basic process will be

  1. Create a GIT repository on the server – jekyll.git
  2. Create a location for the uncompiled source files – source_code
  3. Create a GIT hook to extract the changed source files and the build them into the public_html folder
  4. Clone the GIT Repository on the local machine and edit it

Log into the Server

ssh user@domain.com​

​Set up the Server

git init --bare jekyll.git
git clone jekyll.git source_code

Set up GIT Hook on post-receive

touch jekyll.git/hooks/post-receive
chmod +x jekyll.git/hooks/post-receive
vim jekyll.git/hooks/post-receive

Add hook code

#!/bin/sh
cd $HOME/source_code/ || exit
unset GIT_DIR
git pull origin master && jekyll build --destination $HOME/public_html

You can test this by running

cd ~/source_code
jekyll build --destination ../public_html

To make sure that Jekyll can be found in the GIT Hook, we can also add an env file

env > .ssh/environment

Now exit the server and find a location on the local machine to clone the repository.

git clone ssh://user@domain.com:22/home/user/jekyll.git

This command can be used to test everything works

echo `date` >> index.php && git commit -a -m "index" && git push

done

Leave a Reply