{"id":14043,"date":"2023-01-06T08:39:08","date_gmt":"2023-01-06T08:39:08","guid":{"rendered":"http:\/\/localhost\/cloudpap\/?post_type=docs&#038;p=14043"},"modified":"2023-02-03T05:52:03","modified_gmt":"2023-02-03T05:52:03","password":"","slug":"deploy-a-flask-app-on-a-vps-using-ssh","status":"publish","type":"docs","link":"https:\/\/cloudpap.com\/blog\/docs\/deploy-a-flask-app-on-a-vps-using-ssh\/","title":{"rendered":"How to Deploy a Flask App on a VPS using SSH"},"content":{"rendered":"<p>This guide will help us deploy a flask application on a VPS via SSH. There are several ways to deploy python based apps but in this case, we will use Apache and Phusion Passenger \u2013 the same software used in shared hosting.<\/p>\n<h2 id=\"requirements\">Requirements<\/h2>\n<ul>\n<li>root access to the server<\/li>\n<li>Ubuntu 20.04 installed<\/li>\n<li>Minimum 512MB RAM, 10GB space<\/li>\n<li>a domain\/subdomain pointed to your VPS IP address<\/li>\n<\/ul>\n<p>The steps involved are as follows:<\/p>\n<p>1.Install needed software (Python3, Apache, Passenger and Git)<\/p>\n<p>2.Upload you website<\/p>\n<p>3.Setup server configuration<\/p>\n<p>Lets get started<\/p>\n<h2 id=\"install-needed-software\">Install needed software<\/h2>\n<p>The software needed are python3, Apache, Passenger and Git<\/p>\n<p>Uninstall Python 2<\/p>\n<pre class=\"wp-block-preformatted\">$ sudo apt remove python2<\/pre>\n<pre class=\"wp-block-preformatted\">$ sudo apt remove python-is-python2<\/pre>\n<pre class=\"wp-block-preformatted\">$ sudo apt autoremove --purge<\/pre>\n<p>Install Python 3<\/p>\n<pre class=\"wp-block-preformatted\">$ sudo apt-get update<\/pre>\n<pre class=\"wp-block-preformatted\">$ sudo apt-get install -y python3 python3-pip<\/pre>\n<p>Install Apache<\/p>\n<pre class=\"wp-block-preformatted\">$ sudo apt-get install apache2<\/pre>\n<p>Install Passenger and needed Apache modules<\/p>\n<pre class=\"wp-block-preformatted\">$ sudo apt-get install -y dirmngr gnupg\r\n$ sudo apt-key adv --keyserver hkp:\/\/keyserver.ubuntu.com:80 --recv-keys 561F9B9CAC40B2F7\r\n$ sudo apt-get install -y apt-transport-https ca-certificates\r\n$ sudo apt-get install -y libapache2-mod-passenger\r\n$ sudo a2enmod passenger\r\n$ systemctl restart apache2<\/pre>\n<p>Install Git<\/p>\n<pre class=\"wp-block-preformatted\">$ sudo apt-get install -y git<\/pre>\n<h2 id=\"upload-your-website\">Upload your website<\/h2>\n<p>We will use git to upload our website. To do this, you need to have your website already available in a repo such as Github or Gitlab.<\/p>\n<p>Create a user for your app. We will call our user\u00a0<strong>appuser<\/strong><\/p>\n<pre class=\"wp-block-preformatted\">$ useradd appuser<\/pre>\n<pre class=\"wp-block-preformatted\">$ passwd appuser<\/pre>\n<p>Create your application directory<\/p>\n<pre class=\"wp-block-preformatted\">$ sudo mkdir -p  \/var\/www\/awesomeapp<\/pre>\n<pre class=\"wp-block-preformatted\">$ sudo chown appuser:  \/var\/www\/awesomeapp<\/pre>\n<p>Clone your app<\/p>\n<pre class=\"wp-block-preformatted\">$ cd \/var\/www\/awesomeapp &amp;&amp; sudo -u appuser -H git clone https:\/\/gitlab.com\/username\/awesomeapp.git<\/pre>\n<p><strong>Note<\/strong>: If you do not have an app in a repo such as Github or Gitlab already, please manually upload your app files to<code>\/var\/www\/awesomeapp<\/code><\/p>\n<h2 id=\"setup-server-configuration\">Setup server configuration<\/h2>\n<p>The next thing is to complete the set up of our app. This means we install the application requirements and configure Apache<\/p>\n<p>Install app requirements<\/p>\n<p>Your app should have a requirements.txt file. Run the command below to install required files<\/p>\n<pre class=\"wp-block-preformatted\">$ pip3 install -r requirements.txt<\/pre>\n<p>Create an Apache VHOST file using the following command. We\u2019ll assume your domain is called truehosttestdomain.com<\/p>\n<pre class=\"wp-block-preformatted\">$ sudo vim \/etc\/apache2\/sites-enabled\/awesomeapp.conf<\/pre>\n<p>Copy the content below<\/p>\n<pre class=\"wp-block-code\"><code>&lt;VirtualHost *:80&gt;\r\n    ServerAdmin webmaster@truehosttestdomain.com\r\n    ServerName truehosttestdomain.com\r\n    ServerAlias truehosttestdomain.com\r\n \r\n    # Tell Apache and Passenger where your app's code directory is\r\n    DocumentRoot \/var\/www\/awesomeapp\/code\/\r\n    PassengerAppRoot \/var\/www\/awesomeapp\/code\r\n \r\n    # Tell Passenger that your app is a Python app\r\n    PassengerAppType wsgi\r\n    PassengerStartupFile passenger_wsgi.py\r\n \r\n    ErrorLog \/var\/www\/truehosttestdomain.com\/logs\/error.log\r\n    CustomLog \/var\/www\/truehosttestdomain.com\/logs\/access.log combined\r\n \r\n    Alias \/static\/ \/var\/www\/awesomeapp\/static\r\n    &lt;Directory \/var\/www\/awesomeapp\/static&gt;\r\n        Order allow,deny\r\n        Allow from all\r\n    &lt;\/Directory&gt;\r\n \r\n&lt;\/VirtualHost&gt;\r\n<\/code><\/pre>\n<p>Restart apache and check your domain online!<\/p>\n<pre class=\"wp-block-preformatted\">$ systemctl restart apache2<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>This guide will help us deploy a flask application on a VPS via SSH. There are several ways to deploy python based apps but in this case, we will use Apache and Phusion Passenger \u2013 the same software used in shared hosting. Requirements root access to the server Ubuntu 20.04 installed Minimum 512MB RAM, 10GB&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"_kad_post_transparent":"","_kad_post_title":"","_kad_post_layout":"","_kad_post_sidebar_id":"","_kad_post_content_style":"","_kad_post_vertical_padding":"","_kad_post_feature":"","_kad_post_feature_position":"","_kad_post_header":false,"_kad_post_footer":false,"footnotes":""},"doc_category":[128],"doc_tag":[],"class_list":["post-14043","docs","type-docs","status-publish","hentry","doc_category-vps"],"year_month":"2026-04","word_count":470,"total_views":0,"reactions":{"happy":0,"normal":0,"sad":0},"author_info":{"name":"Cloud Pap","author_nicename":"cloudpapadmin2023","author_url":"https:\/\/cloudpap.com\/blog\/author\/cloudpapadmin2023\/"},"doc_category_info":[{"term_name":"VPS","term_url":"https:\/\/cloudpap.com\/blog\/docs-category\/vps\/"}],"doc_tag_info":[],"_links":{"self":[{"href":"https:\/\/cloudpap.com\/blog\/wp-json\/wp\/v2\/docs\/14043","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/cloudpap.com\/blog\/wp-json\/wp\/v2\/docs"}],"about":[{"href":"https:\/\/cloudpap.com\/blog\/wp-json\/wp\/v2\/types\/docs"}],"author":[{"embeddable":true,"href":"https:\/\/cloudpap.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/cloudpap.com\/blog\/wp-json\/wp\/v2\/comments?post=14043"}],"version-history":[{"count":0,"href":"https:\/\/cloudpap.com\/blog\/wp-json\/wp\/v2\/docs\/14043\/revisions"}],"wp:attachment":[{"href":"https:\/\/cloudpap.com\/blog\/wp-json\/wp\/v2\/media?parent=14043"}],"wp:term":[{"taxonomy":"doc_category","embeddable":true,"href":"https:\/\/cloudpap.com\/blog\/wp-json\/wp\/v2\/doc_category?post=14043"},{"taxonomy":"doc_tag","embeddable":true,"href":"https:\/\/cloudpap.com\/blog\/wp-json\/wp\/v2\/doc_tag?post=14043"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}