title: Raspberry Pi live video streaming with Flask App works with default development server but not in Apache production
body: <p>I've hosted a simple Flask App on Apache webserver on a Raspberry Pi to stream real-time video from the PiCamera using tutorial from <a href="https://blog.miguelgrinberg.com/post/video-streaming-with-flask" rel="nofollow noreferrer">https://blog.miguelgrinberg.com/post/video-streaming-with-flask</a> . Everything works fine locally for me and I can access my <a href="http://localip:5000" rel="nofollow noreferrer">http://localip:5000</a> to get my live video feed. I now wanted to host this on a production server and I used Apache. I set all the configuration files and directory structures linked my Flask app and set the server for port 80. I visit the <a href="http://ip:80" rel="nofollow noreferrer">http://ip:80</a> and my webpage loads with a title, heading and static text but the video that is supposed to be below it is now a picture of a "broken image". Inspecting the webpage video element on the browser shows that the server returned nothing.</p>
  
  <p>I saw another post <a href="https://stackoverflow.com/questions/40768567/video-straming-on-raspberrypi-using-flask-apche2and-wsgi-server">Video Straming on raspberrypi using flask apche2and wsgi server</a>, of a guy who ran into the same problem as mine. He marked an answer saying Apache wasn't having root access to the picamera and hence wasn't able to access it. I know that Apache runs as www-data group user and I don't know which folder/file I should give permissions so that it can access the PiCamera. I don't know how to go about from here.Locally using the inbuild flask dev web server everything is working perfectly but on serving through Apache the camera isn't capturing the images. Please help me. Here is my basic code and configurations (Flask app name is VideoStream):</p>
  
  <p><strong>VideoStream.wsgi</strong></p>
  
  <pre><code>#!/usr/bin/python3
  import sys
  import logging
  logging.basicConfig(stream=sys.stderr)
  sys.path.insert(0,"/var/www/VideoStream/")
  
  from VideoStream import app as application
  </code></pre>
  
  <p><strong>Apache Configuration file:</strong></p>
  
  <pre><code>&lt;VirtualHost *:80&gt;
                  ServerName 10.0.0.69
                  ServerAdmin realityreccode@gmail.com
                  WSGIScriptAlias / /var/www/VideoStream/VideoStream.wsgi
                  WSGIDaemonProcess VideoStream user=www-data group=www-data threads=5 home=/var/www/VideoStream/
          &lt;Directory /var/www/VideoStream/VideoStream/&gt;
                  WSGIProcessGroup VideoStream
                  WSGIApplicationGroup %{GLOBAL}
                  WSGIScriptReloading On
                  Order allow,deny
                  Allow from all
                  &lt;/Directory&gt;
                  ErrorLog ${APACHE_LOG_DIR}/VideoStream-error.log
                  LogLevel warn
                  CustomLog ${APACHE_LOG_DIR}/VideoStream-access.log combined 
  &lt;/VirtualHost&gt;
  </code></pre>
  
  <p><strong>Directory Structure:</strong></p>
  
  <pre><code>/var/www/VideoStream/
  VideoStream.wsgi
  VideoStream/
      __init__.py
      camera_pi.py
      base_camera.py
      templates/index.html
  </code></pre>
  
  <p><strong>__init__.py - Flask app :</strong></p>
  
  <pre><code>#!/usr/bin/python3
  from importlib import import_module
  import os
  from flask import Flask, render_template, Response
  from VideoStream.camera_pi import Camera
  
  
  app = Flask(__name__)
  
  
  @app.route('/')
  def index():
     return render_template('index.html')
  def gen(camera):
  
  while True:
      frame = camera.get_frame()
      yield (b'--frame\r\n'
             b'Content-Type: image/jpeg\r\n\r\n' + frame + b'\r\n')
  @app.route('/video_feed')
  def video_feed():
  
      return Response(gen(Camera()),
                  mimetype='multipart/x-mixed-replace; boundary=frame')
  
  
  if __name__ == '__main__':
      app.run(host='10.0.0.69', threaded=True, debug=True)
  </code></pre>