Update SELF-HOSTING.md

This commit is contained in:
PLUJA 2020-09-05 09:43:13 +02:00 committed by GitHub
parent 1e11f86b91
commit 719b123233
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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=<RandomStringHere!>
SECRET_KEY=<RandomString>
DATABASE_URL=mysql+pymysql://yotter:<db-password>@localhost:3306/yotter
```
Make sure you change `<RandomString>` and `>db-password>`. `<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 `<db-password>` 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 `<db-password` for the **yotter** user needs to match the password that you included in the `DATABASE_URL` variable in the `.env` file. If you didn't change it, you can change it now.
> The password `<db-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/`: