Python Deployment Basic

You can learn here how to deploy python app with apache http server, mod_wsgi and ubuntu.

Making your normal pc as a hosting pc

At this time you are learning. May be don’t want to spend money to buy hosting and mess it up. That’s why It’s time to think alternative. Change your pc as a hosting pc. Most of of the hosting providers gives you a virtual machine with os installed. We use same in our pc.

Virtual Machine

Virtual machine is a software that helps you to install different kinds of operating systems in your main os. Any modification in virtual machine has no impact on main os. We use Vagrant.

Vagrant

Before installing vagrant make sure you enabled virtualization in bios setting. I guess that your main os is ubuntu. So I give you the instruction for this os. For other os you can goole it.

Apache http server

Now we should install apache http server as it is so popular.

mod_wsgi

This is for python dependand web app.

You might get a warning “Could not reliably determine the server’s fully qualified domain name”. Visit https://askubuntu.com/questions/256013/apache-error-could-not-reliably-determine-the-servers-fully-qualified-domain-n to solve this.

WSGI Application

Most of the python web framework use WSGI. Like Flask and Django. But here we quickly test if everything goes fine. Earlier you have changed apache conf file. That’s why create /var/www/html/myapp.wsgi file and edit it like bellow;
`python def application(environ, start_response): status = ‘200 OK’ output = ‘Hello World!’

response_headers = [('Content-type', 'text/plain'), ('Content-Length', str(len(output)))]
start_response(status, response_headers)

return [output] `   Save it and recheck the link http://localhost:8080. Boom you can see a 'Hello World!' in your browser.