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