When local development is complete, it is usually deployed on the server, someone will use FTP, some people will use the SCP, FTP and SCP to facilitate our adoption and also to tar or zip, these practices are also good, but it has some problems
1. All updates, no matter whether some files are modified, to retransmit the server, waste of time and traffic
2. Multiple server repeat upload
3. After the code update, some of the subsequent operations are not automated
The above problem can be solved by direct remote execution via SSH, but need to write some shell scripts, is there a simpler and more efficient way? Yes, that's the hook! of using version management tools.
Here I say is version management tools rather than git, because SVN, Git, Hg are the corresponding hooks, the principle is similar. Here's a detailed idea of git.
Server-side operations
First create a naked library, why is the naked library? Because this library is not really used for modification, we do not allow the code to be modified on the server, we just use it as a place for code transfer:
Copy Code code as follows:
CD Gitroot
mkdir ProjectName
CD ProjectName
Git init--bare
Add our Hooks
Copy Code code as follows:
Cd/hooks
Touch post-receive
Edit Post-receive content for the following, where Sites/projectname is where we store the site code
Copy Code code as follows:
Env-i Git archive Master | Tar-x-c/sites/projectname
echo "Remote Update Complete"
Actions for local git
Local we just need to add a remote library, the need to deploy to push to the remote library on the line, we have added a remote library named publish
Copy Code code as follows:
Git remote add publish Username@xx.xx.xx.xx:/home/gitroot/projectname
git push publish Master
Where it can be fortified.
Here demo is a simple small web site deployment process, complex circumstances we can also add static resource version update, server restart and so on, extrapolate, maximum program automation of our work.