# Deploy and Access Flask App on Windows Server [No CGI]

Quite often you might find a need to deploy your flask application on a Windows Server manually. Though this might not really be a thing in the modern development space due to new technologies (e.g docker) that are revolutionising application development and deployment; mine was prompted by a peer need. We were working around having a consistent development version and don't want to spend extra bucks/resources setting up a CI/CD and the likes so we opted to put it on an existing VPS. 

I was saddled with the responsibility of setting this up, and that won't be much of a problem (at least I thought). Everything was going pretty well until I can't access the deployed application externally. All walkthrough I could find online require me to use FastCGI, but I was quite unlucky installing it.

![Screenshot 2021-11-23 at 20.35.42.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1637696247017/vMW-UgLqO.png)

Then I found another way around...

## Open port for TCP access
To allow HTTP traffic to your application's port, we need to open a static port in the Windows firewall for TCP access. There are many [ways this could be done](https://www.google.com/search?q=enable+port+on+windows+server&oq=enable+port+on+windows+server)  (e.g CMD, control panel etc) but I used the CMD. Simply run to open port 8001
```bash
netsh advfirewall firewall add rule name="TCP Port 8001" dir=in action=allow protocol=TCP localport=8001
```

In case you need to close the port, run the command below
```bash
netsh advfirewall firewall delete rule name="TCP Port 8001" protocol=TCP localport=8001
```

## Set Flask server host to 0.0.0.0
The default host used by Flask server is `127.0.0.1`, this make the server accessible only by the network serving Flask, i.e your local computer.
The last piece is to make the server publicly available; set the Flask host to `0.0.0.0`.
 
To change the port, simply run your Flask project using
```bash
flask run --host=0.0.0.0
```

## Access the application over the internet
Your application is now published and can be accessed outside your server.
Use your machine IP/domain name and port. e.g `http://192.168.28.20:8001`

Thanks for your time!


