I am writing HTML5 Myanmar books using HTML. So, I was using github pages. However, my book is not opensource and I don’t want to allow other people to fork or edit. So, I deleted the repo. After that , I love so much git style publishing. We don’t need to upload the code. I wrote some text and just use git push to update the website. So, I tried appfog. It can do like gh pages. I just need to call
af update mybook . However, we can’t use with own domain if we are using free account. So, I decied to make on my own git server.
Setup git server
First , need to install git.
sudo apt-get install git
Second, we need to add ssh key for pushing the new code without entering password again and again.
Let get your ssh key from your local computer. If you don’t know check on github. You will get id_rsa.pub at ~/.ssh/id_rsa.pub . Copy the ssh public key.
And then copy the text.
We need to add your local public key to server. First , let create temp file.
crete file and paste your key in /tmp/id_rsa.myusername.pub.
cat /tmp/id_rsa.john.pub >> ~/.ssh/authorized_keys
Now ssh key has been authroized and no need to enter password again.
Let create git server on your server.
mkdir /opt/git mkdir /opt/git/myproject.git cd /opt/git/myproject.git git --bare init
Now, we have made the git repo at /opt/git/myproject.git. But we need to create hook for checkout at server after push from local computer.
cd /opt/git/myproject.git/hooks vi post-update
GIT_WORK_TREE=/var/www/yourwebsite/ git checkout -f
In this code
git checkout -f is git command and you can use any git command.
Last thing to do it change the permission.
sudo chmod +x /opt/git/myproject.git/hooks/post-update
Publish website using git
Let create a folder at local for our private git repo.
mkdir myproject cd myproject git init touch README.md git add . git commit -m 'init commit' git remote add origin [email protected]:/opt/git/myproject.git git push origin master
After that , check at /var/www/yourwebsite/ . You will see README.md at there. Ok, put all files in your myproject folder at local computer
git add . git commit -m 'publish website' git push origin master
And then check again /var/www/yourwebsite/ on your server. All of your files will be there and no need to uplaod using SFTP or FTP.