Running Flask on CentOS

Notes on installing my flask app on CentOS

I developed a small flask application at work and put it on a server running CentOS which I ended up spending a few days struggling with getting it up and running. Hopefully this helps someone else avoid some of the pain I had. Jumping right in, the first thing I did was install flask, since CentOS 6.3 comes with python 2.6.6 it was easy to install pip-python and use that to get flask. Since the server was running Apache 2.2, I put my webapp in /var/www/html. Next step was to install httpd_devel and mod_wsgi both of which easily installed from source. Everything seemed fine but I kept getting an HTTP 500 error message, here is what I did:

There was a lot of editing of /etc/httpd/conf/httpd.conf to allow for vitrual hosts.
This was also the first time I had worked on a subdomain but my DNS had supposedly been setup correctly.

Is mod_wsgi in the right place?

Check that mod_wsgi.so is in /usr/lib/httpd/modules a

-rwxr-xr-x. 1 root root 315812 Sep 4 10:20 mod_wsgi.so

The . at the end of the permissions field is the SELinux (in this case CentOS) ACL.

Does the application have SE Linux permissions?

bash: semanage: comand not found

Since semanage is not found I am assume that we are running CentOS without any additional security.

Are we loading mod_wsgi correctly?

Add a line to httpd.conf

LoadModule wsgi_module modules/mod_wsgi.so

Is the socket file set up correctly?

Socket file not able to write to directory, set socket file to write to /tmp using WSGISocketPrefix to allow www-data worker process to connect.

Server still giving HTTP 500

This is where I started trying everything I could thinkof. I set LogLevel to debug and later set LogLevel to info and still could not figure out what was going on. I even asked on stack overflow with little luck.

Solved!

Basically, I was not explicit enough in my file path names which caused the majority of these headaches. I assumed that CentOS would be like Debian in how it parsed filepaths, however this was wrong and this caused more headaches than needed. Since this was a python application, you would think that I would recall from the Zen of Python that “Explicit is better than implicit” but in this case you would be wrong. remember the Zen of Python