installation.rst 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338
  1. Installation
  2. ============
  3. - `Basic Setup <#basic-setup>`_
  4. - `Configuration <#configuration>`_
  5. - `Deplyoing <#deploying>`_
  6. Basic Setup
  7. ===========
  8. Virtualenv Setup
  9. ~~~~~~~~~~~~~~~~
  10. Before you can start, you need to create a `virtualenv`.
  11. You can install the virtualenvwrapper with your package manager or via pip.
  12. Be sure that pip is installed. If you don't know how to install pip, have a
  13. look at their `documentation <http://www.pip-installer.org/en/latest/installing.html>`_.
  14. For example, on archlinux you can install it with
  15. ::
  16. $ sudo pacman -S python2-virtualenvwrapper
  17. or, if you own a Mac, you can simply install it with
  18. ::
  19. $ sudo pip install virtualenvwrapper
  20. For more information checkout the `virtualenvwrapper <http://virtualenvwrapper.readthedocs.org/en/latest/install.html#basic-installation>`_ installation.
  21. After that you can create your virtualenv with
  22. ::
  23. $ mkvirtualenv -a /path/to/flaskbb -p $(which python2) flaskbb
  24. and you should be switched automatically to your newly created virtualenv.
  25. To deactivate it you just have to type ``deactivate`` and if you want to work
  26. on it again, you need to type ``workon flaskbb``.
  27. Required Dependencies
  28. ~~~~~~~~~~~~~~~~~~~~~
  29. Now you can install the required dependencies.
  30. ::
  31. $ pip install -r requirements.txt
  32. Optional Dependencies
  33. ~~~~~~~~~~~~~~~~~~~~~~
  34. We have one optional dependency, redis (the python package is installed automatically).
  35. If you want to use it, be sure that a redis-server is running. If you decide
  36. to use redis, the `online guests` and `online users` are being tracked by redis,
  37. else it will only track the `online users` via a simple SQL query.
  38. On Archlinux
  39. ------------
  40. ::
  41. # Install redis
  42. $ sudo pacman -S redis
  43. # Check if redis is already running.
  44. $ systemctl status redis
  45. # If not, start it.
  46. $ sudo systemctl start redis
  47. # Optional: Start redis everytime you boot your machine
  48. $ sudo systemctl enable redis
  49. On Debian 7.0 (Wheezy)
  50. ----------------------
  51. ::
  52. # Install redis
  53. $ sudo apt-get install redis-server
  54. # Check if redis is already running.
  55. $ service redis-server status
  56. # If not, start it
  57. $ sudo service redis-server start
  58. # Optional: Start redis everytime you boot your machine
  59. # I can't remember if this is done automatically..
  60. $ sudo update-rc.d redis-server defaults
  61. Configuration
  62. =============
  63. Before you can start, you need to configure `FlaskBB`.
  64. Development
  65. ~~~~~~~~~~~
  66. For development, you need to copy ``flaskbb/configs/development.py.example`` to
  67. ``flaskbb/configs/development.py``.
  68. ::
  69. cp flaskbb/configs/development.py.example flaskbb/configs/development.py
  70. The reCAPTCHA keys should work fine on localhost.
  71. Production
  72. ~~~~~~~~~~
  73. If you plan, to use `FlaskBB` in a production environment (not recommended at
  74. the moment, because it's still in development), you need to copy
  75. ``flaskbb/configs/production.py.example`` to ``flaskbb/configs/production.py``.
  76. ::
  77. cp flaskbb/configs/production.py.example flaskbb/configs/production.py
  78. Now open ``flaskbb/configs/production.py`` with your favourite editor and adjust
  79. the config variables to your needs.
  80. Mail Examples
  81. ~~~~~~~~~~~~~
  82. Both methods are included in the example configs.
  83. Google Mail
  84. -----------
  85. ::
  86. MAIL_SERVER = "smtp.gmail.com"
  87. MAIL_PORT = 465
  88. MAIL_USE_SSL = True
  89. MAIL_USERNAME = "your_username@gmail.com"
  90. MAIL_PASSWORD = "your_password"
  91. MAIL_DEFAULT_SENDER = ("Your Name", "your_username@gmail.com")
  92. Local SMTP Server
  93. -----------------
  94. ::
  95. MAIL_SERVER = "localhost"
  96. MAIL_PORT = 25
  97. MAIL_USE_SSL = False
  98. MAIL_USERNAME = ""
  99. MAIL_PASSWORD = ""
  100. MAIL_DEFAULT_SENDER = "noreply@example.org"
  101. Installation
  102. ============
  103. Development
  104. ~~~~~~~~~~~
  105. For development you can create the database with the command below. This will
  106. additional to the database also create a few users with some example content.
  107. ::
  108. python manage.py createall
  109. To test if everything has worked, run the development server with
  110. ``python manage.py runserver``.
  111. Production
  112. ~~~~~~~~~~
  113. Now, you should be able to install `FlaskBB` and can run therefore
  114. ::
  115. python manage.py initflaskbb
  116. There you are going to be asked about your username, your email adress
  117. and which password you want to use for your admin user
  118. (please choose a secure one).
  119. Upgrading
  120. =========
  121. `A upgrade guide will be written when first stable version is released.`
  122. Deploying
  123. =========
  124. I prefer to use supervisor, uWSGI and nginx to deploy my apps, but if you have
  125. figured out how to deploy it in another way, please let me know, so I
  126. (or you if you create a pull request) can add it to the documentation.
  127. **NOTE:** I have only used Debian to deploy it, if someone is using a other
  128. distribution, could you let me know if that works too? `Also, if you have better
  129. configurations for uWSGI, supervisor or nginx let me know that too.`
  130. Supervisor
  131. ~~~~~~~~~~
  132. `Supervisor is a client/server system that allows its users to monitor and
  133. control a number of processes on UNIX-like operating systems.`
  134. To install `supervisor` on Debian, you need to fire up this command:
  135. ::
  136. $ sudo apt-get install supervisor
  137. There are two ways to configure supervisor. The first one is, you just put
  138. the configuration to the end in the ``/etc/supervisor/supervisord.conf`` file.
  139. The second way would be to create a new file in the ``/etc/supervisor/conf.d/``
  140. directory. For example, such a file could be named ``uwsgi.conf``.
  141. After you have choosen the you way you like, simply put the snippet below in the
  142. configuration file.
  143. ::
  144. [program:uwsgi]
  145. command=/usr/bin/uwsgi --emperor /etc/uwsgi/apps-enabled
  146. user=apps
  147. stopsignal=QUIT
  148. autostart=true
  149. autorestart=true
  150. redirect_stderr=true
  151. uWSGI
  152. ~~~~~
  153. `uWSGI is a web application solution with batteries included.`
  154. To get started with uWSGI, you need to install it first.
  155. You'll also need the python plugin to serve python apps.
  156. This can be done with:
  157. ::
  158. $ sudo apt-get install uwsgi uwsgi-plugins-python
  159. For the configuration, you need to create a file in the
  160. ``/etc/uwsgi/apps-available`` directory. In this example, I will call the
  161. file ``flaskbb.ini``. After that, you can start with configuring it.
  162. My config looks like this for `flaskbb.org` (see below). As you might have noticed, I'm
  163. using a own user for my apps whose home directory is located at `/var/apps/`.
  164. In this directory there are living all my Flask apps.
  165. ::
  166. [uwsgi]
  167. base = /var/apps/flaskbb
  168. home = /var/apps/.virtualenvs/flaskbb/
  169. pythonpath = %(base)
  170. socket = 127.0.0.1:30002
  171. module = wsgi
  172. callable = flaskbb
  173. uid = apps
  174. gid = apps
  175. logto = /var/apps/flaskbb/logs/uwsgi.log
  176. plugins = python
  177. =============== ========================== ===============
  178. **base** /path/to/flaskbb The folder where your flaskbb application lives
  179. **home** /path/to/virtualenv/folder The virtualenv folder for your flaskbb application
  180. **pythonpath** /path/to/flaskbb The same as base
  181. **socket** socket This can be either a ip or the path to a socket (don't forget to change that in your nginx config)
  182. **module** wsgi.py This is the file located in the root directory from flaskbb (where manage.py lives).
  183. **callable** flaskbb The callable is application you have created in the ``wsgi.py`` file
  184. **uid** your_user The user who should be used. **NEVER** use root!
  185. **gid** your_group The group who should be used.
  186. **logto** /path/to/log/file The path to your uwsgi logfile
  187. **plugins** python We need the python plugin
  188. =============== ========================== ===============
  189. Don't forget to create a symlink to ``/etc/uwsgi/apps-enabled``.
  190. ::
  191. ln -s /etc/uwsgi/apps-available/flaskbb /etc/uwsgi/apps-enabled/flaskbb
  192. nginx
  193. ~~~~~
  194. `nginx [engine x] is an HTTP and reverse proxy server,
  195. as well as a mail proxy server, written by Igor Sysoev.`
  196. The nginx config is pretty straightforward. Again, this is how I use it for
  197. `FlaskBB`. Just copy the snippet below and paste it to, for example
  198. ``/etc/nginx/sites-available/flaskbb``.
  199. The only thing left is, that you need to adjust the ``server_name`` to your
  200. domain and the paths in ``access_log``, ``error_log``. Also, don't forget to
  201. adjust the paths in the ``alias`` es, as well as the socket adress in ``uwsgi_pass``.
  202. ::
  203. server {
  204. listen 80;
  205. server_name forums.flaskbb.org;
  206. access_log /var/log/nginx/access.forums.flaskbb.log;
  207. error_log /var/log/nginx/error.forums.flaskbb.log;
  208. location / {
  209. try_files $uri @flaskbb;
  210. }
  211. # Static files
  212. location /static {
  213. alias /var/apps/flaskbb/flaskbb/static/;
  214. }
  215. location ~ ^/_themes/([^/]+)/(.*)$ {
  216. alias /var/apps/flaskbb/flaskbb/themes/$1/static/$2;
  217. }
  218. # robots.txt
  219. location /robots.txt {
  220. alias /var/apps/flaskbb/flaskbb/static/robots.txt;
  221. }
  222. location @flaskbb {
  223. uwsgi_pass 127.0.0.1:30002;
  224. include uwsgi_params;
  225. }
  226. }
  227. Like in the `uWSGI <#uwsgi>`_ chapter, don't forget to create a symlink to
  228. ``/etc/nginx/sites-enabled/``.