OSDN Git Service

Regular updates
[twpd/master.git] / heroku.md
1 ---
2 title: Heroku
3 category: Devops
4 layout: 2017/sheet
5 updated: 2017-10-11
6 description: |
7   A one-page reference to common Heroku-CLI commands.
8 intro: |
9   [Heroku](http://heroku.com/) is a web hosting platform supporting many languages, and this guide is a reference to Heroku's [command-line interface](http://heroku.com/).
10 ---
11
12 ### `create` - Create an app
13
14 ```bash
15 heroku create sushi
16 ```
17
18 ```bash
19 git push heroku master
20 ```
21
22 ### `access` - Collaboration
23
24 #### Manage collaborators
25
26 ```bash
27 heroku access                     # List
28 heroku access:add me@xy.com
29 heroku access:remove me@xy.com
30 ```
31
32 #### Transfer to another owner
33
34 ```bash
35 heroku apps:transfer new@owner.com
36 ```
37
38 ### `logs` - Show logs
39
40 ```bash
41 heroku logs
42 heroku logs -t      # --tail (stream)
43 heroku logs -s app  # --source (only on app logs)
44 ```
45
46 ### `releases`
47
48 ```bash
49 heroku releases
50 heroku releases:info v25
51 heroku rollback
52 ```
53
54 ### `pg` - PostgreSQL
55
56 #### Start a database
57
58 ```bash
59 heroku addons:add heroku-postgresql
60 ```
61
62 #### Enable backups
63
64 ```bash
65 heroku addons:add pgbackups:auto-month
66 ```
67
68 See: [Heroku PostgreSQL](https://devcenter.heroku.com/articles/heroku-postgresql) _(devcenter.heroku.com)_
69
70 ### `config` - Environment var configuration
71
72 #### Listing
73
74 ```bash
75 heroku config        # List
76 heroku config -s     # List in shell format
77 ```
78
79 #### Getting
80
81 ```bash
82 heroku config:get KEY
83 ```
84
85 #### Setting
86
87 ```bash
88 heroku config:set KEY=val
89 heroku config:set KEY1=val KEY2=val ...
90 ```
91
92 ```bash
93 heroku config:unset KEY1
94 ```
95
96 ### `apps` - Applications
97
98 ```bash
99 heroku apps                  # list
100 heroku apps:create [NAME]
101 heroku apps:destroy --app APP
102 heroku apps:info
103 heroku apps:open             # open in browser
104 heroku apps:rename NEWNAME
105 ```
106
107 ### `maintenance`
108
109 ```bash
110 heroku maintenance:on
111 ```
112
113 ```bash
114 heroku maintenance:off
115 ```
116
117 ## Processes
118
119
120 ### `ps` - Managing processes
121
122 ```bash
123 heroku ps              # list
124 heroku ps:scale web=1  # spawn more dynos
125 ```
126
127 ### `restart`
128
129 ```bash
130 heroku restart
131 ```
132
133 ### `run` - Running tasks
134
135 ```bash
136 heroku run bash
137 heroku run console                  # Rails console
138 heroku run rake assets:precompile
139 ```
140
141 ## Domains
142
143 ### `domains` - Custom domains
144
145 #### Add both!
146
147 ```bash
148 heroku domains:add example.com
149 heroku domains:add www.example.com
150 ```
151
152 #### Removing
153
154 ```bash
155 heroku domains:clear
156 heroku domains:remove example.com
157 ```
158
159 See: [Custom domains](https://devcenter.heroku.com/articles/custom-domains) _(devcenter.heroku.com)_
160
161 ### Wildcard domains
162
163 ```bash
164 heroku addons:add wildcard_domains
165 ```
166
167 ```bash
168 *.yourdomain.com => heroku.com
169 ```
170
171 ## Other tricks
172
173 ### htpasswd (for PHP apps)
174
175 Create an `.htaccess` file in the webroot:
176
177 ```bash
178 AuthUserFile /app/www/.htpasswd
179 AuthType Basic
180 AuthName "Restricted Access"
181 Require valid-user
182 ```
183
184 Create a `.htpasswd` file:
185
186 ```bash
187 $ htpasswd -c .htpasswd [username]
188 ```
189
190 See: [gist.github.com](https://gist.github.com/3316425)
191
192 ## References
193
194  * <https://addons.heroku.com/>
195  * <https://devcenter.heroku.com/>