# Flask – Deployment

## Externally Visible Server

A Flask application on the development server is accessible only on the computer on which the development environment is set up. This is a default behavior, because in debugging mode, a user can execute arbitrary code on the computer.

If **debug** is disabled, the development server on local computer can be made available to the users on network by setting the host name as **‘0.0.0.0’**.

```
app.run(host = ’0.0.0.0’)
```

<div class="open_grepper_editor" id="bkmrk-" title="Edit & Save To Grepper">  
</div>Thereby, your operating system listens to all public IPs.

## Deployment

To switch over from a development environment to a full-fledged production environment, an application needs to be deployed on a real web server. Depending upon what you have, there are different options available to deploy a Flask web application.

For small application, you can consider deploying it on any of the following hosted platforms, all of which offer free plan for small application.

- Heroku
- dotcloud
- webfaction

Flask application can be deployed on these cloud platforms. In addition, it is possible to deploy Flask app on Google cloud platform. Localtunnel service allows you to share your application on localhost without messing with DNS and firewall settings.

If you are inclined to use a dedicated web server in place of above mentioned shared platforms, following options are there to explore.

## mod\_wsgi

**mod\_wsgi** is an Apache module that provides a WSGI compliant interface for hosting Python based web applications on Apache server.

## Installing mod\_wsgi

To install an official release direct from PyPi, you can run −

```
pip install mod_wsgi
```

<div class="open_grepper_editor" id="bkmrk--0" title="Edit & Save To Grepper">  
</div>To verify that the installation was successful, run the mod\_wsgi-express script with the start-server command −

```
mod_wsgi-express start-server
```

<div class="open_grepper_editor" id="bkmrk--1" title="Edit & Save To Grepper">  
</div>This will start up Apache/mod\_wsgi on port 8000. You can then verify that the installation worked by pointing your browser at −

```
http://localhost:8000/
```

<div class="open_grepper_editor" id="bkmrk--2" title="Edit & Save To Grepper">  
</div>## Creating .wsgi file

There should be a **yourapplication.wsgi** file. This file contains the code **mod\_wsgi,** which executes on startup to get the application object. For most applications, the following file should be sufficient −

```
from yourapplication import app as application
```

<div class="open_grepper_editor" id="bkmrk--3" title="Edit & Save To Grepper">  
</div>Make sure that **yourapplication** and all the libraries that are in use are on the python load path.

## Configuring Apache

You need to tell **mod\_wsgi,** the location of your application.

```
<VirtualHost *>
   ServerName example.com
   WSGIScriptAlias / C:\yourdir\yourapp.wsgi

   <Directory C:\yourdir>
      Order deny,allow
      Allow from all
   </Directory>

</VirtualHost>
```

<div class="open_grepper_editor" id="bkmrk--4" title="Edit & Save To Grepper">  
</div>## Standalone WSGI containers

There are many popular servers written in Python that contains WSGI applications and serve HTTP.

- Gunicorn
- Tornado
- Gevent
- Twisted Web