# Hosting Python Flask Applications as a service on Ubuntu Linux Server

Let us explore how to run Python Flask application as a Linux Service.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1703051601163/161f6ceb-b3f0-4e22-82c6-ed613aa3eec8.gif align="left")

Let’s follow the below steps :

1. In order to deploy a service on Ubuntu server we need to create a file (name of the service : riiva) :
    

`sudo nano /etc/system/system/riiva.service`

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1703051602847/4526d081-948b-4cf6-9a48-045e638ca64a.png align="left")

2\. Now, use the following caption :

`[Unit] section:`

`Description=uWSGI instance to serve myproject`

`After=network.target`

`[Service]`

`User=ubuntu`

`Group=www-data`

`WorkingDirectory=/home/ubuntu/riva-stremingserver/`

`Environment=”PATH=/home/ubuntu/stream/bin”`

`ExecStart= gunicorn — bind 0.0.0.0:9501 -k flask_sockets.worker app:app`

`[Install]`

`WantedBy=multi-user.target`

`service file`

3\. Here the following terms included :

* **User:-** The user is defined as the current user.
    
* **Group:**\- the user is in which group of linux.
    
* **WorkingDirectory:**\- It refers to the directory which you want to be worked on.
    
* **Environment:**\- It the takes the path of env where it can be run.
    
* **ExecStart:**\- It refers to the command which you want to execute.
    

4\. After this, to start this service we have a command:

`-> sudo systemctl start riiva`

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1703051604153/e47b6432-2349-4cbe-89a7-6ff3f06ffc7e.png align="left")

5\. In order to see the status of logs of this service, we have a command:

`sudo systemctl status riiva`

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1703051605435/c6070a21-60a6-4f7c-8677-1d148b4193fc.png align="left")

6\. Now to restart the service, we have a command:

`sudo systemctl restart riiva`

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1703051606495/66e3c564-52c6-4474-899c-8faed0779c4d.png align="left")

Your application is hosted upon [HTTP://IP-ADDRESS:](http://HTTP://IP-ADDRESS:)9501

7\. Finally, to end this service, we have a command:

`sudo systemctl stop riiva`

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1703051607767/45cd6ac7-3cfb-4469-878f-403175c43a68.png align="left")

**Congratulations,** You are done with the hosting.

![](https://cdn-images-1.medium.com/max/800/0*6N0kv58urh5WYtan align="left")

**For any further queries or anything related to Python Development, Coding, Blogging, Tech Documentation you can DM me on** [**Linkedin**](https://in.linkedin.com/in/anubhav-chaturvedi-a7465a72) **or instagram at id=**[**acanubhav94**](http://instagram.com/acanubhav94)**.**
