Merge branch 'stable'
[mediagoblin.git] / docs / source / siteadmin / deploying.rst
CommitLineData
473a4431
CAW
1.. MediaGoblin Documentation
2
fd5c35e5 3 Written in 2011, 2012, 2013 by MediaGoblin contributors
473a4431
CAW
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
abe74178
WKG
14.. _deploying-chapter:
15
4e893b6e 16=====================
17Deploying MediaGoblin
18=====================
00fdc7bd 19
e260065a
CAW
20GNU MediaGoblin is fairly new and so at the time of writing, there
21aren't easy package-manager-friendly methods to install MediaGoblin.
22However, doing a basic install isn't too complex in and of itself.
56d507b6 23
e260065a
CAW
24There's an almost infinite way to deploy things... for now, we'll keep
25it simple with some assumptions and use a setup that combines
26mediagoblin + virtualenv + fastcgi + nginx on a .deb or .rpm based
27GNU/Linux distro.
28
076bf0cf
WKG
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.
e260065a 34
4d8a3cd8
CAW
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
4e893b6e 40Prepare System
41--------------
e260065a 42
4e893b6e 43Dependencies
44~~~~~~~~~~~~
e260065a 45
4e893b6e 46MediaGoblin has the following core dependencies:
e260065a 47
2acf47d8 48- Python 2.7
4e893b6e 49- `python-lxml <http://lxml.de/>`_
50- `git <http://git-scm.com/>`_
775ec9e8 51- `SQLite <http://www.sqlite.org/>`_/`PostgreSQL <http://www.postgresql.org/>`_
4e893b6e 52- `Python Imaging Library <http://www.pythonware.com/products/pil/>`_ (PIL)
53- `virtualenv <http://www.virtualenv.org/>`_
e260065a 54
4e893b6e 55On a DEB-based system (e.g Debian, gNewSense, Trisquel, Ubuntu, and
7798f911 56derivatives) issue the following command::
e260065a 57
775ec9e8 58 sudo apt-get install git-core python python-dev python-lxml \
076bf0cf 59 python-imaging python-virtualenv
e260065a 60
4e893b6e 61On a RPM-based system (e.g. Fedora, RedHat, and derivatives) issue the
7798f911 62following command::
4e893b6e 63
775ec9e8 64 yum install python-paste-deploy python-paste-script \
076bf0cf
WKG
65 git-core python python-devel python-lxml python-imaging \
66 python-virtualenv
e260065a 67
775ec9e8
JW
68Configure PostgreSQL
69~~~~~~~~~~~~~~~~~~~~
70
71.. note::
72
7798f911
WKG
73 MediaGoblin currently supports PostgreSQL and SQLite. The default is a
74 local SQLite database. This will "just work" for small deployments.
775ec9e8 75
7798f911
WKG
76 For medium to large deployments we recommend PostgreSQL.
77
78 If you don't want/need postgres, skip this section.
79
fd5c35e5 80These are the packages needed for Debian Wheezy (stable)::
775ec9e8 81
21a84362 82 sudo apt-get install postgresql postgresql-client python-psycopg2
775ec9e8
JW
83
84The installation process will create a new *system* user named ``postgres``,
85it will have privilegies sufficient to manage the database. We will create a
86new database user with restricted privilegies and a new database owned by our
87restricted database user for our MediaGoblin instance.
88
89In this example, the database user will be ``mediagoblin`` and the database
90name will be ``mediagoblin`` too.
91
7798f911 92To create our new user, run::
775ec9e8 93
5526150e 94 sudo -u postgres createuser -A -D mediagoblin
775ec9e8 95
7798f911 96then create the database all our MediaGoblin data should be stored in::
775ec9e8
JW
97
98 sudo -u postgres createdb -E UNICODE -O mediagoblin mediagoblin
99
100where the first ``mediagoblin`` is the database owner and the second
101``mediagoblin`` is the database name.
102
103.. caution:: Where is the password?
104
105 These steps enable you to authenticate to the database in a password-less
106 manner via local UNIX authentication provided you run the MediaGoblin
107 application as a user with the same name as the user you created in
108 PostgreSQL.
109
110 More on this in :ref:`Drop Privileges for MediaGoblin <drop-privileges-for-mediagoblin>`.
111
112
775ec9e8
JW
113.. _drop-privileges-for-mediagoblin:
114
4e893b6e 115Drop Privileges for MediaGoblin
116~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
17c71230 117
fd5c35e5 118MediaGoblin does not require special permissions or elevated
1b4a9f26
CAW
119access to run. As such, the preferred way to run MediaGoblin is to
120create a dedicated, unprivileged system user for the sole purpose of running
fd5c35e5
JC
121MediaGoblin. Running MediaGoblin processes under an unpriviledged system user
122helps to keep it more secure.
123
124The following command (entered as root or with sudo) will create a
125system account with a username of ``mediagoblin``. You may choose a different
126username if you wish.::
127
9b604868 128 adduser --system mediagoblin
fd5c35e5
JC
129
130No password will be assigned to this account, and you will not be able
131to log in as this user. To switch to this account, enter either::
132
f055b475 133 sudo -u mediagoblin /bin/bash # (if you have sudo permissions)
fd5c35e5 134
9b604868 135or::
fd5c35e5 136
f055b475 137 su mediagoblin -s /bin/bash # (if you have to use root permissions)
fd5c35e5
JC
138
139You may get a warning similar to this when entering these commands::
140
9b604868 141 warning: cannot change directory to /home/mediagoblin: No such file or directory
fd5c35e5
JC
142
143You can disregard this warning. To return to your regular user account after
144using the system account, just enter ``exit``.
145
146.. note::
147
148 Unless otherwise noted, the remainder of this document assumes that all
149 operations are performed using this unpriviledged account.
150
151.. _create-mediagoblin-directory:
152
153Create a MediaGoblin Directory
154~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
17c71230 155
4e893b6e 156You should create a working directory for MediaGoblin. This document
076bf0cf 157assumes your local git repository will be located at
fd5c35e5
JC
158``/srv/mediagoblin.example.org/mediagoblin/``.
159Substitute your prefered local deployment path as needed.
160
161Setting up the working directory requires that we first create the directory
162with elevated priviledges, and then assign ownership of the directory
163to the unpriviledged system account.
17c71230 164
fd5c35e5
JC
165To do this, enter either of the following commands, changing the defaults
166to suit your particular requirements::
17c71230 167
138d934f 168 sudo mkdir -p /srv/mediagoblin.example.org && sudo chown -hR mediagoblin: /srv/mediagoblin.example.org
fd5c35e5 169
9b604868 170or (as the root user)::
fd5c35e5 171
138d934f 172 mkdir -p /srv/mediagoblin.example.org && chown -hR mediagoblin: /srv/mediagoblin.example.org
17c71230 173
4e893b6e 174
e260065a 175Install MediaGoblin and Virtualenv
4e893b6e 176----------------------------------
e260065a 177
076bf0cf
WKG
178.. note::
179
7798f911 180 MediaGoblin is still developing rapidly. As a result
076bf0cf
WKG
181 the following instructions recommend installing from the ``master``
182 branch of the git repository. Eventually production deployments will
183 want to transition to running from more consistent releases.
e260065a 184
fd5c35e5
JC
185We will now clone the MediaGoblin source code repository and setup and
186configure the necessary services. Modify these commands to
187suit your own environment. As a reminder, you should enter these
188commands using your unpriviledged system account.
17c71230 189
fd5c35e5
JC
190Change to the MediaGoblin directory that you just created::
191
192 cd /srv/mediagoblin.example.org
17c71230 193
d3b1fd2e 194Clone the MediaGoblin repository and set up the git submodules::
e260065a 195
82be36d1 196 git clone https://gitorious.org/mediagoblin/mediagoblin.git -b stable
b889f971 197 cd mediagoblin
64ad0bee 198 git submodule init && git submodule update
e260065a 199
e260065a 200
41dbb27a 201Set up the hacking environment::
3b8251f3 202
41dbb27a 203 ./bootstrap.sh && ./configure && make
f0e137ab 204
4e893b6e 205The above provides an in-package install of ``virtualenv``. While this
206is counter to the conventional ``virtualenv`` configuration, it is
207more reliable and considerably easier to configure and illustrate. If
208you're familiar with Python packaging you may consider deploying with
c356dc16 209your preferred method.
e260065a 210
076bf0cf
WKG
211Assuming you are going to deploy with FastCGI, you should also install
212flup::
99192f24 213
076bf0cf 214 ./bin/easy_install flup
99192f24 215
71ef2007
CAW
216(Sometimes this breaks because flup's site is flakey. If it does for
217you, try)::
218
219 ./bin/easy_install https://pypi.python.org/pypi/flup/1.0.3.dev-20110405
220
4e893b6e 221This concludes the initial configuration of the development
8d9aa03f 222environment. In the future, when you update your
076bf0cf 223codebase, you should also run::
e260065a 224
e99431cc 225 git submodule update && ./bin/python setup.py develop --upgrade && ./bin/gmg dbupdate
e260065a 226
9d5cd0b9
CAW
227Note: If you are running an active site, depending on your server
228configuration, you may need to stop it first or the dbupdate command
229may hang (and it's certainly a good idea to restart it after the
230update)
231
232
4e893b6e 233Deploy MediaGoblin Services
234---------------------------
e260065a 235
a7d2a892
ST
236Edit site configuration
237~~~~~~~~~~~~~~~~~~~~~~~
238
041d2fd7
CAW
239A few basic properties must be set before MediaGoblin will work. First
240make a copy of ``mediagoblin.ini`` for editing so the original config
241file isn't lost::
a7d2a892
ST
242
243 cp mediagoblin.ini mediagoblin_local.ini
a7d2a892 244
041d2fd7
CAW
245Then:
246 - Set ``email_sender_address`` to the address you wish to be used as
247 the sender for system-generated emails
248 - Edit ``direct_remote_path``, ``base_dir``, and ``base_url`` if
249 your mediagoblin directory is not the root directory of your
250 vhost.
a7d2a892
ST
251
252
775ec9e8
JW
253Configure MediaGoblin to use the PostgreSQL database
254~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
255
7798f911
WKG
256If you are using postgres, edit the ``[mediagoblin]`` section in your
257``mediagoblin_local.ini`` and put in::
775ec9e8
JW
258
259 sql_engine = postgresql:///mediagoblin
260
261if you are running the MediaGoblin application as the same 'user' as the
262database owner.
263
7798f911 264
775ec9e8
JW
265Update database data structures
266~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
267
7798f911 268Before you start using the database, you need to run::
775ec9e8
JW
269
270 ./bin/gmg dbupdate
271
272to populate the database with the MediaGoblin data structures.
273
274
4e893b6e 275Test the Server
276~~~~~~~~~~~~~~~
e260065a 277
4e893b6e 278At this point MediaGoblin should be properly installed. You can
076bf0cf 279test the deployment with the following command::
e260065a 280
076bf0cf 281 ./lazyserver.sh --server-name=broadcast
e260065a 282
4e893b6e 283You should be able to connect to the machine on port 6543 in your
284browser to confirm that the service is operable.
e260065a 285
cd1abb11
CAW
286.. _webserver-config:
287
56d507b6 288
a7d2a892
ST
289FastCGI and nginx
290~~~~~~~~~~~~~~~~~
291
292This configuration example will use nginx, however, you may
4e893b6e 293use any webserver of your choice as long as it supports the FastCGI
294protocol. If you do not already have a web server, consider nginx, as
295the configuration files may be more clear than the
296alternatives.
297
298Create a configuration file at
299``/srv/mediagoblin.example.org/nginx.conf`` and create a symbolic link
300into a directory that will be included in your ``nginx`` configuration
301(e.g. "``/etc/nginx/sites-enabled`` or ``/etc/nginx/conf.d``) with
076bf0cf 302one of the following commands (as the root user)::
4e893b6e 303
076bf0cf
WKG
304 ln -s /srv/mediagoblin.example.org/nginx.conf /etc/nginx/conf.d/
305 ln -s /srv/mediagoblin.example.org/nginx.conf /etc/nginx/sites-enabled/
4e893b6e 306
307Modify these commands and locations depending on your preferences and
308the existing configuration of your nginx instance. The contents of
076bf0cf
WKG
309this ``nginx.conf`` file should be modeled on the following::
310
311 server {
312 #################################################
313 # Stock useful config options, but ignore them :)
314 #################################################
315 include /etc/nginx/mime.types;
316
317 autoindex off;
318 default_type application/octet-stream;
319 sendfile on;
320
321 # Gzip
322 gzip on;
323 gzip_min_length 1024;
324 gzip_buffers 4 32k;
325 gzip_types text/plain text/html application/x-javascript text/javascript text/xml text/css;
326
327 #####################################
328 # Mounting MediaGoblin stuff
329 # This is the section you should read
330 #####################################
331
332 # Change this to update the upload size limit for your users
333 client_max_body_size 8m;
334
a49c741f
CAW
335 # prevent attacks (someone uploading a .txt file that the browser
336 # interprets as an HTML file, etc.)
337 add_header X-Content-Type-Options nosniff;
37b48053 338
076bf0cf
WKG
339 server_name mediagoblin.example.org www.mediagoblin.example.org;
340 access_log /var/log/nginx/mediagoblin.example.access.log;
341 error_log /var/log/nginx/mediagoblin.example.error.log;
342
343 # MediaGoblin's stock static files: CSS, JS, etc.
344 location /mgoblin_static/ {
345 alias /srv/mediagoblin.example.org/mediagoblin/mediagoblin/static/;
346 }
347
348 # Instance specific media:
349 location /mgoblin_media/ {
350 alias /srv/mediagoblin.example.org/mediagoblin/user_dev/media/public/;
351 }
352
8d051cc0
CAW
353 # Theme static files (usually symlinked in)
354 location /theme_static/ {
355 alias /srv/mediagoblin.example.org/mediagoblin/user_dev/theme_static/;
356 }
357
24ede044
CAW
358 # Plugin static files (usually symlinked in)
359 location /plugin_static/ {
360 alias /srv/mediagoblin.example.org/mediagoblin/user_dev/plugin_static/;
361 }
362
076bf0cf
WKG
363 # Mounting MediaGoblin itself via FastCGI.
364 location / {
365 fastcgi_pass 127.0.0.1:26543;
366 include /etc/nginx/fastcgi_params;
367
368 # our understanding vs nginx's handling of script_name vs
369 # path_info don't match :)
370 fastcgi_param PATH_INFO $fastcgi_script_name;
371 fastcgi_param SCRIPT_NAME "";
4e893b6e 372 }
076bf0cf 373 }
4e893b6e 374
f44bd7dc
CAW
375The first four ``location`` directives instruct Nginx to serve the
376static and uploaded files directly rather than through the MediaGoblin
377process. This approach is faster and requires less memory.
378
379.. note::
380
381 The user who owns the Nginx process, normally ``www-data``,
382 requires execute permission on the directories ``static``,
383 ``public``, ``theme_static`` and ``plugin_static`` plus all their
384 parent directories. This user also requires read permission on all
385 the files within these directories. This is normally the default.
386
4e893b6e 387Now, nginx instance is configured to serve the MediaGoblin
388application. Perform a quick test to ensure that this configuration
389works. Restart nginx so it picks up your changes, with a command that
076bf0cf 390resembles one of the following (as the root user)::
4e893b6e 391
076bf0cf
WKG
392 sudo /etc/init.d/nginx restart
393 sudo /etc/rc.d/nginx restart
4e893b6e 394
395Now start MediaGoblin. Use the following command sequence as an
076bf0cf 396example::
4e893b6e 397
076bf0cf
WKG
398 cd /srv/mediagoblin.example.org/mediagoblin/
399 ./lazyserver.sh --server-name=fcgi fcgi_host=127.0.0.1 fcgi_port=26543
4e893b6e 400
401Visit the site you've set up in your browser by visiting
518c5eb3 402<http://mediagoblin.example.org>. You should see MediaGoblin!
4e893b6e 403
4e893b6e 404.. note::
405
a085dda5 406 The configuration described above is sufficient for development and
407 smaller deployments. However, for larger production deployments
408 with larger processing requirements, see the
409 ":doc:`production-deployments`" documentation.
a7d2a892
ST
410
411
412Apache
413~~~~~~
414
041d2fd7
CAW
415Instructions and scripts for running MediaGoblin on an Apache server
416can be found on the `MediaGoblin wiki <http://wiki.mediagoblin.org/Deployment>`_.
b835e153
E
417
418
419Security Considerations
420~~~~~~~~~~~~~~~~~~~~~~~
421
422.. warning::
423
424 The directory ``user_dev/crypto/`` contains some very
425 sensitive files.
426 Especially the ``itsdangeroussecret.bin`` is very important
427 for session security. Make sure not to leak its contents anywhere.
428 If the contents gets leaked nevertheless, delete your file
429 and restart the server, so that it creates a new secret key.
fd5c35e5
JC
430 All previous sessions will be invalidated.
431
f44bd7dc
CAW
432..
433 Local variables:
434 fill-column: 70
435 End: