- Create a project required environment
- Install a pipenv
pip3 install pipenv - To create virtual env for project
pipenv install
Note: it will Creating a virtualenv for this project… and it will create the pipfile.lock for [dev-packages] and [packages].
- To activate this project's virtualenv, run
pipenv shell - Create project in flask and install
pipenv install flask - Go to the your virtualenv in command prompt for windows
Note: Go to the your virtualenv in terminal for windows
set FLASK_APP=urlshortexport FLASK_APP=urlshort - Run the flask app
flask run - How to move on to the flask app to production to development in command prompt
set FLASK_ENV=development - Then run app
flask run
Protocol for python application in order to server websites unified order.
Deploying the application into ubuntu Servers
- First upload code to server
sudo git clone https://github.com/sada498/url-shortener.git - Move into the directory
cd url-shorener - Install pipenv
sudo apt install python3-pippippip3 install pipenevpipenv shell(Note: I use export because of Linux terminal )export FlASK_APP=urlshortflask run - After that make your application public
flask run –host=0.0.0.0 - Visit the server public ip with port id
Ip:portnumber
-
Install Gunicorn on same server
pipenv install gunicorn -
Running with Gunicorn
gunicorn “urlshort:create_app()” -b 0.0.0.0 -
Recommend to run flask on nginx (to install on Linux )
sudo apt install nginx -
To check the nginx running on server
systemctl status nginxNote: check the Status check Active
-
To fix the configuration of the file to enable the app in nginx
sudo nano /etc/ninx/sites-enabled/default -
Past the following code on the configuration file check the both server and location
server { listen 80; server_name example.org; access_log /var/log/nginx/example.log; location / { proxy_pass http://127.0.0.1:8000; proxy_set_header Host $host; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } } -
After setting up the above code into config file
Ctrl +x ( exit ) -
Run the gunicorn all the time
gunicorn “urlshort:create_app( ) ” -b 0.0.0.0 --daemon -
Upload files to correct location on server according to our app.
nano urlshort/urlshort.py -
Change the file location to where do you want to save the static files on your server
Thanks :) Nick Walter
