Skip to content

Latest commit

 

History

15 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 

Repository files navigation

Best way to code deploy on any VPS using Git

-------------- Server side Work ---------------------

Create a Repo dir on the server

mkdir /var/repo

Create a bare git repo inside /var/repo

mkdir repo_name.git

Initialize the Bare git Repo inside repo_name.git

git init --bare

Now go inside hooks dir and create a file post-receive

vim post-receive

post-receive is bash file so

#!/bin/sh
git --work-tree=/var/www/html --git-dir=/var/repo/repo_name.git checkout -f

save file post-receive and make it executable chmod +x post-receive

----------------- client side Work ---------------------

Inside The project dir initialize git and add new remote to your vps

git remote add live ssh://user@address/var/repo/repo_name.git git push live master

But Before all of these configuration set ssh-keygen features https://github.com/gitachyut/ssh-key-setup

One more way to code deploy the whole project (One Time Code Deploy)

This is not step by step code deploy way it's one time code deploy.

<?php
	$Local_Root = "/home/site/web/xyz.com/public_html";
	$App_name = "app";
	$Local_repo = "{$Local_Root}/{$App_name}";
	$Git_repo = "https://github.com/gitachyut/abc.git";
	$Git_repo_name = "abc";
	if(file_exists($Local_repo)){
		shell_exec("rm -rf {$Local_repo} "); 
	}
	echo shell_exec(" cd {$Local_Root} && git clone {$Git_repo} && mv {$Git_repo_name} {$App_name}  && git checkout master ");
	die("done");
?>

ssh private key set up for git push

create a config file in ~/.ssh dir

host host_url/ip  
 HostName host_url/ip  
 IdentityFile ~/.ssh/your_private_key  
 User user_name  

git remote add live ssh://user_name@host_url_ip/directory/full/path/repo.git

About

Best way to code deploy on any VPS

Resources

Stars

0 stars

Watchers

2 watching

Forks

Releases

Packages

Used by

Contributors