Created
September 7, 2022 03:01
-
-
Save adhikjoshi/7738629ea0e00392333f332834fa8494 to your computer and use it in GitHub Desktop.
PHP auto deploy code from GitHub to web-server
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Step 1 | |
create git repo in your hosting using below command | |
git init | |
Step 2 | |
Get personal access token from git user profile settings | |
Step 3 | |
Add remote origin to your repository | |
git remote add origin https://yourusername:Your_personal_access_token@github.com/yourusername/yourrepo.git | |
Replace details according to your needs and run this command, | |
Step 3 | |
change permission of files to fetch code | |
sudo chown -R www /www/wwwroot/website.com | |
Step 4 | |
Create git.php | |
you need shell_exec function enabled. | |
<?php | |
shell_exec("cd /www/wwwroot/beta.namastye.com && git pull origin main"); | |
?> | |
Step 5 | |
Add webhook in your repo, call yourwebsite.com/git.php everytime you make push request. | |
Step 6 | |
Done, now everytime you push code, your code will be updated on your server. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment