Last active
August 24, 2018 02:02
-
-
Save xiaoysh8/a4058985d21ed8ad70aad2e876534b91 to your computer and use it in GitHub Desktop.
git remote deployment
This file contains hidden or 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
| //远程建立空库 | |
| mkdir repos | |
| cd repos | |
| git init --bare --shared site.git | |
| cd /var/www/web | |
| //网站如果会在 /var/www/web下 | |
| git clone /var/www/web/repos/site.git site | |
| //本地 | |
| cd code/site | |
| git remote add site root@IPAddress:/var/www/web/repos/site.git | |
| //提交到远程 | |
| git add . | |
| git commit -a -m 'Push files to the server' | |
| git push --set-upstream site master //first time push | |
| git push site master | |
| //远程站点 | |
| cd /var/www/web/site | |
| git pull origin master | |
| //改权限,仅在第一次时 | |
| chown -R www-data /var/www/web/site/storage | |
| chmod -R 775 /var/www/web/site/public | |
| chmod -R 0777 /var/www/web/site/storage | |
| chgrp -R www-data /var/www/web/site/public | |
| chmod -R 775 /var/www/web/site/storage | |
| //处理不能远程推送 | |
| git config receive.denycurrentbranch ignore | |
| //远程账号 | |
| repos@IP:/www/repos | |
| 1 mkdir repos | |
| 2 cd repos | |
| Now we can initialize a new Git repository by using the following: | |
| 1 git init --bare --shared learninglaravel.git | |
| cd /var/www/learninglaravel.net | |
| Assuming that our Laravel app will be installed at /var/www/learninglaravel.net/laravel, we’ll | |
| use Git clone to clone the learninglaravel.git repository: | |
| 1 git clone /var/www/learninglaravel.net/repos/learninglaravel.git laravel | |
| If you already have the laravel directory, you should remove it by running this command: | |
| 1 rm -r laravel | |
| Now on our local machine or Homestead, go to our application directory: | |
| 1 cd Code/laravel | |
| Note: If you don’t have the laravel directory yet, be sure to create a new Laravel | |
| application and name it laravel. | |
| We can add a new git remote called learninglaravel here: | |
| 1 git remote add learninglaravel root@yourIPAddress:/var/www/learninglaravel.net/r\ | |
| 2 epos/learninglaravel.git | |
| Note: if you’re using a different site name, be sure to replace learninglaravel with | |
| your site name. Replace yourIPAddress with your real server IP address as well. | |
| That’s it for now! | |
| Deploying our application to a VPS using Git | |
| Once we have a Git remote (learninglaravel), we can push our files to the server using Git: | |
| 1 git add . | |
| 2 git commit -a -m "Push files to the server" | |
| 3 git push learninglaravel master | |
| Now our learninglaravel.git repository should contain all the files. | |
| On our server, navigate to the laravel directory: | |
| Chapter 3: Deployment Recipes 210 | |
| 1 cd /var/www/learninglaravel.net/laravel | |
| Next, we can use git pull to fetch learninglaravel.git repository and merge the changes into the | |
| laravel repository: | |
| 1 git pull origin master | |
| Once that step is done, we must give the directories proper permissions: | |
| 1 chown -R www-data /var/www/learninglaravel.net/laravel/storage | |
| 2 chmod -R 775 /var/www/learninglaravel.net/laravel/public | |
| 3 chmod -R 0777 /var/www/learninglaravel.net/laravel/storage | |
| 4 | |
| 5 chgrp -R www-data /var/www/learninglaravel.net/laravel/public | |
| 6 chmod -R 775 /var/www/learninglaravel.net/laravel/storage | |
| Note: We only need to do this one time. | |
| To ensure that everything is working fine, let’s visit our site |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment