docs: Removed systemcl enable/start. Already issued.
[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
a0392075
JC
101An rpm-based system also requires that you initialize and start the
102PostgresSQL database with a few commands. The following commands are
103not needed on a Debian-based platform, however::
c3075e91 104
44db13fa 105 sudo /usr/bin/postgresql-setup initdb
a0392075
JC
106 sudo systemctl enable postgresql
107 sudo systemctl start postgresql
775ec9e8
JW
108
109The installation process will create a new *system* user named ``postgres``,
c3075e91 110which will have privilegies sufficient to manage the database. We will create a
775ec9e8
JW
111new database user with restricted privilegies and a new database owned by our
112restricted database user for our MediaGoblin instance.
113
114In this example, the database user will be ``mediagoblin`` and the database
115name will be ``mediagoblin`` too.
116
c3075e91
JC
117We'll add these entities by first switching to the *postgres* account::
118
44db13fa 119 sudo su - postgres
775ec9e8 120
c3075e91
JC
121This will change your prompt to a shell prompt, such as *-bash-4.2$*. Enter
122the following *createuser* and *createdb* commands at that prompt. We'll
123create the *mediagoblin* database user first::
775ec9e8 124
44db13fa
JC
125 # this command and the one that follows are run as the ``postgres`` user:
126 createuser -A -D mediagoblin
775ec9e8 127
c3075e91
JC
128Then we'll create the database where all of our MediaGoblin data will be stored::
129
44db13fa 130 createdb -E UNICODE -O mediagoblin mediagoblin
775ec9e8
JW
131
132where the first ``mediagoblin`` is the database owner and the second
133``mediagoblin`` is the database name.
134
7bba6d2e 135Type ``exit`` to exit from the 'postgres' user account.::
c3075e91 136
7bba6d2e 137 exit
c3075e91 138
775ec9e8
JW
139.. caution:: Where is the password?
140
141 These steps enable you to authenticate to the database in a password-less
142 manner via local UNIX authentication provided you run the MediaGoblin
143 application as a user with the same name as the user you created in
144 PostgreSQL.
145
146 More on this in :ref:`Drop Privileges for MediaGoblin <drop-privileges-for-mediagoblin>`.
147
148
775ec9e8
JW
149.. _drop-privileges-for-mediagoblin:
150
4e893b6e 151Drop Privileges for MediaGoblin
152~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
17c71230 153
fd5c35e5 154MediaGoblin does not require special permissions or elevated
1b4a9f26
CAW
155access to run. As such, the preferred way to run MediaGoblin is to
156create a dedicated, unprivileged system user for the sole purpose of running
fd5c35e5
JC
157MediaGoblin. Running MediaGoblin processes under an unpriviledged system user
158helps to keep it more secure.
159
160The following command (entered as root or with sudo) will create a
161system account with a username of ``mediagoblin``. You may choose a different
162username if you wish.::
163
44db13fa 164 sudo useradd -c "GNU MediaGoblin system account" -d /home/mediagoblin -U -m -r mediagoblin
fd5c35e5
JC
165
166No password will be assigned to this account, and you will not be able
9a1ba0e8 167to log in as this user. To switch to this account, enter::
fd5c35e5 168
44db13fa 169 sudo su mediagoblin -s /bin/bash
fd5c35e5 170
ef2642f7
JC
171To return to your regular user account after using the system account, type
172``exit``.
fd5c35e5 173
fd5c35e5
JC
174.. _create-mediagoblin-directory:
175
176Create a MediaGoblin Directory
177~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
17c71230 178
4e893b6e 179You should create a working directory for MediaGoblin. This document
076bf0cf 180assumes your local git repository will be located at
fd5c35e5
JC
181``/srv/mediagoblin.example.org/mediagoblin/``.
182Substitute your prefered local deployment path as needed.
183
184Setting up the working directory requires that we first create the directory
185with elevated priviledges, and then assign ownership of the directory
186to the unpriviledged system account.
17c71230 187
fd5c35e5
JC
188To do this, enter either of the following commands, changing the defaults
189to suit your particular requirements::
17c71230 190
44db13fa 191 sudo mkdir -p /srv/mediagoblin.example.org && sudo chown -hR mediagoblin: /srv/mediagoblin.example.org
fd5c35e5 192
c3075e91 193.. note::
fd5c35e5 194
c3075e91
JC
195 Unless otherwise noted, the remainder of this document assumes that all
196 operations are performed using this unpriviledged account.
17c71230 197
4e893b6e 198
e260065a 199Install MediaGoblin and Virtualenv
4e893b6e 200----------------------------------
e260065a 201
44db13fa
JC
202We will now switch to our 'mediagoblin' system account, and then set up
203our MediaGoblin source code repository and its necessary services.
204You should modify these commands to suit your own environment.
17c71230 205
fd5c35e5
JC
206Change to the MediaGoblin directory that you just created::
207
44db13fa 208 sudo su mediagoblin -s /bin/bash # to change to the 'mediagoblin' account
9a1ba0e8 209 $ cd /srv/mediagoblin.example.org
17c71230 210
d3b1fd2e 211Clone the MediaGoblin repository and set up the git submodules::
e260065a 212
a35b7c7f 213 $ git clone git://git.savannah.gnu.org/mediagoblin.git -b stable
9a1ba0e8
JC
214 $ cd mediagoblin
215 $ git submodule init && git submodule update
e260065a 216
9fa1e602
CAW
217.. note::
218
219 The MediaGoblin repository used to be on gitorious.org, but since
220 gitorious.org shut down, we had to move. We are presently on
221 Savannah. You may need to update your git repository location::
222
44db13fa 223 $ git remote set-url origin git://git.savannah.gnu.org/mediagoblin.git
e260065a 224
41dbb27a 225Set up the hacking environment::
3b8251f3 226
9a1ba0e8 227 $ ./bootstrap.sh && ./configure && make
f0e137ab 228
4e893b6e 229The above provides an in-package install of ``virtualenv``. While this
230is counter to the conventional ``virtualenv`` configuration, it is
231more reliable and considerably easier to configure and illustrate. If
232you're familiar with Python packaging you may consider deploying with
c356dc16 233your preferred method.
e260065a 234
8d59cd1f
CAW
235.. note::
236
237 What if you don't want an in-package ``virtualenv``? Maybe you
238 have your own ``virtualenv``, or you are building a MediaGoblin
239 package for a distribution. There's no need necessarily for the
240 virtualenv produced by ``./configure && make`` by default other
241 than attempting to simplify work for developers and people
242 deploying by hiding all the virtualenv and bower complexity.
243
244 If you want to install all of MediaGoblin's libraries
245 independently, that's totally fine! You can pass the flag
246 ``--without-virtualenv`` which will skip this step.
247 But you will need to install all those libraries manually and make
248 sure they are on your ``PYTHONPATH`` yourself! (You can still use
249 ``python setup.py develop`` to install some of those libraries,
250 but note that no ``./bin/python`` will be set up for you via this
251 method, since no virtualenv is set up for you!)
252
076bf0cf
WKG
253Assuming you are going to deploy with FastCGI, you should also install
254flup::
99192f24 255
9a1ba0e8 256 $ ./bin/easy_install flup
71ef2007 257
4e893b6e 258This concludes the initial configuration of the development
8d9aa03f 259environment. In the future, when you update your
076bf0cf 260codebase, you should also run::
e260065a 261
9a1ba0e8
JC
262 $ git submodule update && ./bin/python setup.py develop --upgrade && ./bin/gmg dbupdate
263
264.. note::
e260065a 265
9a1ba0e8
JC
266 Note: If you are running an active site, depending on your server
267 configuration, you may need to stop it first or the dbupdate command
268 may hang (and it's certainly a good idea to restart it after the
269 update)
9d5cd0b9
CAW
270
271
4e893b6e 272Deploy MediaGoblin Services
273---------------------------
e260065a 274
a7d2a892
ST
275Edit site configuration
276~~~~~~~~~~~~~~~~~~~~~~~
277
041d2fd7 278A few basic properties must be set before MediaGoblin will work. First
ec255f63
JC
279make a copy of ``mediagoblin.ini`` and ``paste.ini`` for editing so the original
280config files aren't lost (you likely won't need to edit the paste configuration,
281but we'll make a local copy of it just in case)::
a7d2a892 282
ec255f63 283 $ cp -av mediagoblin.ini mediagoblin_local.ini && cp -av paste.ini paste_local.ini
a7d2a892 284
ec255f63 285Then edit mediagoblin_local.ini:
041d2fd7
CAW
286 - Set ``email_sender_address`` to the address you wish to be used as
287 the sender for system-generated emails
288 - Edit ``direct_remote_path``, ``base_dir``, and ``base_url`` if
289 your mediagoblin directory is not the root directory of your
290 vhost.
a7d2a892
ST
291
292
775ec9e8
JW
293Configure MediaGoblin to use the PostgreSQL database
294~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
295
7798f911
WKG
296If you are using postgres, edit the ``[mediagoblin]`` section in your
297``mediagoblin_local.ini`` and put in::
775ec9e8
JW
298
299 sql_engine = postgresql:///mediagoblin
300
301if you are running the MediaGoblin application as the same 'user' as the
302database owner.
303
7798f911 304
775ec9e8
JW
305Update database data structures
306~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
307
7798f911 308Before you start using the database, you need to run::
775ec9e8 309
44db13fa 310 $ ./bin/gmg dbupdate
775ec9e8
JW
311
312to populate the database with the MediaGoblin data structures.
313
314
4e893b6e 315Test the Server
316~~~~~~~~~~~~~~~
e260065a 317
4e893b6e 318At this point MediaGoblin should be properly installed. You can
076bf0cf 319test the deployment with the following command::
e260065a 320
44db13fa 321 $ ./lazyserver.sh --server-name=broadcast
e260065a 322
4e893b6e 323You should be able to connect to the machine on port 6543 in your
324browser to confirm that the service is operable.
e260065a 325
3948e44c
JC
326The next series of commands will need to be run as a priviledged user. Type
327exit to return to the root/sudo account.::
328
329 exit
330
cd1abb11
CAW
331.. _webserver-config:
332
56d507b6 333
a7d2a892
ST
334FastCGI and nginx
335~~~~~~~~~~~~~~~~~
336
337This configuration example will use nginx, however, you may
4e893b6e 338use any webserver of your choice as long as it supports the FastCGI
339protocol. If you do not already have a web server, consider nginx, as
340the configuration files may be more clear than the
341alternatives.
342
343Create a configuration file at
344``/srv/mediagoblin.example.org/nginx.conf`` and create a symbolic link
345into a directory that will be included in your ``nginx`` configuration
346(e.g. "``/etc/nginx/sites-enabled`` or ``/etc/nginx/conf.d``) with
cd7af789 347one of the following commands.
4e893b6e 348
cd7af789
JC
349On a DEB-based system (e.g Debian, gNewSense, Trisquel, Ubuntu, and
350derivatives) issue the following commands::
351
352 sudo apt-get install nginx
44db13fa 353 sudo ln -s /srv/mediagoblin.example.org/nginx.conf /etc/nginx/sites-enabled/
cd7af789
JC
354 sudo systemctl enable nginx
355
356On a RPM-based system (e.g. Fedora, RedHat, and derivatives) issue the
357following commands::
4e893b6e 358
cd7af789
JC
359 sudo yum install nginx
360 sudo ln -s /srv/mediagoblin.example.org/nginx.conf /etc/nginx/conf.d/
361 sudo systemctl enable nginx
362
363You can modify these commands and locations depending on your preferences and
4e893b6e 364the existing configuration of your nginx instance. The contents of
076bf0cf
WKG
365this ``nginx.conf`` file should be modeled on the following::
366
367 server {
368 #################################################
369 # Stock useful config options, but ignore them :)
370 #################################################
371 include /etc/nginx/mime.types;
372
373 autoindex off;
374 default_type application/octet-stream;
375 sendfile on;
376
377 # Gzip
378 gzip on;
379 gzip_min_length 1024;
380 gzip_buffers 4 32k;
cd7af789 381 gzip_types text/plain application/x-javascript text/javascript text/xml text/css;
076bf0cf
WKG
382
383 #####################################
384 # Mounting MediaGoblin stuff
385 # This is the section you should read
386 #####################################
387
388 # Change this to update the upload size limit for your users
389 client_max_body_size 8m;
390
a49c741f
CAW
391 # prevent attacks (someone uploading a .txt file that the browser
392 # interprets as an HTML file, etc.)
393 add_header X-Content-Type-Options nosniff;
37b48053 394
076bf0cf
WKG
395 server_name mediagoblin.example.org www.mediagoblin.example.org;
396 access_log /var/log/nginx/mediagoblin.example.access.log;
397 error_log /var/log/nginx/mediagoblin.example.error.log;
398
399 # MediaGoblin's stock static files: CSS, JS, etc.
400 location /mgoblin_static/ {
401 alias /srv/mediagoblin.example.org/mediagoblin/mediagoblin/static/;
402 }
403
404 # Instance specific media:
405 location /mgoblin_media/ {
406 alias /srv/mediagoblin.example.org/mediagoblin/user_dev/media/public/;
407 }
408
8d051cc0
CAW
409 # Theme static files (usually symlinked in)
410 location /theme_static/ {
411 alias /srv/mediagoblin.example.org/mediagoblin/user_dev/theme_static/;
412 }
413
24ede044
CAW
414 # Plugin static files (usually symlinked in)
415 location /plugin_static/ {
416 alias /srv/mediagoblin.example.org/mediagoblin/user_dev/plugin_static/;
417 }
418
076bf0cf
WKG
419 # Mounting MediaGoblin itself via FastCGI.
420 location / {
421 fastcgi_pass 127.0.0.1:26543;
422 include /etc/nginx/fastcgi_params;
423
424 # our understanding vs nginx's handling of script_name vs
425 # path_info don't match :)
426 fastcgi_param PATH_INFO $fastcgi_script_name;
427 fastcgi_param SCRIPT_NAME "";
4e893b6e 428 }
076bf0cf 429 }
4e893b6e 430
f44bd7dc
CAW
431The first four ``location`` directives instruct Nginx to serve the
432static and uploaded files directly rather than through the MediaGoblin
433process. This approach is faster and requires less memory.
434
435.. note::
436
cd7af789 437 The user who owns the Nginx process, normally ``www-data`` or ``nginx``,
f44bd7dc
CAW
438 requires execute permission on the directories ``static``,
439 ``public``, ``theme_static`` and ``plugin_static`` plus all their
440 parent directories. This user also requires read permission on all
441 the files within these directories. This is normally the default.
442
cd7af789
JC
443Nginx is now configured to serve the MediaGoblin application. Perform a quick
444test to ensure that this configuration works::
445
446 nginx -t
447
448If you encounter any errors, review your nginx configuration files, and try to
449resolve them. If you do not encounter any errors, you can start your nginx
450server with one of the following commands (depending on your environment)::
4e893b6e 451
076bf0cf
WKG
452 sudo /etc/init.d/nginx restart
453 sudo /etc/rc.d/nginx restart
44db13fa 454 sudo systemctl restart nginx
4e893b6e 455
456Now start MediaGoblin. Use the following command sequence as an
076bf0cf 457example::
4e893b6e 458
076bf0cf 459 cd /srv/mediagoblin.example.org/mediagoblin/
cd7af789 460 su mediagoblin -s /bin/bash
076bf0cf 461 ./lazyserver.sh --server-name=fcgi fcgi_host=127.0.0.1 fcgi_port=26543
4e893b6e 462
463Visit the site you've set up in your browser by visiting
518c5eb3 464<http://mediagoblin.example.org>. You should see MediaGoblin!
4e893b6e 465
4e893b6e 466.. note::
467
a085dda5 468 The configuration described above is sufficient for development and
469 smaller deployments. However, for larger production deployments
470 with larger processing requirements, see the
471 ":doc:`production-deployments`" documentation.
a7d2a892
ST
472
473
474Apache
475~~~~~~
476
041d2fd7
CAW
477Instructions and scripts for running MediaGoblin on an Apache server
478can be found on the `MediaGoblin wiki <http://wiki.mediagoblin.org/Deployment>`_.
b835e153
E
479
480
481Security Considerations
482~~~~~~~~~~~~~~~~~~~~~~~
483
484.. warning::
485
486 The directory ``user_dev/crypto/`` contains some very
487 sensitive files.
488 Especially the ``itsdangeroussecret.bin`` is very important
489 for session security. Make sure not to leak its contents anywhere.
490 If the contents gets leaked nevertheless, delete your file
491 and restart the server, so that it creates a new secret key.
fd5c35e5
JC
492 All previous sessions will be invalidated.
493
f44bd7dc
CAW
494..
495 Local variables:
496 fill-column: 70
497 End: