Although has been using Git to do version management, has also used the GIT project deployment, but did not adhere to this habit, recently decided to learn, the following article is mainly about PHP implementation of the method of Git deployment tutorial, the article through the sample code introduced in very detailed, the need for friends can refer to the next.
Background
In small sites, it's quite handy to deploy PHP directly with git, and your remote site and local repository have a version control, and it's easy to track down problems or rollback.
Because in the small company to work, the original system is still using the traditional FTP upload deployment, deployment is too cumbersome, and not control the code on the line. On the Internet to find the next Git deployment tutorial, along the way down to meet a lot of pits, and now the whole process sent out, hoping to help everyone, the following words do not say more, come together to see the detailed introduction bar.
Account related
Useradd-m git//Add git account Ssh-keygen//Key generation, if you already have a can skip su git//switch to git account CD ~//switch to git account root directory mkdir. SSH//create. SSH directory CAT/Key storage directory/xx X.pub >> ~/.ssh/authorized_keys//Set Public key
Here must pay attention to the permissions problem, otherwise the key login cannot take effect, the corresponding permissions of each folder are as follows
. SSH folder permissions 700id_rsa 600id_rsa.pub 644authorized_keys 600
File permission settings
Put git in the same user group as the site that is running Nginx or Apache, such as www
VIM/ETC/PASSWD find git account and www account, change the group ID of git account to be consistent with WWW group identity
Site owner is set to git, user group is set to WWW//assuming nginx and git belong to www user group
Directory permission settings 775, file permissions set to 664
Warehouse Code
Server-side
CD Site Directory git init/Initialize directory
Git configuration
git config receive.denycurrentbranch ignore//Set up warehouse Accept code submission
Setting sudo free-secret
vim/etc/sudoers# Defaults Secure_path If there is no command you want, note that the command to add a # PHP will be added by default on the last side of Secure_path:/usr/local/php/bin "in Root all= ( All) The following line adds Git all= (All) Nopasswd:all # Save exit so that the command to restart the queue for Laravel can be used. # sudo php artisan queue:restart
Hook settings
CD. Git/hooks//Switch to site Hook directory touch post-receive//create receive commit when hook//hook file content is as follows: #!/bin/sh# set the default permissions for the account creation file Umask 002 unset git_dircd. Git checkout-f# execute php Hook logic/usr/bin/curl http (s)://domain/Hook text location/hook.php# If you use Laravel queue then you need to restart the queue process for new code to take effect # sudo php artisan Queue:restartexit 0
hook.php Content
<?php/** * git upload execution hooks *///todo security restrictions//todo Other hooks behavior//Clear Opcacheif (Version_compare (php_version, ' 5.5.0 ', ' >= ')) {OPCAC He_reset ();}
Add hooks to execute permissions
chmod a+x. git/hooks/post-receive
Local code
Git remote Add repository name SSH://GIT@IP Address:/Site Directory//Add remote repository git push remote repository name Master
Special attention
The user uploads the picture directory must be good to do the file neglect action, otherwise it is possible to clear the non-tracking files when this part of the file deleted, resulting in catastrophic results
Summarize
An example analysis of the binary search algorithm implemented by PHP
PHP implementation of the binary lookup algorithm example explained
Example of a string matching algorithm implemented by PHP