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