0eb67be4953475cae5bc3a693f9b8ae372738370
[mediagoblin.git] / docs / source / siteadmin / deploying.rst
1 .. MediaGoblin Documentation
2
3 Written in 2011, 2012 by MediaGoblin contributors
4
5 To the extent possible under law, the author(s) have dedicated all
6 copyright and related and neighboring rights to this software to
7 the public domain worldwide. This software is distributed without
8 any warranty.
9
10 You should have received a copy of the CC0 Public Domain
11 Dedication along with this software. If not, see
12 <http://creativecommons.org/publicdomain/zero/1.0/>.
13
14 .. _deploying-chapter:
15
16 =====================
17 Deploying MediaGoblin
18 =====================
19
20 GNU MediaGoblin is fairly new and so at the time of writing, there
21 aren't easy package-manager-friendly methods to install MediaGoblin.
22 However, doing a basic install isn't too complex in and of itself.
23
24 There's an almost infinite way to deploy things... for now, we'll keep
25 it simple with some assumptions and use a setup that combines
26 mediagoblin + virtualenv + fastcgi + nginx on a .deb or .rpm based
27 GNU/Linux distro.
28
29 .. note::
30
31 These tools are for site administrators wanting to deploy a fresh
32 install. If instead you want to join in as a contributor, see our
33 `Hacking HOWTO <http://wiki.mediagoblin.org/HackingHowto>`_ instead.
34
35 There are also many ways to install servers... for the sake of
36 simplicity, our instructions below describe installing with nginx.
37 For more recipes, including Apache, see
38 `our wiki <http://wiki.mediagoblin.org/Deployment>`_.
39
40 Prepare System
41 --------------
42
43 Dependencies
44 ~~~~~~~~~~~~
45
46 MediaGoblin has the following core dependencies:
47
48 - Python 2.6 or 2.7
49 - `python-lxml <http://lxml.de/>`_
50 - `git <http://git-scm.com/>`_
51 - `SQLite <http://www.sqlite.org/>`_/`PostgreSQL <http://www.postgresql.org/>`_
52 - `Python Imaging Library <http://www.pythonware.com/products/pil/>`_ (PIL)
53 - `virtualenv <http://www.virtualenv.org/>`_
54
55 On a DEB-based system (e.g Debian, gNewSense, Trisquel, Ubuntu, and
56 derivatives) issue the following command::
57
58 sudo apt-get install git-core python python-dev python-lxml \
59 python-imaging python-virtualenv
60
61 On a RPM-based system (e.g. Fedora, RedHat, and derivatives) issue the
62 following command::
63
64 yum install python-paste-deploy python-paste-script \
65 git-core python python-devel python-lxml python-imaging \
66 python-virtualenv
67
68 Configure PostgreSQL
69 ~~~~~~~~~~~~~~~~~~~~
70
71 .. note::
72
73 MediaGoblin currently supports PostgreSQL and SQLite. The default is a
74 local SQLite database. This will "just work" for small deployments.
75
76 For medium to large deployments we recommend PostgreSQL.
77
78 If you don't want/need postgres, skip this section.
79
80 These are the packages needed for Debian Wheezy (testing)::
81
82 sudo apt-get install postgresql postgresql-client python-psycopg2
83
84 The installation process will create a new *system* user named ``postgres``,
85 it will have privilegies sufficient to manage the database. We will create a
86 new database user with restricted privilegies and a new database owned by our
87 restricted database user for our MediaGoblin instance.
88
89 In this example, the database user will be ``mediagoblin`` and the database
90 name will be ``mediagoblin`` too.
91
92 To create our new user, run::
93
94 sudo -u postgres createuser mediagoblin
95
96 then answer NO to *all* the questions::
97
98 Shall the new role be a superuser? (y/n) n
99 Shall the new role be allowed to create databases? (y/n) n
100 Shall the new role be allowed to create more new roles? (y/n) n
101
102 then create the database all our MediaGoblin data should be stored in::
103
104 sudo -u postgres createdb -E UNICODE -O mediagoblin mediagoblin
105
106 where the first ``mediagoblin`` is the database owner and the second
107 ``mediagoblin`` is the database name.
108
109 .. caution:: Where is the password?
110
111 These steps enable you to authenticate to the database in a password-less
112 manner via local UNIX authentication provided you run the MediaGoblin
113 application as a user with the same name as the user you created in
114 PostgreSQL.
115
116 More on this in :ref:`Drop Privileges for MediaGoblin <drop-privileges-for-mediagoblin>`.
117
118
119 .. _drop-privileges-for-mediagoblin:
120
121 Drop Privileges for MediaGoblin
122 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
123
124 As MediaGoblin does not require special permissions or elevated
125 access, you should run MediaGoblin under an existing non-root user or
126 preferably create a dedicated user for the purpose of running
127 MediaGoblin. Consult your distribution's documentation on how to
128 create "system account" or dedicated service user. Ensure that it is
129 not possible to log in to your system with as this user.
130
131 You should create a working directory for MediaGoblin. This document
132 assumes your local git repository will be located at
133 ``/srv/mediagoblin.example.org/mediagoblin/`` for this documentation.
134 Substitute your prefer ed local deployment path as needed.
135
136 This document assumes that all operations are performed as this
137 user. To drop privileges to this user, run the following command::
138
139 su - [mediagoblin]
140
141 Where, "``[mediagoblin]``" is the username of the system user that will
142 run MediaGoblin.
143
144 Install MediaGoblin and Virtualenv
145 ----------------------------------
146
147 .. note::
148
149 MediaGoblin is still developing rapidly. As a result
150 the following instructions recommend installing from the ``master``
151 branch of the git repository. Eventually production deployments will
152 want to transition to running from more consistent releases.
153
154 Issue the following commands, to create and change the working
155 directory. Modify these commands to reflect your own environment::
156
157 mkdir -p /srv/mediagoblin.example.org/
158 cd /srv/mediagoblin.example.org/
159
160 Clone the MediaGoblin repository::
161
162 git clone git://gitorious.org/mediagoblin/mediagoblin.git
163
164 And set up the in-package virtualenv::
165
166 cd mediagoblin
167 (virtualenv --system-site-packages . || virtualenv .) && ./bin/python setup.py develop
168
169 .. note::
170
171 If you have problems here, consider trying to install virtualenv
172 with the ``--distribute`` or ``--no-site-packages`` options. If
173 your system's default Python is in the 3.x series you may need to
174 run ``virtualenv`` with the ``--python=python2.7`` or
175 ``--python=python2.6`` options.
176
177 The above provides an in-package install of ``virtualenv``. While this
178 is counter to the conventional ``virtualenv`` configuration, it is
179 more reliable and considerably easier to configure and illustrate. If
180 you're familiar with Python packaging you may consider deploying with
181 your preferred method.
182
183 Assuming you are going to deploy with FastCGI, you should also install
184 flup::
185
186 ./bin/easy_install flup
187
188 This concludes the initial configuration of the development
189 environment. In the future, when you update your
190 codebase, you should also run::
191
192 ./bin/python setup.py develop --upgrade && ./bin/gmg dbupdate
193
194 Deploy MediaGoblin Services
195 ---------------------------
196
197 Configure MediaGoblin to use the PostgreSQL database
198 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
199
200 If you are using postgres, edit the ``[mediagoblin]`` section in your
201 ``mediagoblin_local.ini`` and put in::
202
203 sql_engine = postgresql:///mediagoblin
204
205 if you are running the MediaGoblin application as the same 'user' as the
206 database owner.
207
208
209 Update database data structures
210 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
211
212 Before you start using the database, you need to run::
213
214 ./bin/gmg dbupdate
215
216 to populate the database with the MediaGoblin data structures.
217
218
219 Test the Server
220 ~~~~~~~~~~~~~~~
221
222 At this point MediaGoblin should be properly installed. You can
223 test the deployment with the following command::
224
225 ./lazyserver.sh --server-name=broadcast
226
227 You should be able to connect to the machine on port 6543 in your
228 browser to confirm that the service is operable.
229
230 .. _webserver-config:
231
232 Connect the Webserver to MediaGoblin with FastCGI
233 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
234
235 This section describes how to configure MediaGoblin to work via
236 FastCGI. Our configuration example will use nginx, however, you may
237 use any webserver of your choice as long as it supports the FastCGI
238 protocol. If you do not already have a web server, consider nginx, as
239 the configuration files may be more clear than the
240 alternatives.
241
242 Create a configuration file at
243 ``/srv/mediagoblin.example.org/nginx.conf`` and create a symbolic link
244 into a directory that will be included in your ``nginx`` configuration
245 (e.g. "``/etc/nginx/sites-enabled`` or ``/etc/nginx/conf.d``) with
246 one of the following commands (as the root user)::
247
248 ln -s /srv/mediagoblin.example.org/nginx.conf /etc/nginx/conf.d/
249 ln -s /srv/mediagoblin.example.org/nginx.conf /etc/nginx/sites-enabled/
250
251 Modify these commands and locations depending on your preferences and
252 the existing configuration of your nginx instance. The contents of
253 this ``nginx.conf`` file should be modeled on the following::
254
255 server {
256 #################################################
257 # Stock useful config options, but ignore them :)
258 #################################################
259 include /etc/nginx/mime.types;
260
261 autoindex off;
262 default_type application/octet-stream;
263 sendfile on;
264
265 # Gzip
266 gzip on;
267 gzip_min_length 1024;
268 gzip_buffers 4 32k;
269 gzip_types text/plain text/html application/x-javascript text/javascript text/xml text/css;
270
271 #####################################
272 # Mounting MediaGoblin stuff
273 # This is the section you should read
274 #####################################
275
276 # Change this to update the upload size limit for your users
277 client_max_body_size 8m;
278
279 server_name mediagoblin.example.org www.mediagoblin.example.org;
280 access_log /var/log/nginx/mediagoblin.example.access.log;
281 error_log /var/log/nginx/mediagoblin.example.error.log;
282
283 # MediaGoblin's stock static files: CSS, JS, etc.
284 location /mgoblin_static/ {
285 alias /srv/mediagoblin.example.org/mediagoblin/mediagoblin/static/;
286 }
287
288 # Instance specific media:
289 location /mgoblin_media/ {
290 alias /srv/mediagoblin.example.org/mediagoblin/user_dev/media/public/;
291 }
292
293 # Theme static files (usually symlinked in)
294 location /theme_static/ {
295 alias /srv/mediagoblin.example.org/mediagoblin/user_dev/theme_static/;
296 }
297
298 # Mounting MediaGoblin itself via FastCGI.
299 location / {
300 fastcgi_pass 127.0.0.1:26543;
301 include /etc/nginx/fastcgi_params;
302
303 # our understanding vs nginx's handling of script_name vs
304 # path_info don't match :)
305 fastcgi_param PATH_INFO $fastcgi_script_name;
306 fastcgi_param SCRIPT_NAME "";
307 }
308 }
309
310 Now, nginx instance is configured to serve the MediaGoblin
311 application. Perform a quick test to ensure that this configuration
312 works. Restart nginx so it picks up your changes, with a command that
313 resembles one of the following (as the root user)::
314
315 sudo /etc/init.d/nginx restart
316 sudo /etc/rc.d/nginx restart
317
318 Now start MediaGoblin. Use the following command sequence as an
319 example::
320
321 cd /srv/mediagoblin.example.org/mediagoblin/
322 ./lazyserver.sh --server-name=fcgi fcgi_host=127.0.0.1 fcgi_port=26543
323
324 Visit the site you've set up in your browser by visiting
325 <http://mediagoblin.example.org>. You should see MediaGoblin!
326
327 .. note::
328
329 The configuration described above is sufficient for development and
330 smaller deployments. However, for larger production deployments
331 with larger processing requirements, see the
332 ":doc:`production-deployments`" documentation.