installation.rst 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373
  1. Installation
  2. ============
  3. - `Basic Setup <#basic-setup>`_
  4. - `Configuration <#configuration>`_
  5. - `Deploying <#deploying>`_
  6. - `Deploying to PythonAnywhere <#deploying-to-pythonanywhere>`_
  7. Basic Setup
  8. -----------
  9. Virtualenv Setup
  10. ~~~~~~~~~~~~~~~~
  11. Before you can start, you need to create a `virtualenv`.
  12. You can install the virtualenvwrapper with your package manager or via pip.
  13. Be sure that pip is installed. If you don't know how to install pip, have a
  14. look at their `documentation <http://www.pip-installer.org/en/latest/installing.html>`_.
  15. For example, on archlinux you can install it with
  16. ::
  17. $ sudo pacman -S python2-virtualenvwrapper
  18. or, if you own a Mac, you can install it with
  19. ::
  20. $ sudo pip install virtualenvwrapper
  21. For more information checkout the `virtualenvwrapper <http://virtualenvwrapper.readthedocs.org/en/latest/install.html#basic-installation>`_ installation.
  22. After that, you can create your virtualenv with
  23. ::
  24. $ mkvirtualenv -a /path/to/flaskbb -p $(which python2) flaskbb
  25. and you should be switched automatically to your newly created virtualenv.
  26. To deactivate it you just have to type ``deactivate`` and if you want to work
  27. on it again, you need to type ``workon flaskbb``.
  28. Required Dependencies
  29. ~~~~~~~~~~~~~~~~~~~~~
  30. Now you can install the required dependencies.
  31. ::
  32. $ pip install -r requirements.txt
  33. Alternatively, you can use the `make` command to install the dependencies.
  34. ::
  35. $ make dependencies
  36. Optional Dependencies
  37. ~~~~~~~~~~~~~~~~~~~~~~
  38. We have one optional dependency, redis (the python package is installed automatically).
  39. If you want to use it, be sure that a redis-server is running. If you decide
  40. to use redis, the `online guests` and `online users` are being tracked by redis,
  41. else it will only track the `online users` via a simple SQL query.
  42. **On Archlinux**
  43. ::
  44. # Install redis
  45. $ sudo pacman -S redis
  46. # Check if redis is already running.
  47. $ systemctl status redis
  48. # If not, start it.
  49. $ sudo systemctl start redis
  50. # Optional: Start redis everytime you boot your machine
  51. $ sudo systemctl enable redis
  52. **On Debian 7.0 (Wheezy)**
  53. ::
  54. # Install redis
  55. $ sudo apt-get install redis-server
  56. # Check if redis is already running.
  57. $ service redis-server status
  58. # If not, start it
  59. $ sudo service redis-server start
  60. # Optional: Start redis everytime you boot your machine
  61. # I can't remember if this is done automatically..
  62. $ sudo update-rc.d redis-server defaults
  63. Configuration
  64. -------------
  65. Before you can start, you need to configure `FlaskBB`.
  66. Development
  67. ~~~~~~~~~~~
  68. For development, you need to copy ``flaskbb/configs/development.py.example`` to
  69. ``flaskbb/configs/development.py``.
  70. ::
  71. cp flaskbb/configs/development.py.example flaskbb/configs/development.py
  72. The reCAPTCHA keys should work fine on localhost.
  73. Production
  74. ~~~~~~~~~~
  75. If you plan, to use `FlaskBB` in a production environment (not recommended at
  76. the moment, because it's still in development), you need to copy
  77. ``flaskbb/configs/production.py.example`` to ``flaskbb/configs/production.py``.
  78. ::
  79. cp flaskbb/configs/production.py.example flaskbb/configs/production.py
  80. Now open ``flaskbb/configs/production.py`` with your favourite editor and adjust
  81. the config variables to your needs.
  82. Mail Examples
  83. ~~~~~~~~~~~~~
  84. Both methods are included in the example configs.
  85. **Google Mail**
  86. ::
  87. MAIL_SERVER = "smtp.gmail.com"
  88. MAIL_PORT = 465
  89. MAIL_USE_SSL = True
  90. MAIL_USERNAME = "your_username@gmail.com"
  91. MAIL_PASSWORD = "your_password"
  92. MAIL_DEFAULT_SENDER = ("Your Name", "your_username@gmail.com")
  93. **Local SMTP Server**
  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. For a guided install, run
  104. ::
  105. $ make install
  106. or
  107. ::
  108. flaskbb install
  109. During the installation process you are asked about your username,
  110. your email address and the password for your administrator user. Using the
  111. `make install` command is recommended as it checks that the dependencies are also
  112. installed.
  113. Upgrading
  114. ---------
  115. If the database models changed after a release, you have to run the ``upgrade``
  116. command
  117. ::
  118. flaskbb db upgrade
  119. Deploying
  120. ---------
  121. I prefer to use supervisor, uWSGI and nginx to deploy my apps, but if you have
  122. figured out how to deploy it in another way, please let me know, so I
  123. (or you if you create a pull request) can add it to the documentation.
  124. **NOTE:** I have only used Debian to deploy it, if someone is using a other
  125. distribution, could you let me know if that works too? `Also, if you have better
  126. configurations for uWSGI, supervisor or nginx let me know that too.`
  127. Supervisor
  128. ~~~~~~~~~~
  129. `Supervisor is a client/server system that allows its users to monitor and
  130. control a number of processes on UNIX-like operating systems.`
  131. To install `supervisor` on Debian, you need to fire up this command:
  132. ::
  133. $ sudo apt-get install supervisor
  134. There are two ways to configure supervisor. The first one is, you just put
  135. the configuration to the end in the ``/etc/supervisor/supervisord.conf`` file.
  136. The second way would be to create a new file in the ``/etc/supervisor/conf.d/``
  137. directory. For example, such a file could be named ``uwsgi.conf``.
  138. After you have choosen the you way you like, simply put the snippet below in the
  139. configuration file.
  140. ::
  141. [program:uwsgi]
  142. command=/usr/bin/uwsgi --emperor /etc/uwsgi/apps-enabled
  143. user=apps
  144. stopsignal=QUIT
  145. autostart=true
  146. autorestart=true
  147. redirect_stderr=true
  148. uWSGI
  149. ~~~~~
  150. `uWSGI is a web application solution with batteries included.`
  151. To get started with uWSGI, you need to install it first.
  152. You'll also need the python plugin to serve python apps.
  153. This can be done with:
  154. ::
  155. $ sudo apt-get install uwsgi uwsgi-plugin-python
  156. For the configuration, you need to create a file in the
  157. ``/etc/uwsgi/apps-available`` directory. In this example, I will call the
  158. file ``flaskbb.ini``. After that, you can start with configuring it.
  159. My config looks like this for `flaskbb.org` (see below). As you might have noticed, I'm
  160. using a own user for my apps whose home directory is located at `/var/apps/`.
  161. In this directory there are living all my Flask apps.
  162. ::
  163. [uwsgi]
  164. base = /var/apps/flaskbb
  165. home = /var/apps/.virtualenvs/flaskbb/
  166. pythonpath = %(base)
  167. socket = 127.0.0.1:30002
  168. module = wsgi
  169. callable = flaskbb
  170. uid = apps
  171. gid = apps
  172. logto = /var/apps/flaskbb/logs/uwsgi.log
  173. plugins = python
  174. =============== ========================== ===============
  175. **base** /path/to/flaskbb The folder where your flaskbb application lives
  176. **home** /path/to/virtualenv/folder The virtualenv folder for your flaskbb application
  177. **pythonpath** /path/to/flaskbb The same as base
  178. **socket** socket This can be either a ip or the path to a socket (don't forget to change that in your nginx config)
  179. **module** wsgi.py This is the file located in the root directory from flaskbb (where manage.py lives).
  180. **callable** flaskbb The callable is application you have created in the ``wsgi.py`` file
  181. **uid** your_user The user who should be used. **NEVER** use root!
  182. **gid** your_group The group who should be used.
  183. **logto** /path/to/log/file The path to your uwsgi logfile
  184. **plugins** python We need the python plugin
  185. =============== ========================== ===============
  186. Don't forget to create a symlink to ``/etc/uwsgi/apps-enabled``.
  187. ::
  188. ln -s /etc/uwsgi/apps-available/flaskbb /etc/uwsgi/apps-enabled/flaskbb
  189. nginx
  190. ~~~~~
  191. `nginx [engine x] is an HTTP and reverse proxy server,
  192. as well as a mail proxy server, written by Igor Sysoev.`
  193. The nginx config is pretty straightforward. Again, this is how I use it for
  194. `FlaskBB`. Just copy the snippet below and paste it to, for example
  195. ``/etc/nginx/sites-available/flaskbb``.
  196. The only thing left is, that you need to adjust the ``server_name`` to your
  197. domain and the paths in ``access_log``, ``error_log``. Also, don't forget to
  198. adjust the paths in the ``alias`` es, as well as the socket adress in ``uwsgi_pass``.
  199. ::
  200. server {
  201. listen 80;
  202. server_name forums.flaskbb.org;
  203. access_log /var/log/nginx/access.forums.flaskbb.log;
  204. error_log /var/log/nginx/error.forums.flaskbb.log;
  205. location / {
  206. try_files $uri @flaskbb;
  207. }
  208. # Static files
  209. location /static {
  210. alias /var/apps/flaskbb/flaskbb/static/;
  211. }
  212. location ~ ^/_themes/([^/]+)/(.*)$ {
  213. alias /var/apps/flaskbb/flaskbb/themes/$1/static/$2;
  214. }
  215. # robots.txt
  216. location /robots.txt {
  217. alias /var/apps/flaskbb/flaskbb/static/robots.txt;
  218. }
  219. location @flaskbb {
  220. uwsgi_pass 127.0.0.1:30002;
  221. include uwsgi_params;
  222. }
  223. }
  224. Like in the `uWSGI <#uwsgi>`_ chapter, don't forget to create a symlink to
  225. ``/etc/nginx/sites-enabled/``.
  226. Deploying to PythonAnywhere
  227. ---------------------------
  228. `PythonAnywhere <https://www.pythonanywhere.com/>`_ is a platform-as-a-service, which basically means they have a bunch of servers pre-configured with Python, nginx and uWSGI. You can run a low-traffic website with them for free, so it's an easy way to get quickly FlaskBB running publicly.
  229. Here's what to do:
  230. * Sign up for a PythonAnywhere account at `https://www.pythonanywhere.com/ <https://www.pythonanywhere.com/>`_.
  231. * On the "Consoles" tab, start a Bash console and install/configure FlaskBB like this:
  232. ::
  233. git clone https://github.com/sh4nks/flaskbb.git
  234. cd flaskbb
  235. pip3.5 install --user -r requirements.txt
  236. python3.5 manage.py initdb
  237. * Click the PythonAnywhere logo to go back to the dashboard, then go to the "Web" tab, and click the "Add a new web app" button.
  238. * Just click "Next" on the first page.
  239. * On the next page, click "Flask"
  240. * On the next page, click "Python 3.5"
  241. * On the next page, just accept the default and click next
  242. * Wait while the website is created.
  243. * Click on the "Source code" link, and in the input that appears, replace the `mysite` at the end with `flaskbb`
  244. * Click on the "WSGI configuration file" filename, and wait for an editor to load.
  245. * Change the line that sets `project_home` to replace `mysite` with `flaskbb` again.
  246. * Change the line that says
  247. ::
  248. from flask_app import app as application
  249. ...to say
  250. ::
  251. from manage import app as application
  252. * Click the green "Save" button near the top right.
  253. * Go back to the "Web" tab.
  254. * Click the green "Reload..." button.
  255. * Click the link to visit the site -- you'll have a new FlaskBB install!