From fc20f584dc61e1f00bc1571e27720f613226b287 Mon Sep 17 00:00:00 2001 From: Ofen <32882793+0fen@users.noreply.github.com> Date: Wed, 27 Jun 2018 16:16:29 +0300 Subject: [PATCH] Update mod_wsgi.rst Added deploying information to a shared hosting --- docs/deploying/mod_wsgi.rst | 55 +++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/docs/deploying/mod_wsgi.rst b/docs/deploying/mod_wsgi.rst index c9da6a2d..97408313 100644 --- a/docs/deploying/mod_wsgi.rst +++ b/docs/deploying/mod_wsgi.rst @@ -215,3 +215,58 @@ For Python 3 add the following lines to the top of your ``.wsgi`` file:: This sets up the load paths according to the settings of the virtual environment. Keep in mind that the path has to be absolute. + +Deploying to shared hosting +--------------------------------- + +You can deploy flask application to shared hosting. + +`Requirements:` + +1. Shared hosting with ``SSH`` and ``mod_wsgi`` support + +2. Python with pip and virtualenv module (pre-installed or compiled from source to ``~/.local/``) + +3. Virtual enviroment with flask application dependencies + +4. Flask application inside your ``/public_html`` folder + +5. ``.htaccess`` file and ``wsgi-script`` (e.g. ``wsgi.py``) + +Content of ``.htaccess`` file: + +.. sourcecode:: apache + + AddDefaultCharset utf-8 + AddHandler wsgi-script .py + RewriteEngine On + RewriteCond %{REQUEST_FILENAME} !-f + RewriteRule ^(.*)$ /wsgi.py/$1 [QSA,L] + +Content of ``wsgi.py`` file: + +.. sourcecode:: python + + #!/home/u/username/.local/bin/python + # -*- coding: utf-8 -*- + + import logging + import sys + # Adding dependencies for flask application to $PATH + sys.path.insert(0, '/home/u/username/public_html/venv/lib/python3.6/site-packages/') + # Adding flask application folder to $PATH + sys.path.insert(0, '/home/u/username/public_html/') + + # Importing flask application + from app import app + + # Removing wsgi.py file name from url + class ScriptNameStripper(object): + def __init__(self, app): + self.app = app + + def __call__(self, environ, start_response): + environ['SCRIPT_NAME'] = '' + return self.app(environ, start_response) + + application = ScriptNameStripper(app)