title: Apache webserver and Flask app
body: <p>I have apache2 web server running on Ubuntu 14.04.
  By default when I start apache web server on <code>http://localhost</code> I can see "Apache2 Ubuntu Default Page" which is launched from /var/www/html/index.html file.</p>
  
  <p>I have a flask app at /home/ubuntu/myprojects/ location. The flask app is running on virtualenv and have proper folder structure to render a html file.
  Below is the folder structure</p>
  
  <blockquote>
    <p>/home/ubuntu/myprojects/hello/hello.py (flask app rendering a html)
    /home/ubuntu/myprojects/hello/templates/hello.html</p>
  </blockquote>
  
  <p>The flask app code is as below:</p>
  
  <pre class="lang-py prettyprint-override"><code>from flask import Flask
  from flask import render_template
  from flask import request
  
  app = Flask(__name__)
  
  @app.route('/')
  def my_form():
          return render_template("hello.html")
  
  if __name__ == '__main__':
          app.debug = True
          app.run(host='0.0.0.0')
  </code></pre>
  
  <p>When I run <code>http://localhost:5000</code> the hello.html is rendered.
  I want to render hello.html from hello.py flask app when <code>http://localhost</code> is called without any port number specified.
  To do that I added below code:</p>
  
  <pre><code>app.run(host='0.0.0.0', port=80)
  </code></pre>
  
  <p>But then, when I run the flask app, is exists with error:</p>
  
  <pre><code> * Running on http://0.0.0.0:80/ (Press CTRL+C to quit)
  Traceback (most recent call last):
    File "hello.py", line 21, in &lt;module&gt;
      app.run(host='0.0.0.0', port=80)
    File "/home/ubuntu/myproject/venv/local/lib/python2.7/site-packages/flask/app.py", line 772, in run
      run_simple(host, port, self, **options)
    File "/home/ubuntu/myproject/venv/local/lib/python2.7/site-packages/werkzeug/serving.py", line 618, in run_simple
      test_socket.bind((hostname, port))
    File "/usr/lib/python2.7/socket.py", line 224, in meth
      return getattr(self._sock,name)(*args)
  socket.error: [Errno 13] Permission denied
  </code></pre>
  
  <p>I don't know what I am doing wrong. On <code>http://localhost</code>, the index.html from /var/www/html/ is getting rendering.</p>
  
  <hr>
  
  <p>In addition to above, when I used mod_wsgi I added below code
  Added application.wsgi</p>
  
  <pre class="lang-py prettyprint-override"><code>import os, sys, logging
  logging.basicConfig(stream=sys.stderr)
  
  PROJECT_DIR = '/home/ubuntu/myproject/hello'
  
  activate_this = os.path.join(PROJECT_DIR, 'bin', 'activate_this.py')
  execfile(activate_this, dict(__file__=activate_this))
  sys.path.append(PROJECT_DIR)
  
  from hello import app as application
  </code></pre>
  
  <p>In <code>/etc/apache2/sites-available/000-default.conf</code>, I added below:</p>
  
  <pre><code>&lt;VirtualHost *:80&gt;
          WSGIDaemonProcess FunRoute user=ubuntu group=root threads=5
          WSGIScriptAlias / /home/ubuntu/myproject/FunRoute/application.wsgi
  
          &lt;Directory /home/ubuntu/myproject/FunRoute/&gt;
                  WSGIProcessGroup FunRoute
                  WSGIApplicationGroup %{GLOBAL}
                  Order deny,allow
                  Allow from all
          &lt;/Directory&gt;
  &lt;/VirtualHost&gt;
  </code></pre>
  
  <p>Also I changed the hello.py back to :</p>
  
  <pre><code>app.run(host='0.0.0.0')
  </code></pre>
  
  <p>But then I received <code>403 Forbidden</code> error when I try to launch <a href="http://localhost" rel="noreferrer">http://localhost</a></p>
  
  <pre><code>Forbidden
  
  You don't have permission to access / on this server.
  
  Apache/2.4.7 (Ubuntu) Server at 52.8.217.39 Port 80
  </code></pre>