Tech Monger

Programming, Web Development and Computer Science.

Skip to main content| Skip to information by topic

How to create simple Flask application on Openshift

In this tutorial we will learn deployment of flask application on openshift. I assume that you have some working knowledge of openshift, python, flask and git.


Make sure you answer affirmatively to the following things before we proceed with this tutorial.

  • Have working Openshift account.

  • Have created Openshift namespace.

  • Have created Python application on Openshift.

  • Can ssh into application repository using

    • ssh
    • ssh
  • Have cloned application git repository locally using

    • git clone ssh://
    • git clone ssh://
  • Can see default openshift python web page at



If you have answered Yes to above questions then let’s start with Hello World Flask App.

Creating Application Locally

Before deploying we will create flask application locally. You should have flask package installed locally in your python setup. You can either install flask globally or better install it in virtual environment using

pip install flask

Create file in your project folder and copy following hello world app code into the file.

from flask import Flask
app = Flask(__name__)

def hello():
    return "Hello World!"

if __name__ == "__main__":

Make sure you are able to see Hello World! in your browser by running created program using


If you face error in above make sure flask is installed correctly and try again.

Local Openshift Repository

In the cloned openshift repository you would see following three files, each has its purpose.

  • requirements.txt Application Dependencies
  • Application Metadata and Required Packages
  • WSGI Interface

Note that the default openshift python web page code stored in file.

Editing Local Repository

Update file with metadata and required installation packages. Your file should have following content

from setuptools import setup

      description='Simple flask openshift application',
      author='Tech Monger',

Note that we have removed Django from install_requires and added flask.

Now add application file that we have created earlier into this repository.

Remove existing default openshift python code from and import web application in Your file should have following content.

import os

virtenv = os.environ['OPENSHIFT_PYTHON_DIR'] + '/virtenv/'
virtualenv = os.path.join(virtenv, 'bin/')
    execfile(virtualenv, dict(__file__=virtualenv))
except IOError:
# IMPORTANT: Put any additional includes below this line.  If placed above this
# line, it's possible required libraries won't be in your searchable path

# Importing Hello World application

from web_app import app as application

If you take a look at content of file then you would find that openshift internally uses virtual environment for your application and activates same before starting of the application.

Keep requirements.txt empty as we will discuss more about it further.

Deploying Application

Before we push local changes make sure you have committed the same. To commit changes enter into the local repository folder and do following git operations.

git add .
git commit -m “Hello World App”
git push

Once pushed you would see changes getting deployed on openshift by application restart.

Now you will be able to find your application up and running at application url

Manually Installing Packages

You can also add your dependencies into requirements.txt instead of but openshift would not install dependencies automatically due to the way directory permissions on openshift are configured. There is workaround to install dependencies manually.

Your requirements.txt file should have following content. You can get these dependencies by doing

pip freeze

Add, commit and push local changes.

git add .
git commit -m “Manual dependency installation”
git push

Upon pushing you would see following error.

remote: The directory '/var/lib/openshift/5855124a7628e1df1800006e/.cache/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.

While building package you would get following error.

remote: OSError: [Errno 13] Permission denied: '/var/lib/openshift/585505782d5271c9f400013d/.cache'

To install dependencies manually perform the following

  1. ssh openshift application like below for each package.

    • ssh
    • ssh
  2. Once logged in, activate virtual environment of your application remotely on openshift

    • Navagate to openshift python directory using following environment variable

    • Activate Virtual Environment

      • . virtenv/bin/activate
  3. Install dependencies from requirements.txt

    • Navigate to application repository using following environment variable

    • Install packages using pip with no-cache flag

      • pip install -r requirements.txt --no-cache

Now you shall see that your all dependencies are installed and application is up and running.

Tagged Under : Flask Linux Python Web