Nishu

nishumsn03@gmail.com

Deployment On DigitalOcean for Python Flask project

Posted on June 29, 2021



>sudo apt install libapache2-mod-wsgi-py3

www>mkdir flaskapp

>cd flaskapp

>mkdir flaskapp

>sudo apt install python3-pip

>pip3 install virtualenv

>sudo virtualenv venv

>source venv/bin/activate

>pip3 install flask request pandas flask-slqalchemy

>cd /etc/apache2/sites-available

>cp 000-default.conf flaskapp.conf


>nano flaskapp.conf

Open flaskapp.conf and copy paste below code:

<VirtualHost *:80>
# The ServerName directive sets the request scheme, hostname and port that
# the server uses to identify itself. This is used when creating
# redirection URLs. In the context of virtual hosts, the ServerName
# specifies what hostname must appear in the request's Host: header to
# match this virtual host. For the default virtual host (this file) this
# value is not decisive as it is used as a last resort host regardless.
# However, you must set it for any further virtual host explicitly.
#ServerName www.python-ds.com
ServerName python-ds.com
ServerAlias www.python-ds.com
ServerAdmin python.ds.com@gmail.com
WSGIScriptAlias / /var/www/flaskapp/flaskapp.wsgi
<Directory /var/www/flaskapp/flaskapp/>
Order allow,deny
Allow from all
</Directory>
Alias /static /var/www/flaskapp/flaskapp/static
<Directory /var/www/flaskapp/static/>
Order allow,deny
Allow from all
</Directory>
# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the loglevel for particular
# modules, e.g.
#LogLevel info ssl:warn
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
# For most configuration files from conf-available/, which are
# enabled or disabled at a global level, it is possible to
# include a line for only one particular virtual host. For example the
# following line enables the CGI configuration for this host only
# after it has been globally disabled with "a2disconf".
#Include conf-available/serve-cgi-bin.conf
</VirtualHost>
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet
<Directory>

>sudo a2ensite flaskapp.conf

>service apache2 restart

>cd /var/www/flaskapp

>sudo nano flaskapp.wsgi

open flaskapp.wsgi and copy paste below code according to your need:

#!/usr/bin/python
import sys
import logging
logging.basicConfig(stream=sys.stderr)
sys.path.insert(0,"/var/www/flaskapp/")
from flaskapp import app as application
application.secret_key = '\xfd{H\xe5<\x95\xf9\xe3\x96.5\xd1\x01O<!\xd5\xa2\xa0\x9fR"\xa1\xa8'

>python3 __init__.py

>service apache2 restart


Sign In for comment and like the post.
admin

assad