installation.rst 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499
  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. We recommend installing FlaskBB in an isolated Python environment. This can be
  10. achieved with `virtualenv`_. In our little guide we will use a wrapper around
  11. virtualenv - the `virtualenvwrapper`_. In addition to virtualenv, we will also
  12. use the package manager `pip`_ to install the dependencies for FlaskBB.
  13. Virtualenv Setup
  14. ~~~~~~~~~~~~~~~~
  15. The easiest way to install `virtualenv`_ and
  16. `virtualenvwrapper`_ is, to use the package manager on your system (if you
  17. are running Linux) to install them.
  18. For example, on archlinux you can install them with::
  19. $ sudo pacman -S python2-virtualenvwrapper
  20. or, on macOS, you can install them with::
  21. $ sudo pip install virtualenvwrapper
  22. It's sufficient to just install the virtualenvwrapper because it depends on
  23. virtualenv and the package manager will resolve all the dependncies for you.
  24. After that, you can create your virtualenv with::
  25. $ mkvirtualenv -a /path/to/flaskbb -p $(which python2) flaskbb
  26. This will create a virtualenv named ``flaskbb`` using the python interpreter in
  27. version 2 and it will set your project directory to ``/path/to/flaskbb``.
  28. This comes handy when typing ``workon flaskbb`` as it will change your
  29. current directory automatically to ``/path/to/flaskbb``.
  30. To deactivate it you just have to type ``deactivate`` and if you want to work
  31. on it again, just type ``workon flaskbb``.
  32. If you want to know more about those isolated python environments, checkout
  33. the `virtualenv`_ and `virtualenvwrapper`_ docs.
  34. Required Dependencies
  35. ~~~~~~~~~~~~~~~~~~~~~
  36. Now that you have set up your environment, you are ready to install the
  37. dependencies.
  38. ::
  39. $ pip install -r requirements.txt
  40. Alternatively, you can use the `make` command to install the dependencies.
  41. ::
  42. $ make dependencies
  43. Optional Dependencies
  44. ~~~~~~~~~~~~~~~~~~~~~~
  45. We have one optional dependency, redis (the python package is installed
  46. automatically).
  47. If you want to use it, make sure that a redis-server is running.
  48. Redis will be used as the default result and caching backend for
  49. celery (celery is a task queue which FlaskBB uses to send non blocking emails).
  50. The feature for tracking the `online guests` and `online users` do also
  51. require redis (although `online users` works without redis as well).
  52. To install redis, just use your distributions package manager. For Arch Linux
  53. this is `pacman` and for Debian/Ubuntu based systems this is `apt-get`.
  54. ::
  55. # Installing redis using 'pacman':
  56. $ sudo pacman -S redis
  57. # Installing redis using 'apt-get':
  58. $ sudo apt-get install redis-server
  59. # Check if redis is already running.
  60. $ systemctl status redis
  61. # If not, start it.
  62. $ sudo systemctl start redis
  63. # Optional: Lets start redis everytime you boot your machine
  64. $ sudo systemctl enable redis
  65. Configuration
  66. -------------
  67. FlaskBB will no longer assume which config to use. By default, it will load
  68. a config with some sane defaults (i.e. debug off) but thats it.
  69. You can either pass the import string to a config object or
  70. the path to the config file, which is in turn a valid python file.
  71. A valid import string, for example, is::
  72. flaskbb.configs.development.DevelopmentConfig
  73. and if you wish to use a configuration file, you are free to place it anywhere
  74. your app user has read access. Please note, that if you decide to use a
  75. relativ path, it will start looking for the file in the 'root' directory
  76. of FlaskBB (this is, where the README.md, LICENSE, etc. files are in).
  77. Absolut paths are also supported. Use whatever you like.
  78. ::
  79. flaskbb --config dev_config.cfg run
  80. [+] Using config from: /path/to/flaskbb/dev_config.cfg
  81. * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
  82. Development
  83. ~~~~~~~~~~~
  84. For development, you need to copy ``flaskbb/configs/development.py.example`` to
  85. ``flaskbb/configs/development.py``.
  86. ::
  87. cp flaskbb/configs/development.py.example flaskbb/configs/development.py
  88. And you should be ready to go!
  89. You can either run::
  90. make run
  91. or::
  92. flaskbb --config flaskbb.configs.development.DevelopmentConfig run
  93. to start the development server using the development config.
  94. Production
  95. ~~~~~~~~~~
  96. FlaskBB already sets some sane defaults, so you shouldn't have to change much.
  97. There are only a few things you have to do. Here we will use the provided
  98. `production.py.example` configuration file as a template.
  99. Let's copy the example config (production.py file is in .gitignore)::
  100. cp flaskbb/configs/production.py.example flaskbb/configs/production.py
  101. and now you are ready to start adjusting the config.
  102. Open `production.py` with your favorite editor and search for the following
  103. configuration variables and change them accordingly to your needs:
  104. - ``SERVER_NAME = "example.org"``
  105. - ``PREFERRED_URL_SCHEME = "https"``
  106. - ``SQLALCHEMY_DATABASE_URI = 'sqlite:///path/to/flaskbb.sqlite'``
  107. - ``SECRET_KEY = "secret key"``
  108. - ``WTF_CSRF_SECRET_KEY = "reallyhardtoguess"``
  109. Redis
  110. ~~~~~
  111. If you have decided to use redis as well, which we highly recommend, then
  112. the following services and features can be enabled and configured to use redis.
  113. Before you can start using redis, you have to enable and configure it.
  114. This is quite easy just set ``REDIS_ENABLE`` to ``True`` and adjust the
  115. ``REDIS_URL`` if needed.::
  116. REDIS_ENABLED = True
  117. REDIS_URL = "redis://localhost:6379" # or with a password: "redis://:password@localhost:6379"
  118. REDIS_DATABASE = 0
  119. The other services are already configured to use the REDIS_URL configuration
  120. variable.
  121. **Celery**
  122. ::
  123. CELERY_BROKER_URL = REDIS_URL
  124. CELERY_RESULT_BACKEND = REDIS_URL
  125. **Caching**
  126. ::
  127. CACHE_TYPE = "redis"
  128. CACHE_REDIS_URL = REDIS_URL
  129. **Rate Limiting**
  130. ::
  131. RATELIMIT_ENABLED = True
  132. RATELIMIT_STORAGE_URL = REDIS_URL
  133. Mail Examples
  134. ~~~~~~~~~~~~~
  135. Both methods are included in the example configs.
  136. **Google Mail**
  137. ::
  138. MAIL_SERVER = "smtp.gmail.com"
  139. MAIL_PORT = 465
  140. MAIL_USE_SSL = True
  141. MAIL_USERNAME = "your_username@gmail.com"
  142. MAIL_PASSWORD = "your_password"
  143. MAIL_DEFAULT_SENDER = ("Your Name", "your_username@gmail.com")
  144. **Local SMTP Server**
  145. ::
  146. MAIL_SERVER = "localhost"
  147. MAIL_PORT = 25
  148. MAIL_USE_SSL = False
  149. MAIL_USERNAME = ""
  150. MAIL_PASSWORD = ""
  151. MAIL_DEFAULT_SENDER = "noreply@example.org"
  152. Installation
  153. ------------
  154. For a guided install, run::
  155. $ make install
  156. or::
  157. flaskbb install
  158. During the installation process you are asked about your username,
  159. your email address and the password for your administrator user. Using the
  160. `make install` command is recommended as it checks that the dependencies
  161. are also installed.
  162. Upgrading
  163. ---------
  164. If the database models changed after a release, you have to run the ``upgrade``
  165. command::
  166. flaskbb db upgrade
  167. Deploying
  168. ---------
  169. This chapter will describe how to set up Supervisor + uWSGI + nginx for
  170. FlaskBB as well as document how to use the built-in WSGI server (gunicorn)
  171. that can be used in a productive environment.
  172. Supervisor
  173. ~~~~~~~~~~
  174. `Supervisor is a client/server system that allows its users to monitor and
  175. control a number of processes on UNIX-like operating systems.`
  176. To install `supervisor` on Debian, you need to fire up this command:
  177. ::
  178. $ sudo apt-get install supervisor
  179. There are two ways to configure supervisor. The first one is, you just put
  180. the configuration to the end in the ``/etc/supervisor/supervisord.conf`` file.
  181. The second way would be to create a new file in the ``/etc/supervisor/conf.d/``
  182. directory. For example, such a file could be named ``uwsgi.conf``.
  183. After you have choosen the you way you like, simply put the snippet below in the
  184. configuration file.
  185. ::
  186. [program:uwsgi]
  187. command=/usr/bin/uwsgi --emperor /etc/uwsgi/apps-enabled
  188. user=apps
  189. stopsignal=QUIT
  190. autostart=true
  191. autorestart=true
  192. redirect_stderr=true
  193. uWSGI
  194. ~~~~~
  195. `uWSGI is a web application solution with batteries included.`
  196. To get started with uWSGI, you need to install it first.
  197. You'll also need the python plugin to serve python apps.
  198. This can be done with::
  199. $ sudo apt-get install uwsgi uwsgi-plugin-python
  200. For the configuration, you need to create a file in the
  201. ``/etc/uwsgi/apps-available`` directory. In this example, I will call the
  202. file ``flaskbb.ini``. After that, you can start with configuring it.
  203. My config looks like this for `flaskbb.org` (see below). As you might have noticed, I'm
  204. using a own user for my apps whose home directory is located at `/var/apps/`.
  205. In this directory there are living all my Flask apps.
  206. ::
  207. [uwsgi]
  208. base = /var/apps/flaskbb
  209. home = /var/apps/.virtualenvs/flaskbb/
  210. pythonpath = %(base)
  211. socket = 127.0.0.1:30002
  212. module = wsgi
  213. callable = flaskbb
  214. uid = apps
  215. gid = apps
  216. logto = /var/apps/flaskbb/logs/uwsgi.log
  217. plugins = python
  218. =============== ========================== ===============
  219. **base** /path/to/flaskbb The folder where your flaskbb application lives
  220. **home** /path/to/virtualenv/folder The virtualenv folder for your flaskbb application
  221. **pythonpath** /path/to/flaskbb The same as base
  222. **socket** socket This can be either a ip or the path to a socket (don't forget to change that in your nginx config)
  223. **module** wsgi.py This is the file located in the root directory from flaskbb (where manage.py lives).
  224. **callable** flaskbb The callable is application you have created in the ``wsgi.py`` file
  225. **uid** your_user The user who should be used. **NEVER** use root!
  226. **gid** your_group The group who should be used.
  227. **logto** /path/to/log/file The path to your uwsgi logfile
  228. **plugins** python We need the python plugin
  229. =============== ========================== ===============
  230. Don't forget to create a symlink to ``/etc/uwsgi/apps-enabled``.
  231. ::
  232. ln -s /etc/uwsgi/apps-available/flaskbb /etc/uwsgi/apps-enabled/flaskbb
  233. gunicorn
  234. ~~~~~~~~
  235. `Gunicorn 'Green Unicorn' is a Python WSGI HTTP Server for UNIX.`
  236. It's a pre-fork worker model ported from Ruby's Unicorn project.
  237. The Gunicorn server is broadly compatible with various web frameworks,
  238. simply implemented, light on server resources, and fairly speedy.
  239. This is probably the easiest way to run a FlaskBB instance.
  240. Just install gunicorn via pip inside your virtualenv::
  241. pip install gunicorn
  242. FlaskBB has an built-in command to gunicorn::
  243. flaskbb start
  244. To see a full list of options either type ``flaskbb start --help`` or
  245. visit the :ref:`cli <commandline>` docs.
  246. nginx
  247. ~~~~~
  248. `nginx [engine x] is an HTTP and reverse proxy server,
  249. as well as a mail proxy server, written by Igor Sysoev.`
  250. The nginx config is pretty straightforward. Again, this is how I use it for
  251. `FlaskBB`. Just copy the snippet below and paste it to, for example
  252. ``/etc/nginx/sites-available/flaskbb``.
  253. The only thing left is, that you need to adjust the ``server_name`` to your
  254. domain and the paths in ``access_log``, ``error_log``. Also, don't forget to
  255. adjust the paths in the ``alias`` es, as well as the socket address in ``uwsgi_pass``.
  256. ::
  257. server {
  258. listen 80;
  259. server_name forums.flaskbb.org;
  260. access_log /var/log/nginx/access.forums.flaskbb.log;
  261. error_log /var/log/nginx/error.forums.flaskbb.log;
  262. location / {
  263. try_files $uri @flaskbb;
  264. }
  265. # Static files
  266. location /static {
  267. alias /var/apps/flaskbb/flaskbb/static/;
  268. }
  269. location ~ ^/_themes/([^/]+)/(.*)$ {
  270. alias /var/apps/flaskbb/flaskbb/themes/$1/static/$2;
  271. }
  272. # robots.txt
  273. location /robots.txt {
  274. alias /var/apps/flaskbb/flaskbb/static/robots.txt;
  275. }
  276. location @flaskbb {
  277. uwsgi_pass 127.0.0.1:30002;
  278. include uwsgi_params;
  279. }
  280. }
  281. If you wish to use gunicorn instead of uwsgi just replace the ``location @flaskbb``
  282. with this::
  283. location @flaskbb {
  284. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  285. proxy_set_header X-Forwarded-Proto $scheme;
  286. proxy_set_header Host $http_host;
  287. #proxy_set_header SCRIPT_NAME /forums; # This line will make flaskbb available on /forums;
  288. proxy_redirect off;
  289. proxy_buffering off;
  290. proxy_pass http://127.0.0.1:8000;
  291. }
  292. Don't forget to adjust the ``proxy_pass`` address to your socket address.
  293. Like in the `uWSGI <#uwsgi>`_ chapter, don't forget to create a symlink to
  294. ``/etc/nginx/sites-enabled/``.
  295. User Contributed Deployment Guides
  296. ----------------------------------
  297. We do not maintain these deployment guides. They have been submitted by users
  298. and we thought it is nice to include them in docs. If something is missing,
  299. or doesn't work - please open a new pull request on GitHub.
  300. Deploying to PythonAnywhere
  301. ~~~~~~~~~~~~~~~~~~~~~~~~~~~
  302. `PythonAnywhere <https://www.pythonanywhere.com/>`_ is a
  303. platform-as-a-service, which basically means they have a bunch of servers
  304. pre-configured with Python, nginx and uWSGI.
  305. You can run a low-traffic website with them for free,
  306. so it's an easy way to get quickly FlaskBB running publicly.
  307. Here's what to do:
  308. * Sign up for a PythonAnywhere account at
  309. `https://www.pythonanywhere.com/ <https://www.pythonanywhere.com/>`_.
  310. * On the "Consoles" tab, start a Bash console and install/configure
  311. FlaskBB like this
  312. ::
  313. git clone https://github.com/sh4nks/flaskbb.git
  314. cd flaskbb
  315. pip3.5 install --user -r requirements.txt
  316. pip3.5 install --user -e .
  317. * Click the PythonAnywhere logo to go back to the dashboard,
  318. then go to the "Web" tab, and click the "Add a new web app" button.
  319. * Just click "Next" on the first page.
  320. * On the next page, click "Flask"
  321. * On the next page, click "Python 3.5"
  322. * On the next page, just accept the default and click next
  323. * Wait while the website is created.
  324. * Click on the "Source code" link, and in the input that appears,
  325. replace the `mysite` at the end with `flaskbb`
  326. * Click on the "WSGI configuration file" filename,
  327. and wait for an editor to load.
  328. * Change the line that sets `project_home` to replace `mysite` with `flaskbb`
  329. again.
  330. * Change the line that says
  331. ::
  332. from flask_app import app as application
  333. to say
  334. ::
  335. from flaskbb import create_app
  336. application = create_app("/path/to/your/configuration/file")
  337. * Click the green "Save" button near the top right.
  338. * Go back to the "Web" tab.
  339. * Click the green "Reload..." button.
  340. * Click the link to visit the site -- you'll have a new FlaskBB install!
  341. .. _virtualenv: https://virtualenv.pypa.io/en/latest/installation.html
  342. .. _virtualenvwrapper: http://virtualenvwrapper.readthedocs.org/en/latest/install.html#basic-installation
  343. .. _pip: http://www.pip-installer.org/en/latest/installing.html