title: Deploying flask app to Apache shared hosting
body: <p>I am trying to deploy a simple flask application in the Apache shared hosting server.</p>
  
  <p>I am not sure what is wrong here.</p>
  
  <p>I am stuck at the <code>.cgi</code> file for now.</p>
  
  <p>The flask app - hello.py:</p>
  
  <pre><code>#!/usr/bin/python
  
  from flask import Flask
  app = Flask(__name__)
  
  @app.route("/")
  def hello():
      return "Hello World!\n"
  
  if __name__ == "__main__":
      app.run()
  </code></pre>
  
  <p>The myapp.cgi file:</p>
  
  <pre><code>#!/usr/bin/python  
  
  import os
  from wsgiref.handlers import CGIHandler
  from hello import app
  
  
  os.environ['SERVER_NAME'] = '127.0.0.1'
  os.environ['SERVER_PORT'] = '5000'
  os.environ['REQUEST_METHOD'] = 'GET'
  os.environ['PATH_INFO'] = ""
  
  CGIHandler().run(app)
  </code></pre>
  
  <p>Both the files are placed in the <code>/home/username/public_html/cgi-bin</code> directory</p>
  
  <p>The same <code>cgi-bin</code> has the directory named <code>myenv</code> - it's a <code>virtualenv</code> I have created. The <code>virtualenv</code> is active.</p>
  
  <p>Now,</p>
  
  <p>I navigate to the cgi-bin directory and run -</p>
  
  <pre><code> python hello.py
  </code></pre>
  
  <p>I get this : </p>
  
  <pre><code>* Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
  </code></pre>
  
  <p>So this is fine. Now I am running the myapp.cgi file:</p>
  
  <pre><code>python myapp.cgi
  </code></pre>
  
  <p>I get this :</p>
  
  <pre><code>Status: 301 MOVED PERMANENTLY
  Content-Type: text/html; charset=utf-8
  Content-Length: 251
  Location: http://127.0.0.1:5000/
  
  &lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"&gt;
  &lt;title&gt;Redirecting...&lt;/title&gt;
  &lt;h1&gt;Redirecting...&lt;/h1&gt;
  &lt;p&gt;You should be redirected automatically to target URL: &lt;a href="http://127.0.0.1:5000/"&gt;http://127.0.0.1:5000/&lt;/a&gt;.  If not click the link.
  </code></pre>
  
  <p>How can I make this status as 200 OK,
  Please suggest.</p>
  
  <p>Thanks!</p>