{"id":14037,"date":"2023-01-06T08:36:23","date_gmt":"2023-01-06T08:36:23","guid":{"rendered":"http:\/\/localhost\/cloudpap\/?post_type=docs&#038;p=14037"},"modified":"2023-02-03T05:50:11","modified_gmt":"2023-02-03T05:50:11","password":"","slug":"deploy-a-flask-app-in-cpanel","status":"publish","type":"docs","link":"https:\/\/cloudpap.com\/blog\/docs\/deploy-a-flask-app-in-cpanel\/","title":{"rendered":"How to deploy a Flask App in cPanel"},"content":{"rendered":"<p>Each hosting package in CloudPap\u00a0allows hosting of Python Applications. Flask and Django top the Python frameworks people prefer. In this guide we will learn how to deploy a Flask Application in cPanel.<\/p>\n<h2 id=\"prerequisites\"><strong>Prerequisites<\/strong><\/h2>\n<p>-Flask App already created on your computer using Python 3<\/p>\n<p>-Flask App has a requirements.txt file ready. This can be created on your localhost by running the command below in the directory where your flask files reside:<\/p>\n<p>$ pip3 freeze &gt;&gt; requirements.txt<\/p>\n<h2 id=\"a-create-a-python-app-in-cpanel\">A.\u00a0<strong>Create a Python App in cPanel<\/strong><\/h2>\n<p>1.\u00a0<strong>Login<\/strong>\u00a0to cPanel<\/p>\n<p>2. Navigate to\u00a0<strong>Setup Python App<\/strong>\u00a0icon and click it.<\/p>\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-6137\" src=\"https:\/\/truehost.co.ke\/support\/wp-content\/uploads\/2020\/11\/How-to-deploy-a-Flask-App-in-cPanel1.png\" sizes=\"auto, (max-width: 922px) 100vw, 922px\" srcset=\"https:\/\/truehost.com\/support\/wp-content\/uploads\/2020\/11\/How-to-deploy-a-Flask-App-in-cPanel1.png 922w, https:\/\/truehost.com\/support\/wp-content\/uploads\/2020\/11\/How-to-deploy-a-Flask-App-in-cPanel1-300x117.png 300w, https:\/\/truehost.com\/support\/wp-content\/uploads\/2020\/11\/How-to-deploy-a-Flask-App-in-cPanel1-768x300.png 768w, https:\/\/truehost.com\/support\/wp-content\/uploads\/2020\/11\/How-to-deploy-a-Flask-App-in-cPanel1-50x20.png 50w, https:\/\/truehost.com\/support\/wp-content\/uploads\/2020\/11\/How-to-deploy-a-Flask-App-in-cPanel1-920x359.png 920w, https:\/\/truehost.com\/support\/wp-content\/uploads\/2020\/11\/How-to-deploy-a-Flask-App-in-cPanel1-600x234.png 600w, https:\/\/truehost.com\/support\/wp-content\/uploads\/2020\/11\/How-to-deploy-a-Flask-App-in-cPanel1-320x125.png 320w\" alt=\"\" width=\"922\" height=\"360\" title=\"\"><\/figure>\n<p>3. Click\u00a0<strong>Create Application<\/strong><\/p>\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-6138\" src=\"https:\/\/truehost.co.ke\/support\/wp-content\/uploads\/2020\/11\/How-to-deploy-a-Flask-App-in-cPanel2-1024x292.png\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" srcset=\"https:\/\/truehost.com\/support\/wp-content\/uploads\/2020\/11\/How-to-deploy-a-Flask-App-in-cPanel2-1024x292.png 1024w, https:\/\/truehost.com\/support\/wp-content\/uploads\/2020\/11\/How-to-deploy-a-Flask-App-in-cPanel2-300x85.png 300w, https:\/\/truehost.com\/support\/wp-content\/uploads\/2020\/11\/How-to-deploy-a-Flask-App-in-cPanel2-768x219.png 768w, https:\/\/truehost.com\/support\/wp-content\/uploads\/2020\/11\/How-to-deploy-a-Flask-App-in-cPanel2-50x14.png 50w, https:\/\/truehost.com\/support\/wp-content\/uploads\/2020\/11\/How-to-deploy-a-Flask-App-in-cPanel2-920x262.png 920w, https:\/\/truehost.com\/support\/wp-content\/uploads\/2020\/11\/How-to-deploy-a-Flask-App-in-cPanel2-600x171.png 600w, https:\/\/truehost.com\/support\/wp-content\/uploads\/2020\/11\/How-to-deploy-a-Flask-App-in-cPanel2-320x91.png 320w, https:\/\/truehost.com\/support\/wp-content\/uploads\/2020\/11\/How-to-deploy-a-Flask-App-in-cPanel2.png 1267w\" alt=\"\" width=\"1024\" height=\"292\" title=\"\"><\/figure>\n<p>4. Fill in the form as follows then click<strong>\u00a0Create<\/strong><\/p>\n<p><strong>Python version\u00a0<\/strong>\u2013 Select the Python version you need. We will use Python 3.8. If unsure, use the latest Python3 available.<\/p>\n<p><strong>Application root<\/strong>\u00a0\u2013 This is the folder where you will put your website files e.g static and template folders etc<\/p>\n<p><strong>Application URL<\/strong>\u00a0\u2013 This is the link people will use to access your application eg truehost.co.ke, truehost.co.ke\/blog, portal.truehost.co.ke etc.<\/p>\n<p><strong>Application startup file\u00a0<\/strong>\u2013 This is the file that should be run to load your application eg app.py, main.py etc<\/p>\n<p><strong>Application Entry point<\/strong>\u00a0\u2013 This is the function that should be run to display your site. Its contained in your startup file under route(\u201c\/\u201d)<\/p>\n<p><strong>Passenger log file<\/strong>\u00a0\u2013 This is the file where errors will be logged. Helps with debugging and fixing errors<\/p>\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-6139\" src=\"https:\/\/truehost.co.ke\/support\/wp-content\/uploads\/2020\/11\/How-to-deploy-a-Flask-App-in-cPanel4-1024x500.png\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" srcset=\"https:\/\/truehost.com\/support\/wp-content\/uploads\/2020\/11\/How-to-deploy-a-Flask-App-in-cPanel4-1024x500.png 1024w, https:\/\/truehost.com\/support\/wp-content\/uploads\/2020\/11\/How-to-deploy-a-Flask-App-in-cPanel4-300x147.png 300w, https:\/\/truehost.com\/support\/wp-content\/uploads\/2020\/11\/How-to-deploy-a-Flask-App-in-cPanel4-768x375.png 768w, https:\/\/truehost.com\/support\/wp-content\/uploads\/2020\/11\/How-to-deploy-a-Flask-App-in-cPanel4-50x24.png 50w, https:\/\/truehost.com\/support\/wp-content\/uploads\/2020\/11\/How-to-deploy-a-Flask-App-in-cPanel4-920x449.png 920w, https:\/\/truehost.com\/support\/wp-content\/uploads\/2020\/11\/How-to-deploy-a-Flask-App-in-cPanel4-600x293.png 600w, https:\/\/truehost.com\/support\/wp-content\/uploads\/2020\/11\/How-to-deploy-a-Flask-App-in-cPanel4-320x156.png 320w, https:\/\/truehost.com\/support\/wp-content\/uploads\/2020\/11\/How-to-deploy-a-Flask-App-in-cPanel4.png 1306w\" alt=\"\" width=\"1024\" height=\"500\" title=\"\"><\/figure>\n<p>5<strong>. Stop the Application.<\/strong>\u00a0You will restart it after upload files.<\/p>\n<h2 id=\"b-upload-your-application-files\">B.\u00a0<strong>Upload your application files<\/strong><\/h2>\n<p>Once you create an application as described above, a\u00a0<em><strong>virtualenv<\/strong><\/em>\u00a0will be created. A folder called\u00a0<strong>appfiles<\/strong>\u00a0will be created as well under\u00a0<strong>File Manager.<\/strong><\/p>\n<p>1. In cPanel, go to\u00a0<strong>File Manager<\/strong><\/p>\n<p>2. Access\u00a0<strong>appfiles<\/strong>\u00a0folder<\/p>\n<p>3. On your computer and create a zip file containing your template folder, static folder, requirements.txt and python files.<\/p>\n<p>4. Click\u00a0<strong>Upload<\/strong>\u00a0under\u00a0<strong>appfiles<\/strong>\u00a0folder and upload your zip files.<\/p>\n<p>5. Once uploaded, extract the files<\/p>\n<h2 id=\"c-update-main-py-and-passenger_wsgi-py-files\">C.\u00a0<strong>Update\u00a0<\/strong><em><strong>main.py<\/strong><\/em><strong>\u00a0and\u00a0<\/strong><em><strong>passenger_wsgi.py\u00a0<\/strong><\/em><strong>files<\/strong><\/h2>\n<p>1. Open the main.py file and add the line below under app = Flask(__name__) line<\/p>\n<p><em><strong>application = app<\/strong><\/em><\/p>\n<p>2. Open the passenger_wsgi.py and delete the content in it then add the line below and\u00a0<strong>Save<\/strong><\/p>\n<p><strong><em>from main import application<\/em><\/strong><\/p>\n<h2 id=\"d-import-modules-in-requirements-txt-file\"><strong>D. Import modules in requirements.txt file<\/strong><\/h2>\n<p>1. In cPanel, got to\u00a0<strong>Setup Py<\/strong><strong>t<\/strong><strong>hon App<\/strong>.<\/p>\n<p>2. Under\u00a0<strong>Configuration files<\/strong>, type in requirements.txt and click\u00a0<strong>Add<\/strong><\/p>\n<p>3. Click\u00a0<strong>Run Pip Install<\/strong><\/p>\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-6140\" src=\"https:\/\/truehost.co.ke\/support\/wp-content\/uploads\/2020\/11\/How-to-deploy-a-Flask-App-in-cPanel3-1024x267.png\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" srcset=\"https:\/\/truehost.com\/support\/wp-content\/uploads\/2020\/11\/How-to-deploy-a-Flask-App-in-cPanel3-1024x267.png 1024w, https:\/\/truehost.com\/support\/wp-content\/uploads\/2020\/11\/How-to-deploy-a-Flask-App-in-cPanel3-300x78.png 300w, https:\/\/truehost.com\/support\/wp-content\/uploads\/2020\/11\/How-to-deploy-a-Flask-App-in-cPanel3-768x201.png 768w, https:\/\/truehost.com\/support\/wp-content\/uploads\/2020\/11\/How-to-deploy-a-Flask-App-in-cPanel3-50x13.png 50w, https:\/\/truehost.com\/support\/wp-content\/uploads\/2020\/11\/How-to-deploy-a-Flask-App-in-cPanel3-920x240.png 920w, https:\/\/truehost.com\/support\/wp-content\/uploads\/2020\/11\/How-to-deploy-a-Flask-App-in-cPanel3-600x157.png 600w, https:\/\/truehost.com\/support\/wp-content\/uploads\/2020\/11\/How-to-deploy-a-Flask-App-in-cPanel3-320x84.png 320w, https:\/\/truehost.com\/support\/wp-content\/uploads\/2020\/11\/How-to-deploy-a-Flask-App-in-cPanel3.png 1229w\" alt=\"\" width=\"1024\" height=\"267\" title=\"\"><\/figure>\n<p>4. Once the modules are installed, you can\u00a0<strong>Start the Application<\/strong><\/p>\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-6141\" src=\"https:\/\/truehost.co.ke\/support\/wp-content\/uploads\/2020\/11\/How-to-deploy-a-Flask-App-in-cPanel5-1024x264.png\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" srcset=\"https:\/\/truehost.com\/support\/wp-content\/uploads\/2020\/11\/How-to-deploy-a-Flask-App-in-cPanel5-1024x264.png 1024w, https:\/\/truehost.com\/support\/wp-content\/uploads\/2020\/11\/How-to-deploy-a-Flask-App-in-cPanel5-300x77.png 300w, https:\/\/truehost.com\/support\/wp-content\/uploads\/2020\/11\/How-to-deploy-a-Flask-App-in-cPanel5-768x198.png 768w, https:\/\/truehost.com\/support\/wp-content\/uploads\/2020\/11\/How-to-deploy-a-Flask-App-in-cPanel5-50x13.png 50w, https:\/\/truehost.com\/support\/wp-content\/uploads\/2020\/11\/How-to-deploy-a-Flask-App-in-cPanel5-920x237.png 920w, https:\/\/truehost.com\/support\/wp-content\/uploads\/2020\/11\/How-to-deploy-a-Flask-App-in-cPanel5-600x155.png 600w, https:\/\/truehost.com\/support\/wp-content\/uploads\/2020\/11\/How-to-deploy-a-Flask-App-in-cPanel5-320x83.png 320w, https:\/\/truehost.com\/support\/wp-content\/uploads\/2020\/11\/How-to-deploy-a-Flask-App-in-cPanel5.png 1252w\" alt=\"\" width=\"1024\" height=\"264\" title=\"\"><\/figure>\n<p>Hurray! Your app is now live.<\/p>\n<h2 id=\"troubleshooting\">Troubleshooting<\/h2>\n<ol>\n<li>We\u2019re sorry, but something went wrong.<br \/>\nYou may see the page below when trying to run your application<\/li>\n<\/ol>\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-6142\" src=\"https:\/\/truehost.co.ke\/support\/wp-content\/uploads\/2020\/11\/How-to-deploy-a-Flask-App-in-cPanel-Were-sorry-but-something-went-wrong-Web-application-could-not-be-started-1024x496.png\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" srcset=\"https:\/\/truehost.com\/support\/wp-content\/uploads\/2020\/11\/How-to-deploy-a-Flask-App-in-cPanel-Were-sorry-but-something-went-wrong-Web-application-could-not-be-started-1024x496.png 1024w, https:\/\/truehost.com\/support\/wp-content\/uploads\/2020\/11\/How-to-deploy-a-Flask-App-in-cPanel-Were-sorry-but-something-went-wrong-Web-application-could-not-be-started-300x145.png 300w, https:\/\/truehost.com\/support\/wp-content\/uploads\/2020\/11\/How-to-deploy-a-Flask-App-in-cPanel-Were-sorry-but-something-went-wrong-Web-application-could-not-be-started-768x372.png 768w, https:\/\/truehost.com\/support\/wp-content\/uploads\/2020\/11\/How-to-deploy-a-Flask-App-in-cPanel-Were-sorry-but-something-went-wrong-Web-application-could-not-be-started-50x24.png 50w, https:\/\/truehost.com\/support\/wp-content\/uploads\/2020\/11\/How-to-deploy-a-Flask-App-in-cPanel-Were-sorry-but-something-went-wrong-Web-application-could-not-be-started-920x445.png 920w, https:\/\/truehost.com\/support\/wp-content\/uploads\/2020\/11\/How-to-deploy-a-Flask-App-in-cPanel-Were-sorry-but-something-went-wrong-Web-application-could-not-be-started-600x290.png 600w, https:\/\/truehost.com\/support\/wp-content\/uploads\/2020\/11\/How-to-deploy-a-Flask-App-in-cPanel-Were-sorry-but-something-went-wrong-Web-application-could-not-be-started-320x155.png 320w, https:\/\/truehost.com\/support\/wp-content\/uploads\/2020\/11\/How-to-deploy-a-Flask-App-in-cPanel-Were-sorry-but-something-went-wrong-Web-application-could-not-be-started.png 1318w\" alt=\"\" width=\"1024\" height=\"496\" title=\"\"><\/figure>\n<p>In cPanel, python, ruby and nodejs applications run via Phusion Passenger. The page above indicates you app run into an error and could not be loaded, but it does not show the exact error message as the app is in production. Your app users don\u2019t need to see the python error.<\/p>\n<p>As such, to fix, you need to check the Apache logs (Check Errors icon under Metrics) and passenger log file you configured while creating the application in Step A above. Some of the causes of the error above and their solutions are:<\/p>\n<figure class=\"wp-block-table\">\n<table>\n<tbody>\n<tr>\n<td><strong>Issue<\/strong><\/td>\n<td><strong>Solution<\/strong><\/td>\n<\/tr>\n<tr>\n<td>Incorrect file\/folder permissions<\/td>\n<td>All files should be 0644 and folders 0755 permissions<\/td>\n<\/tr>\n<tr>\n<td>Mod Security in cPanel<\/td>\n<td><a href=\"https:\/\/truehost.co.ke\/support\/knowledge-base\/turn-mod-security-off\/\" target=\"_blank\" rel=\"noopener\">Turn off Mod Security in cPanel<\/a><\/td>\n<\/tr>\n<tr>\n<td>Incorrect database configuration<\/td>\n<td>If your site runs on a database, supply the correct connection details<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/figure>\n<p>2. Incomplete response received from application<\/p>\n<p>One cause of this error is that, your passenger_wsgi.py file was over writen on restarting the application. Hence the content we put in there was removed. The solution is just to paste back the line below then restart the app.<\/p>\n<p>from main import application<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Each hosting package in CloudPap\u00a0allows hosting of Python Applications. Flask and Django top the Python frameworks people prefer. In this guide we will learn how to deploy a Flask Application in cPanel. Prerequisites -Flask App already created on your computer using Python 3 -Flask App has a requirements.txt file ready. This can be created on&#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":[129],"doc_tag":[],"class_list":["post-14037","docs","type-docs","status-publish","hentry","doc_category-hosting"],"year_month":"2026-04","word_count":613,"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":"Hosting","term_url":"https:\/\/cloudpap.com\/blog\/docs-category\/hosting\/"}],"doc_tag_info":[],"_links":{"self":[{"href":"https:\/\/cloudpap.com\/blog\/wp-json\/wp\/v2\/docs\/14037","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=14037"}],"version-history":[{"count":0,"href":"https:\/\/cloudpap.com\/blog\/wp-json\/wp\/v2\/docs\/14037\/revisions"}],"wp:attachment":[{"href":"https:\/\/cloudpap.com\/blog\/wp-json\/wp\/v2\/media?parent=14037"}],"wp:term":[{"taxonomy":"doc_category","embeddable":true,"href":"https:\/\/cloudpap.com\/blog\/wp-json\/wp\/v2\/doc_category?post=14037"},{"taxonomy":"doc_tag","embeddable":true,"href":"https:\/\/cloudpap.com\/blog\/wp-json\/wp\/v2\/doc_tag?post=14037"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}