|
| 1 | +git-deploy-php 2.0 |
| 2 | +================== |
| 3 | + |
| 4 | +git-deploy-php allows quick and easy deployments of Git repositories to FTP or SFTP servers. You DO NOT need to have git installed on the server. Great for shared servers where you have no shell access, and to save bandwidth and time by only uploading the files that have changed. |
| 5 | + |
| 6 | +Usage |
| 7 | +----- |
| 8 | + |
| 9 | +1. Drop `git-deploy` into your project. |
| 10 | +2. Create the `deploy.ini` file (see below). |
| 11 | +3. Run `php git-deploy` in your command line / terminal. |
| 12 | + |
| 13 | +And there you go. It's that simple. |
| 14 | + |
| 15 | +### deploy.ini |
| 16 | + |
| 17 | +In the root directory of your project, create a `deploy.ini` file. |
| 18 | + |
| 19 | +*Note: `deploy.ini` is the default file's name. You can name it anything you want (for example, `staging.ini`), and run `php git-deploy staging`. That serves as an easy way to separate the deployment to staging and production servers.* |
| 20 | + |
| 21 | + ; This is a sample deploy.ini file. |
| 22 | + |
| 23 | + [example] |
| 24 | + |
| 25 | + skip = false |
| 26 | + user = example |
| 27 | + pass = password |
| 28 | + host = example.com |
| 29 | + port = 21 |
| 30 | + path = /path/to/installation |
| 31 | + passive = true |
| 32 | + |
| 33 | + ; If that seemed too long for you, you can specify servers like this: |
| 34 | + [ftp://example:password@example.com:21/path/to/installation] |
| 35 | + |
| 36 | +The first time it's executed, git-deploy will assume that your deployment server is empty, and will upload all the files in the git repository. |
| 37 | +If you've already deployed your project's files previously, you have to create a REVISION file on your deployment server, containing the hash of the commit it's currently in. |
| 38 | + |
| 39 | +To get the hash of the current commit, you can use: |
| 40 | + |
| 41 | + git rev-parse HEAD |
| 42 | + |
| 43 | +Advanced Usage |
| 44 | +-------------- |
| 45 | + |
| 46 | +### Using SFTP |
| 47 | + |
| 48 | +To use SFTP, you have two options. With the long-form deploy.ini configuration, you just need to add `scheme = sftp`. With the short-form, you just need to change `ftp://` to `sftp://`. |
| 49 | + |
| 50 | +If you want to use a private key to login instead of a password, you can do so by adding the following to your deploy.ini configuration: |
| 51 | + |
| 52 | + sftp_key = /path/to/key/file |
| 53 | + |
| 54 | +### Revert a deployment |
| 55 | + |
| 56 | +If you deployed using git-deploy and you want to go back to the previous deployment, all you need is `--revert`: |
| 57 | + |
| 58 | + php git-deploy --revert [your_ini_file_name] |
| 59 | + |
| 60 | +If you use deploy.ini (i.e., if you didn't give the .ini file a custom name), then you can simply use: |
| 61 | + |
| 62 | + php git-deploy --revert |
| 63 | + |
| 64 | +### Deploy a specific commit |
| 65 | + |
| 66 | + php git-deploy -r [your_commit_hash] [your_ini_file_name] |
| 67 | + |
| 68 | +If you use deploy.ini (i.e., if you didn't give the .ini file a custom name), then you can simply use: |
| 69 | + |
| 70 | + php git-deploy -r [your_commit_hash] |
| 71 | + |
| 72 | +Note: If you want to, instead of using a commit hash, you can use a tag, or any other valid reference. |
| 73 | + |
| 74 | +### Deploy the latest commit from different branches |
| 75 | + |
| 76 | +Sometimes you might need to deploy code from different branches to different servers (e.g. from the develop branch to the staging server, and from the master branch to the production server). This is easy to do. Add the following to your deploy.ini configuration: |
| 77 | + |
| 78 | + branch = develop |
| 79 | + |
| 80 | +git-deploy will then always deploy the latest commit from the develop branch to the server. |
| 81 | + |
| 82 | +### List files to upload and delete |
| 83 | + |
| 84 | +Sometimes, you may just want to see what files are to be uploaded to the FTP server, and which ones are to be deleted. In this case, you can use `-l` (lowercase L): |
| 85 | + |
| 86 | + php git-deploy -l [your_ini_file_name] |
| 87 | + |
| 88 | +If you use deploy.ini (i.e., if you didn't give the .ini file a custom name), then you can simply use: |
| 89 | + |
| 90 | + php git-deploy -l |
| 91 | + |
| 92 | +Pretty simple, huh? |
| 93 | + |
| 94 | +### Clean remote directories automatically |
| 95 | + |
| 96 | +If you have directories you use for caching that you'd like to clear when you deploy a new commit, you can add the following to your .ini file: |
| 97 | + |
| 98 | + clean_directories[] = folder/to/clean |
| 99 | + clean_directories[] = another/folder |
| 100 | + |
| 101 | +And git-deploy will empty those directories for you. |
| 102 | + |
| 103 | +### Ignore files |
| 104 | + |
| 105 | +If you have files that you don't want uploaded to your server, you can add the following to your .ini file: |
| 106 | + |
| 107 | + ignore_files[] = file/toignore.txt |
| 108 | + ignore_files[] = another/file/toignore.php |
| 109 | + |
| 110 | +And git-deploy will ignore those files. |
| 111 | + |
| 112 | +### Upload untracked files |
| 113 | + |
| 114 | +If you have files that you're not tracking in your repository but that you'd still like to upload, you can add the following to your .ini file: |
| 115 | + |
| 116 | + upload_untracked[] = folder/to/upload |
| 117 | + upload_untracked[] = another/file/toignore.php |
| 118 | + |
| 119 | +And git-deploy will automatically upload those files for you. This is super useful for things like Composer, which recommends that you don't track the vendor folder in your git repo. This way, you can have git-deploy upload the entire vendor folder to the server, and you won't need Composer installed on it. |
| 120 | + |
| 121 | +### Enable maintenance mode on your website for the duration of the deployment |
| 122 | + |
| 123 | +If you want to take your website down with an "under maintenance" page to prevent users from seeing errors during the middle of a deployment, you can ask git-deploy to automatically turn maintenance mode on prior to deploying, and off at the end of the deployment. |
| 124 | + |
| 125 | +It works by modifying a file specified by the `maintenance_file` option in your `deploy.ini`. It'll set that file's contents to `maintenance_on_value` at the start of the deployment and then set its contents to `maintenance_off_value` at the end of the deployment. For example: |
| 126 | + |
| 127 | + maintenance_file = 'maintenance.php' |
| 128 | + maintenance_on_value = '<?php $under_maintenance = true;?>' |
| 129 | + maintenance_off_value = '<?php $under_maintenance = false;?>' |
| 130 | + |
| 131 | +Note: It's up to your application to detect whether or not maintenance mode is on by checking the `maintenance_file`, and proceed accordingly. |
| 132 | + |
| 133 | +How It Works |
| 134 | +------------ |
| 135 | +git-deploy stores a file called REVISION on your server. This file contains the hash of the commit that you've deployed to that server. When you run git-deploy, it downloads that file and compares the commit reference in it with the commit you're trying to deploy to find out which files to upload. |
| 136 | + |
| 137 | +git-deploy also stores a REVISION file for each submodule in your repository, as well as a PREVIOUS_REVISION file for both your repository and each submodule. This allows it to keep your submodules up-to-date, as well as to know which commit to go back to you when you run `php git-deploy --revert`. |
| 138 | + |
| 139 | +Suggestions, questions and complaints. |
| 140 | +---------- |
| 141 | + |
| 142 | +If you've got any suggestions, questions, or anything you don't like about git-deploy, [you should create an issue here](https://github.com/BrunoDeBarros/git-deploy-php/issues). Feel free to fork this project, if you want to contribute to it. |
0 commit comments