Changing "su -" to just "su"... considerably simpler.
[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
4e893b6e 48- Python 2.6 or 2.7
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
JW
93
94 sudo -u postgres createuser mediagoblin
95
7798f911 96then answer NO to *all* the questions::
775ec9e8
JW
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
7798f911 102then create the database all our MediaGoblin data should be stored in::
775ec9e8
JW
103
104 sudo -u postgres createdb -E UNICODE -O mediagoblin mediagoblin
105
106where 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
775ec9e8
JW
119.. _drop-privileges-for-mediagoblin:
120
4e893b6e 121Drop Privileges for MediaGoblin
122~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
17c71230 123
fd5c35e5 124MediaGoblin does not require special permissions or elevated
1b4a9f26
CAW
125access to run. As such, the preferred way to run MediaGoblin is to
126create a dedicated, unprivileged system user for the sole purpose of running
fd5c35e5
JC
127MediaGoblin. Running MediaGoblin processes under an unpriviledged system user
128helps to keep it more secure.
129
130The following command (entered as root or with sudo) will create a
131system account with a username of ``mediagoblin``. You may choose a different
132username if you wish.::
133
9b604868 134 adduser --system mediagoblin
fd5c35e5
JC
135
136No password will be assigned to this account, and you will not be able
137to log in as this user. To switch to this account, enter either::
138
a040f72d 139 sudo su mediagoblin # (if you have sudo permissions)
fd5c35e5 140
9b604868 141or::
fd5c35e5 142
a040f72d 143 su mediagoblin # (if you have to use root permissions)
fd5c35e5
JC
144
145You may get a warning similar to this when entering these commands::
146
9b604868 147 warning: cannot change directory to /home/mediagoblin: No such file or directory
fd5c35e5
JC
148
149You can disregard this warning. To return to your regular user account after
150using the system account, just enter ``exit``.
151
152.. note::
153
154 Unless otherwise noted, the remainder of this document assumes that all
155 operations are performed using this unpriviledged account.
156
157.. _create-mediagoblin-directory:
158
159Create a MediaGoblin Directory
160~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
17c71230 161
4e893b6e 162You should create a working directory for MediaGoblin. This document
076bf0cf 163assumes your local git repository will be located at
fd5c35e5
JC
164``/srv/mediagoblin.example.org/mediagoblin/``.
165Substitute your prefered local deployment path as needed.
166
167Setting up the working directory requires that we first create the directory
168with elevated priviledges, and then assign ownership of the directory
169to the unpriviledged system account.
17c71230 170
fd5c35e5
JC
171To do this, enter either of the following commands, changing the defaults
172to suit your particular requirements::
17c71230 173
e27e04a3 174 sudo mkdir -p /srv/mediagoblin.example.org && sudo chown -hR mediagoblin:mediagoblin /srv/mediagoblin.example.org
fd5c35e5 175
9b604868 176or (as the root user)::
fd5c35e5 177
e27e04a3 178 mkdir -p /srv/mediagoblin.example.org && chown -hR mediagoblin:mediagoblin /srv/mediagoblin.example.org
17c71230 179
4e893b6e 180
e260065a 181Install MediaGoblin and Virtualenv
4e893b6e 182----------------------------------
e260065a 183
076bf0cf
WKG
184.. note::
185
7798f911 186 MediaGoblin is still developing rapidly. As a result
076bf0cf
WKG
187 the following instructions recommend installing from the ``master``
188 branch of the git repository. Eventually production deployments will
189 want to transition to running from more consistent releases.
e260065a 190
fd5c35e5
JC
191We will now clone the MediaGoblin source code repository and setup and
192configure the necessary services. Modify these commands to
193suit your own environment. As a reminder, you should enter these
194commands using your unpriviledged system account.
17c71230 195
fd5c35e5
JC
196Change to the MediaGoblin directory that you just created::
197
198 cd /srv/mediagoblin.example.org
17c71230 199
d3b1fd2e 200Clone the MediaGoblin repository and set up the git submodules::
e260065a 201
5a756fb8 202 git clone git://gitorious.org/mediagoblin/mediagoblin.git
b889f971 203 cd mediagoblin
64ad0bee 204 git submodule init && git submodule update
e260065a 205
e260065a 206
3b8251f3
CAW
207And set up the in-package virtualenv::
208
209 (virtualenv --system-site-packages . || virtualenv .) && ./bin/python setup.py develop
e260065a 210
4e893b6e 211.. note::
e260065a 212
3b8251f3
CAW
213 We presently have an experimental make-style deployment system. if
214 you'd like to try it, instead of the above command, you can run::
215
216 ./bootstrap.sh && ./configure && make
99d79749 217
3b8251f3
CAW
218 This also includes a number of nice features, such as keeping your
219 viratualenv up to date by simply running `make update`.
99d79749
CAW
220
221.. ::
222
223 (NOTE: Is this still relevant?)
224
4e893b6e 225 If you have problems here, consider trying to install virtualenv
226 with the ``--distribute`` or ``--no-site-packages`` options. If
c356dc16 227 your system's default Python is in the 3.x series you may need to
4e893b6e 228 run ``virtualenv`` with the ``--python=python2.7`` or
229 ``--python=python2.6`` options.
e260065a 230
4e893b6e 231The above provides an in-package install of ``virtualenv``. While this
232is counter to the conventional ``virtualenv`` configuration, it is
233more reliable and considerably easier to configure and illustrate. If
234you're familiar with Python packaging you may consider deploying with
c356dc16 235your preferred method.
e260065a 236
076bf0cf
WKG
237Assuming you are going to deploy with FastCGI, you should also install
238flup::
99192f24 239
076bf0cf 240 ./bin/easy_install flup
99192f24 241
71ef2007
CAW
242(Sometimes this breaks because flup's site is flakey. If it does for
243you, try)::
244
245 ./bin/easy_install https://pypi.python.org/pypi/flup/1.0.3.dev-20110405
246
4e893b6e 247This concludes the initial configuration of the development
8d9aa03f 248environment. In the future, when you update your
076bf0cf 249codebase, you should also run::
e260065a 250
d3b1fd2e 251 ./bin/python setup.py develop --upgrade && ./bin/gmg dbupdate && git submodule fetch
e260065a 252
9d5cd0b9
CAW
253Note: If you are running an active site, depending on your server
254configuration, you may need to stop it first or the dbupdate command
255may hang (and it's certainly a good idea to restart it after the
256update)
257
258
4e893b6e 259Deploy MediaGoblin Services
260---------------------------
e260065a 261
a7d2a892
ST
262Edit site configuration
263~~~~~~~~~~~~~~~~~~~~~~~
264
041d2fd7
CAW
265A few basic properties must be set before MediaGoblin will work. First
266make a copy of ``mediagoblin.ini`` for editing so the original config
267file isn't lost::
a7d2a892
ST
268
269 cp mediagoblin.ini mediagoblin_local.ini
a7d2a892 270
041d2fd7
CAW
271Then:
272 - Set ``email_sender_address`` to the address you wish to be used as
273 the sender for system-generated emails
274 - Edit ``direct_remote_path``, ``base_dir``, and ``base_url`` if
275 your mediagoblin directory is not the root directory of your
276 vhost.
a7d2a892
ST
277
278
775ec9e8
JW
279Configure MediaGoblin to use the PostgreSQL database
280~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
281
7798f911
WKG
282If you are using postgres, edit the ``[mediagoblin]`` section in your
283``mediagoblin_local.ini`` and put in::
775ec9e8
JW
284
285 sql_engine = postgresql:///mediagoblin
286
287if you are running the MediaGoblin application as the same 'user' as the
288database owner.
289
7798f911 290
775ec9e8
JW
291Update database data structures
292~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
293
7798f911 294Before you start using the database, you need to run::
775ec9e8
JW
295
296 ./bin/gmg dbupdate
297
298to populate the database with the MediaGoblin data structures.
299
300
4e893b6e 301Test the Server
302~~~~~~~~~~~~~~~
e260065a 303
4e893b6e 304At this point MediaGoblin should be properly installed. You can
076bf0cf 305test the deployment with the following command::
e260065a 306
076bf0cf 307 ./lazyserver.sh --server-name=broadcast
e260065a 308
4e893b6e 309You should be able to connect to the machine on port 6543 in your
310browser to confirm that the service is operable.
e260065a 311
cd1abb11
CAW
312.. _webserver-config:
313
56d507b6 314
a7d2a892
ST
315FastCGI and nginx
316~~~~~~~~~~~~~~~~~
317
318This configuration example will use nginx, however, you may
4e893b6e 319use any webserver of your choice as long as it supports the FastCGI
320protocol. If you do not already have a web server, consider nginx, as
321the configuration files may be more clear than the
322alternatives.
323
324Create a configuration file at
325``/srv/mediagoblin.example.org/nginx.conf`` and create a symbolic link
326into a directory that will be included in your ``nginx`` configuration
327(e.g. "``/etc/nginx/sites-enabled`` or ``/etc/nginx/conf.d``) with
076bf0cf 328one of the following commands (as the root user)::
4e893b6e 329
076bf0cf
WKG
330 ln -s /srv/mediagoblin.example.org/nginx.conf /etc/nginx/conf.d/
331 ln -s /srv/mediagoblin.example.org/nginx.conf /etc/nginx/sites-enabled/
4e893b6e 332
333Modify these commands and locations depending on your preferences and
334the existing configuration of your nginx instance. The contents of
076bf0cf
WKG
335this ``nginx.conf`` file should be modeled on the following::
336
337 server {
338 #################################################
339 # Stock useful config options, but ignore them :)
340 #################################################
341 include /etc/nginx/mime.types;
342
343 autoindex off;
344 default_type application/octet-stream;
345 sendfile on;
346
347 # Gzip
348 gzip on;
349 gzip_min_length 1024;
350 gzip_buffers 4 32k;
351 gzip_types text/plain text/html application/x-javascript text/javascript text/xml text/css;
352
353 #####################################
354 # Mounting MediaGoblin stuff
355 # This is the section you should read
356 #####################################
357
358 # Change this to update the upload size limit for your users
359 client_max_body_size 8m;
360
a49c741f
CAW
361 # prevent attacks (someone uploading a .txt file that the browser
362 # interprets as an HTML file, etc.)
363 add_header X-Content-Type-Options nosniff;
37b48053 364
076bf0cf
WKG
365 server_name mediagoblin.example.org www.mediagoblin.example.org;
366 access_log /var/log/nginx/mediagoblin.example.access.log;
367 error_log /var/log/nginx/mediagoblin.example.error.log;
368
369 # MediaGoblin's stock static files: CSS, JS, etc.
370 location /mgoblin_static/ {
371 alias /srv/mediagoblin.example.org/mediagoblin/mediagoblin/static/;
372 }
373
374 # Instance specific media:
375 location /mgoblin_media/ {
376 alias /srv/mediagoblin.example.org/mediagoblin/user_dev/media/public/;
377 }
378
8d051cc0
CAW
379 # Theme static files (usually symlinked in)
380 location /theme_static/ {
381 alias /srv/mediagoblin.example.org/mediagoblin/user_dev/theme_static/;
382 }
383
24ede044
CAW
384 # Plugin static files (usually symlinked in)
385 location /plugin_static/ {
386 alias /srv/mediagoblin.example.org/mediagoblin/user_dev/plugin_static/;
387 }
388
076bf0cf
WKG
389 # Mounting MediaGoblin itself via FastCGI.
390 location / {
391 fastcgi_pass 127.0.0.1:26543;
392 include /etc/nginx/fastcgi_params;
393
394 # our understanding vs nginx's handling of script_name vs
395 # path_info don't match :)
396 fastcgi_param PATH_INFO $fastcgi_script_name;
397 fastcgi_param SCRIPT_NAME "";
4e893b6e 398 }
076bf0cf 399 }
4e893b6e 400
401Now, nginx instance is configured to serve the MediaGoblin
402application. Perform a quick test to ensure that this configuration
403works. Restart nginx so it picks up your changes, with a command that
076bf0cf 404resembles one of the following (as the root user)::
4e893b6e 405
076bf0cf
WKG
406 sudo /etc/init.d/nginx restart
407 sudo /etc/rc.d/nginx restart
4e893b6e 408
409Now start MediaGoblin. Use the following command sequence as an
076bf0cf 410example::
4e893b6e 411
076bf0cf
WKG
412 cd /srv/mediagoblin.example.org/mediagoblin/
413 ./lazyserver.sh --server-name=fcgi fcgi_host=127.0.0.1 fcgi_port=26543
4e893b6e 414
415Visit the site you've set up in your browser by visiting
518c5eb3 416<http://mediagoblin.example.org>. You should see MediaGoblin!
4e893b6e 417
4e893b6e 418.. note::
419
a085dda5 420 The configuration described above is sufficient for development and
421 smaller deployments. However, for larger production deployments
422 with larger processing requirements, see the
423 ":doc:`production-deployments`" documentation.
a7d2a892
ST
424
425
426Apache
427~~~~~~
428
041d2fd7
CAW
429Instructions and scripts for running MediaGoblin on an Apache server
430can be found on the `MediaGoblin wiki <http://wiki.mediagoblin.org/Deployment>`_.
b835e153
E
431
432
433Security Considerations
434~~~~~~~~~~~~~~~~~~~~~~~
435
436.. warning::
437
438 The directory ``user_dev/crypto/`` contains some very
439 sensitive files.
440 Especially the ``itsdangeroussecret.bin`` is very important
441 for session security. Make sure not to leak its contents anywhere.
442 If the contents gets leaked nevertheless, delete your file
443 and restart the server, so that it creates a new secret key.
fd5c35e5
JC
444 All previous sessions will be invalidated.
445