Python Flask debug logger causes 500 server error in production (Apache) Python Flask debug logger causes 500 server error in production (Apache) flask flask

Python Flask debug logger causes 500 server error in production (Apache)


What's most likely happening is that you are running your web server on development with user X, and this user has write permissions to the directory your Flask app is stored in - therefore it can write to application.log.

I noticed from the tutorial you posted that all directores were created using sudo and therefore your directory permissions are owned by the root user, while your Flask application is running as a different user that doesn't have permission to write to a directory owned by root.

There are two potential fixes:

Change the permissions of the directory where your Flask app is installed to be the same:

$ sudo chown -R www-data:www-data /var/www/FlaskApp

OR

Change where you write your log file (preferred method):

$ sudo mkdir /var/log/flaskapp$ sudo chown -R www-data:www-data /var/log/flaskapp

and then change code to:

app.config['LOG_FILE'] = '/var/log/flaskapp/application.log'