-
Notifications
You must be signed in to change notification settings - Fork 39
Installation
The python version for install nanobrok-server is high python>=3.7 (I recommand this version). If you just want to use the tool, you can install Nanobrok-server in a few different ways according to what you find easiest.
- virtualenv
- docker
- heroku
- VPS
The nanobrok-server can be to install easily using the virtualenv, you should be install the virtualenv your python version.
Installing a virtualenv is done using pip, Python's package manager. follow a google tutorial how to install pip your Operational system (OS).
$ pip3 install virtualenv
Next step is create your local enverioment with command bellow:
$ virtualenv -p python3.7 venv
After creating a virtualenv, we need to activate it so that we can install the necessary project packages. For this, we use the following command:
- source venv/bin/activate (Linux ou macOS)
- venv/Scripts/Activate (Windows)
With virtualenv enabled, we can install the necessary packages using the PIP itself:
$ pip install -r requirements.txt
if you got this message error from psycopg2:
ERROR: Could not find a version that satisfies the requirement psycopg2>=2.8.5 (from versions: 2.0.10, 2.0.11, 2.0.12, 2.0.13, 2.0.14, 2.2.0, 2.2.1, 2.2.2, 2.3.0, 2.3.1, 2.3.2, 2.4, 2.4.1, 2.4.2, 2.4.3, 2.4.4, 2.4.5, 2.4.6, 2.5, 2.5.1, 2.5.2, 2.5.3, 2.5.4, 2.5.5, 2.6, 2.6.1, 2.6.2, 2.7, 2.7.1, 2.7.2, 2.7.3, 2.7.3.1, 2.7.3.2, 2.7.4, 2.7.5, 2.7.6, 2.7.6.1, 2.7.7, 2.8, 2.8.1, 2.8.2, 2.8.3, 2.8.4, 2.8.5, 2.8.6, 2.9, 2.9.1)
ERROR: No matching distribution found for psycopg2>=2.8.5
Install the libpg and python3.7 dev :
sudo apt install libpq-dev python3.7-dev
You might need to install python3.8-dev or similar for e.g. Python 3.8.
Try this and repeat the command pip above again, try to solve the problem with psycopg2:
sudo apt-get install postgresql
pip install psycopg2-binary
By default nanobrok use the dababase of postgresql to save all data, but you can set your database manager in settings.toml, checkout how to config connection URI with flask.
The sqlite is a great way to use for test nanabrok in your localhost, it more easy to setup:
1 - Open the settings.toml file and find the SQLALCHEMY_DATABASE_URI
in section [localhost].
2 - Now, you should be configure or set your .db file like this 'sqlite:///development.db'
the value of SQLALCHEMY_DATABASE_URI
is a string with path of file sqlite.
The evenrioment is a great way to settings your server with more secure, in this file you should be add somes information about your env, and somes flag of flask, you need to create this file on current root folder of the project. see the example:
FLASK_ENV=development
FLASK_DEBUG=1
FLASK_APP=nanobrok.app:create_app()
look, the variable FLASK_ENV
is a name your section in settings.toml if you want to run with localhost settings your should be change this option on file .env
. after that you can run the command: flask run
for mount your server or use the makefile make start
.
After create your .env file, now you can to settings,build and populate your database. the nanabrok-server have somes command line, checkout:
# type flask in terminal to show this
add-user Adds a new user to the database
create-db Creates database
db Perform database migrations.
drop-db Cleans database
populate-db Populate db with sample data
populate-db-dev Populate db with sample data
populate-db-prod Populate db with data for production
routes Show the routes for the app.
run Run a development server.
shell Runs a shell in the app context.
Commands: This command bellow is used for create the tables into database file or manager.
flask create-db
This command bellow is used for populate the default user admin, after run this command it recommanded change the default username and password in file nanobrok/ext/commands.py
.
$ flask populate-db
This command bellow is used for delete all tables into database.
$ flask drop-db
This command bellow s used for start the webserver (nanobrok-server) with flask application.
$ flask run
frist of all, the commands populate-db
and create-db
is made for run after on setup your remote server, follow the steps for create the all tables in database and create the frist username and password of nanobrok-server:
$ flask create-db
$ flask populate-db
after that, the only thing you should do is run the service of nanobrok applicaiton, look the param --host
is used when your is running in localhost:
$ flask run --host 0.0.0.0 --port 5000
now, open the browser type http://localhost:50000
if your running in localhost.
if you have a VPS (virtual private server), it great! because you can to install nanobrok-server easily. le't go...
The first steps is install somes dependency for build your nanobrok-server.
sudo apt-get install python3.7 python3.7-dev
sudo apt install gunicorn3
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.7 2
sudo pip3 install psycopg2-binary
ok, the first command is for python3.7, after that we need to install gunicorn3 for build your server in background process and change the default python for python3.7.
now, we need to clone the nanobrok-server, and install the all depedency of project.
git clone https://github.com/P0cL4bs/Nanobrok-server
cd Nanobrok-server
python3.7 -m pip install -r requirements.txt
now, we need to create the database and initial settings. for make this, open the file settings.tmol go to section development and change this:
1 - set the SECRET_KEY
for random string, type this on terminal:
tr -dc A-Za-z0-9 </dev/urandom | head -c 20 ; echo ''
2 - change the SQLALCHEMY_DATABASE_URI
like this, we should be use the sqlite for build us database, but you can use the postgresql if your want.
SQLALCHEMY_DATABASE_URI = 'sqlite:///development.db'
3 - The evenrioment is a great way to settings your server with more secure, in this file you should be add somes information about your env, and somes flags of flask, you need to create this file on current root folder of the project. see the example:
FLASK_ENV=development
FLASK_DEBUG=1
FLASK_APP=nanobrok.app:create_app()
ok, everything is great with settings.
the last step is create a service from systemctl for better control the server. use the command nano
to create a file in system service.
nano /etc/systemd/system/nanobrok.service
Past the code bellow with your settings folder path in /root/nanobrok-server
and change the root
for your username:
[Unit]
Description=Nanobrok service
After=network.target
[Service]
User=root
Group=www-data
WorkingDirectory=/root/nanobrok-server
ExecStart=/usr/bin/gunicorn3 -b 0.0.0.0:80 --workers 3 -w 1 --threads 100 -m 007 "nanobrok.app:create_app()" --preload --env FLASK_ENV=development
great, now we should be create the tables and create the default username and password for do login in nanobrok-server, find the file nanobrok/ext/commands.py
and change the variable bellow.
"""Populate db with sample data"""
user_data = {
"username": "yourusername",
"password": "yourpassword",
}
now, after that, run the command for create the table and populate the default user in system.
$ flask create-db
$ flask populate-db
so, the finish is run the service in background, checkout !
sudo systemctl start nanobrok.service
© Copyright 2021, Nanobrok - P0cL4bs Team