1 .. MediaGoblin Documentation
3 Written in 2011, 2012 by MediaGoblin contributors
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
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/>.
14 .. _deploying-chapter:
20 GNU MediaGoblin is fairly new and so at the time of writing, there
21 aren't easy package-manager-friendly methods to install MediaGoblin.
22 However, doing a basic install isn't too complex in and of itself.
24 There's an almost infinite way to deploy things... for now, we'll keep
25 it simple with some assumptions and use a setup that combines
26 mediagoblin + virtualenv + fastcgi + nginx on a .deb or .rpm based
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.
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>`_.
46 MediaGoblin has the following core dependencies:
49 - `python-lxml <http://lxml.de/>`_
50 - `git <http://git-scm.com/>`_
51 - `SQLite <http://www.sqlite.org/>`_/`PostgreSQL <http://www.postgresql.org/>`_
52 - `Python Imaging Library <http://www.pythonware.com/products/pil/>`_ (PIL)
53 - `virtualenv <http://www.virtualenv.org/>`_
55 On a DEB-based system (e.g Debian, gNewSense, Trisquel, Ubuntu, and
56 derivatives) issue the following command::
58 sudo apt-get install git-core python python-dev python-lxml \
59 python-imaging python-virtualenv
61 On a RPM-based system (e.g. Fedora, RedHat, and derivatives) issue the
64 yum install python-paste-deploy python-paste-script \
65 git-core python python-devel python-lxml python-imaging \
73 MediaGoblin currently supports PostgreSQL and SQLite. The default is a
74 local SQLite database. This will "just work" for small deployments.
76 For medium to large deployments we recommend PostgreSQL.
78 If you don't want/need postgres, skip this section.
80 These are the packages needed for Debian Wheezy (testing)::
82 sudo apt-get install postgresql postgresql-client python-psycopg2
84 The installation process will create a new *system* user named ``postgres``,
85 it will have privilegies sufficient to manage the database. We will create a
86 new database user with restricted privilegies and a new database owned by our
87 restricted database user for our MediaGoblin instance.
89 In this example, the database user will be ``mediagoblin`` and the database
90 name will be ``mediagoblin`` too.
92 To create our new user, run::
94 sudo -u postgres createuser mediagoblin
96 then answer NO to *all* the questions::
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
102 then create the database all our MediaGoblin data should be stored in::
104 sudo -u postgres createdb -E UNICODE -O mediagoblin mediagoblin
106 where the first ``mediagoblin`` is the database owner and the second
107 ``mediagoblin`` is the database name.
109 .. caution:: Where is the password?
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
116 More on this in :ref:`Drop Privileges for MediaGoblin <drop-privileges-for-mediagoblin>`.
119 .. _drop-privileges-for-mediagoblin:
121 Drop Privileges for MediaGoblin
122 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
124 As MediaGoblin does not require special permissions or elevated
125 access, you should run MediaGoblin under an existing non-root user or
126 preferably create a dedicated user for the purpose of running
127 MediaGoblin. Consult your distribution's documentation on how to
128 create "system account" or dedicated service user. Ensure that it is
129 not possible to log in to your system with as this user.
131 You should create a working directory for MediaGoblin. This document
132 assumes your local git repository will be located at
133 ``/srv/mediagoblin.example.org/mediagoblin/`` for this documentation.
134 Substitute your prefer ed local deployment path as needed.
136 This document assumes that all operations are performed as this
137 user. To drop privileges to this user, run the following command::
141 Where, "``[mediagoblin]``" is the username of the system user that will
144 Install MediaGoblin and Virtualenv
145 ----------------------------------
149 MediaGoblin is still developing rapidly. As a result
150 the following instructions recommend installing from the ``master``
151 branch of the git repository. Eventually production deployments will
152 want to transition to running from more consistent releases.
154 Issue the following commands, to create and change the working
155 directory. Modify these commands to reflect your own environment::
157 mkdir -p /srv/mediagoblin.example.org/
158 cd /srv/mediagoblin.example.org/
160 Clone the MediaGoblin repository and set up the git submodules::
162 git clone git://gitorious.org/mediagoblin/mediagoblin.git
164 git submodule init && git submodule update
166 Set up the in-package virtualenv via make:
168 ./bootstrap.sh && ./configure && make
172 Prefer not to use make, or want to use the "old way" of installing
173 MediaGoblin (maybe you know how to use virtualenv and python
174 packaging)? You still can! All that the above make script is doing
175 is installing an in-package virtualenv and running
177 ./bin/python setup.py develop
181 (NOTE: Is this still relevant?)
183 If you have problems here, consider trying to install virtualenv
184 with the ``--distribute`` or ``--no-site-packages`` options. If
185 your system's default Python is in the 3.x series you may need to
186 run ``virtualenv`` with the ``--python=python2.7`` or
187 ``--python=python2.6`` options.
189 The above provides an in-package install of ``virtualenv``. While this
190 is counter to the conventional ``virtualenv`` configuration, it is
191 more reliable and considerably easier to configure and illustrate. If
192 you're familiar with Python packaging you may consider deploying with
193 your preferred method.
195 Assuming you are going to deploy with FastCGI, you should also install
198 ./bin/easy_install flup
200 (Sometimes this breaks because flup's site is flakey. If it does for
203 ./bin/easy_install https://pypi.python.org/pypi/flup/1.0.3.dev-20110405
205 This concludes the initial configuration of the development
206 environment. In the future, when you update your
207 codebase, you should also run::
209 ./bin/python setup.py develop --upgrade && ./bin/gmg dbupdate && git submodule fetch
211 Note: If you are running an active site, depending on your server
212 configuration, you may need to stop it first or the dbupdate command
213 may hang (and it's certainly a good idea to restart it after the
217 Deploy MediaGoblin Services
218 ---------------------------
220 Edit site configuration
221 ~~~~~~~~~~~~~~~~~~~~~~~
223 A few basic properties must be set before MediaGoblin will work. First
224 make a copy of ``mediagoblin.ini`` for editing so the original config
227 cp mediagoblin.ini mediagoblin_local.ini
230 - Set ``email_sender_address`` to the address you wish to be used as
231 the sender for system-generated emails
232 - Edit ``direct_remote_path``, ``base_dir``, and ``base_url`` if
233 your mediagoblin directory is not the root directory of your
237 Configure MediaGoblin to use the PostgreSQL database
238 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
240 If you are using postgres, edit the ``[mediagoblin]`` section in your
241 ``mediagoblin_local.ini`` and put in::
243 sql_engine = postgresql:///mediagoblin
245 if you are running the MediaGoblin application as the same 'user' as the
249 Update database data structures
250 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
252 Before you start using the database, you need to run::
256 to populate the database with the MediaGoblin data structures.
262 At this point MediaGoblin should be properly installed. You can
263 test the deployment with the following command::
265 ./lazyserver.sh --server-name=broadcast
267 You should be able to connect to the machine on port 6543 in your
268 browser to confirm that the service is operable.
270 .. _webserver-config:
276 This configuration example will use nginx, however, you may
277 use any webserver of your choice as long as it supports the FastCGI
278 protocol. If you do not already have a web server, consider nginx, as
279 the configuration files may be more clear than the
282 Create a configuration file at
283 ``/srv/mediagoblin.example.org/nginx.conf`` and create a symbolic link
284 into a directory that will be included in your ``nginx`` configuration
285 (e.g. "``/etc/nginx/sites-enabled`` or ``/etc/nginx/conf.d``) with
286 one of the following commands (as the root user)::
288 ln -s /srv/mediagoblin.example.org/nginx.conf /etc/nginx/conf.d/
289 ln -s /srv/mediagoblin.example.org/nginx.conf /etc/nginx/sites-enabled/
291 Modify these commands and locations depending on your preferences and
292 the existing configuration of your nginx instance. The contents of
293 this ``nginx.conf`` file should be modeled on the following::
296 #################################################
297 # Stock useful config options, but ignore them :)
298 #################################################
299 include /etc/nginx/mime.types;
302 default_type application/octet-stream;
307 gzip_min_length 1024;
309 gzip_types text/plain text/html application/x-javascript text/javascript text/xml text/css;
311 #####################################
312 # Mounting MediaGoblin stuff
313 # This is the section you should read
314 #####################################
316 # Change this to update the upload size limit for your users
317 client_max_body_size 8m;
319 # prevent attacks (someone uploading a .txt file that the browser
320 # interprets as an HTML file, etc.)
321 add_header X-Content-Type-Options nosniff;
323 server_name mediagoblin.example.org www.mediagoblin.example.org;
324 access_log /var/log/nginx/mediagoblin.example.access.log;
325 error_log /var/log/nginx/mediagoblin.example.error.log;
327 # MediaGoblin's stock static files: CSS, JS, etc.
328 location /mgoblin_static/ {
329 alias /srv/mediagoblin.example.org/mediagoblin/mediagoblin/static/;
332 # Instance specific media:
333 location /mgoblin_media/ {
334 alias /srv/mediagoblin.example.org/mediagoblin/user_dev/media/public/;
337 # Theme static files (usually symlinked in)
338 location /theme_static/ {
339 alias /srv/mediagoblin.example.org/mediagoblin/user_dev/theme_static/;
342 # Plugin static files (usually symlinked in)
343 location /plugin_static/ {
344 alias /srv/mediagoblin.example.org/mediagoblin/user_dev/plugin_static/;
347 # Mounting MediaGoblin itself via FastCGI.
349 fastcgi_pass 127.0.0.1:26543;
350 include /etc/nginx/fastcgi_params;
352 # our understanding vs nginx's handling of script_name vs
353 # path_info don't match :)
354 fastcgi_param PATH_INFO $fastcgi_script_name;
355 fastcgi_param SCRIPT_NAME "";
359 Now, nginx instance is configured to serve the MediaGoblin
360 application. Perform a quick test to ensure that this configuration
361 works. Restart nginx so it picks up your changes, with a command that
362 resembles one of the following (as the root user)::
364 sudo /etc/init.d/nginx restart
365 sudo /etc/rc.d/nginx restart
367 Now start MediaGoblin. Use the following command sequence as an
370 cd /srv/mediagoblin.example.org/mediagoblin/
371 ./lazyserver.sh --server-name=fcgi fcgi_host=127.0.0.1 fcgi_port=26543
373 Visit the site you've set up in your browser by visiting
374 <http://mediagoblin.example.org>. You should see MediaGoblin!
378 The configuration described above is sufficient for development and
379 smaller deployments. However, for larger production deployments
380 with larger processing requirements, see the
381 ":doc:`production-deployments`" documentation.
387 Instructions and scripts for running MediaGoblin on an Apache server
388 can be found on the `MediaGoblin wiki <http://wiki.mediagoblin.org/Deployment>`_.
391 Security Considerations
392 ~~~~~~~~~~~~~~~~~~~~~~~
396 The directory ``user_dev/crypto/`` contains some very
398 Especially the ``itsdangeroussecret.bin`` is very important
399 for session security. Make sure not to leak its contents anywhere.
400 If the contents gets leaked nevertheless, delete your file
401 and restart the server, so that it creates a new secret key.
402 All previous sessions will be invalifated then.