From 719b1232331d247eeb543ad7e594d69c30ec1540 Mon Sep 17 00:00:00 2001 From: PLUJA <64632615+pluja@users.noreply.github.com> Date: Sat, 5 Sep 2020 09:43:13 +0200 Subject: [PATCH] Update SELF-HOSTING.md --- SELF-HOSTING.md | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/SELF-HOSTING.md b/SELF-HOSTING.md index bf2cbee..6c18559 100644 --- a/SELF-HOSTING.md +++ b/SELF-HOSTING.md @@ -61,14 +61,15 @@ Now you should be logged in. Make sure to set up a good password. It is recommen * `flask db upgrade` 7. Set up `.env` - 1. (PRE) Generate a random string and copy it to clipboard: + 1. (PRE) Generate a **random string** and copy it to clipboard: `python3 -c "import uuid; print(uuid.uuid4().hex)"` 2. Create a `.env` file on the root folder of the project (`/home/ubuntu/Yotter/.env`): ``` - SECRET_KEY= + SECRET_KEY= DATABASE_URL=mysql+pymysql://yotter:@localhost:3306/yotter ``` +Make sure you change `` and `>db-password>`. `` should be different from the password of the database root user (the one you set up on step 1.2). This password will be needed later. #### Step 2: Setting up the MySQL Database: * Open the MySQL prompt line (Use the previously set MySQL root password!) @@ -80,7 +81,7 @@ Now you should be on the MySQL prompt line (`mysql>`). So let's create the datab > Change `` for a password of your like. It will be the password for the dabase user `yotter`. Don't choose the same password as the root user of MySQL for security. -> The password ` The password `` for the **yotter** user needs to match the password that you included in the `DATABASE_URL` variable in the `.env` file. If you want to change it, you can change it now. ``` mysql> create database yotter character set utf8 collate utf8_bin; @@ -97,10 +98,12 @@ If your set up was correct, you should now be able to run: #### Step 3: Setting up Gunicorn and Supervisor When you run the server with flask run, you are using a web server that comes with Flask. This server is very useful during development, but it isn't a good choice to use for a production server because it wasn't built with performance and robustness in mind. Instead of the Flask development server, for this deployment I decided to use gunicorn, which is also a pure Python web server, but unlike Flask's, it is a robust production server that is used by a lot of people, while at the same time it is very easy to use. [ref](https://blog.miguelgrinberg.com/post/the-flask-mega-tutorial-part-xvii-deployment-on-linux) -* Start yotter under Gunicorn: +* Start yotter under Gunicorn and check it has no errors: `gunicorn -b localhost:8000 -w 4 yotter:app` +Once you see that no errors appear, you can stop gunicorn by pressing `Ctrl+C`. + The supervisor utility uses configuration files that tell it what programs to monitor and how to restart them when necessary. Configuration files must be stored in /etc/supervisor/conf.d. Here is a configuration file for Yotter, which I'm going to call yotter.conf [ref](https://blog.miguelgrinberg.com/post/the-flask-mega-tutorial-part-xvii-deployment-on-linux). * Create a yotter.conf file on `/etc/supervisor/conf.d/`: