Be social

Can finally move on from php -- Deploying python Flask on Apache mod_wsgi

Alert! This ended well, posting this from a beach.


How spent my time one day

Wanted to test a Python app, For that, needed to make a web form and script to reliably send off an email. Simple enough. Pretty standard stuff.

Done it all before. Here is the bit that made the emails reliable.

So popped open the text editor geany and wrote the code in php. Cuz it's for the web and php is the bestest.

And the winner is?! Ah those were the days...
A police lineup? This is how software development is portrayed.

How would have liked to spend my time one day

Same Python app, Few years ago, there was less options when it came to which web programming languages were available. Since was testing a Python app, seems reasonable to not switch to another programming language. Sure implementing in PHP would be quicker, but the code is not exactly easy on the eyes.

Decided to go with python's flask framework. Flask touts itself as a micro webdevelopment framework. Which seems about the scale of a simple test script. So micro it is. After installing Flask and trying out a single file (Flask) test script was ready to deploy! Lets see this puppy in action. How exciting! So uploaded the .wsgi file and python module, static, and template folders. Oh almost forgot to tell Apache about the .wsgi file. Opps!

My web host
makes this bit much easier!

In their cpanel, under Virtual Hosts can do the equivalent of the WSGIScriptAlias command. Done! Creepy feeling down my spine, anticipation of saying goodbye to the days of php is overwhelming. Had to test this puppy out immediately. Open the browser and type in the URL and get 404 File not Found screen. What's going on?! Contact the web host and amongst many charming gems get this reply:

We have corrected the path to below in the myapp.wsgi file

sys.path.insert(0, '/home105/sub051/sc24938-RIHB/myapps')

However you will need to upload the flask framework as well as we do not have it pre-installed. 
so you need to upload the flask framework now. You may get it here

Oh yeah sure right! If only had shell access with root privileges. That isn't going to happen, so seems stuck with PHP afterall.

Anyone else experiencing similar hurdles with web hosts stuck in the days of LAMP?

Dave Faulkmore profile photo About Dave Faulkmore

Dave Faulkmore finds product testing work for foreign people living in Japan. Fetitch
Enjoys reading PHP manual comments to learn hacks to get code working. Sad Python relatively works with less fuss.