{"id":5663,"date":"2019-10-07T10:07:22","date_gmt":"2019-10-07T10:07:22","guid":{"rendered":"https:\/\/www.icdsoft.com\/blog\/?p=5663"},"modified":"2020-09-03T05:28:17","modified_gmt":"2020-09-03T05:28:17","slug":"running-python-3-6-with-a-simple-web-server-on-a-webapps-account","status":"publish","type":"post","link":"https:\/\/www.icdsoft.com\/blog\/running-python-3-6-with-a-simple-web-server-on-a-webapps-account\/","title":{"rendered":"Running Python 3.6 with a Simple Web Server on a WebApps Account"},"content":{"rendered":"\n<p>In this post, we will provide a tutorial on how to install Python 3.6 with a simple web server on a <a href=\"https:\/\/www.icdsoft.com\/en\/hosting\/webapps\" target=\"_blank\" rel=\"noreferrer noopener\" aria-label=\"WebApps hosting account (opens in a new tab)\">WebApps hosting account<\/a>. <\/p>\n\n\n\n<p>Our WebApps platform is designed to support all features of our shared hosting plans. On top of that, it also allows users to deploy projects using custom runtime environments such as Node.js. On a single WebApps account, you can have:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Standard PHP\/Perl applications like WordPress, for example.<\/li><li>Node.js with out-of-the-box support.<\/li><li>Custom environments such as Django, Ruby.<\/li><li>MongoDB instances.<\/li><li>Full support of ICDSoft's email features, including spam protection and Webmail software.<\/li><\/ul>\n\n\n\n<p><strong>All the above is combined within a single hosting account on the WebApps platform.<\/strong><\/p>\n\n\n\n<p>Background processes are usually forbidden on shared hosting platforms, but the power of the WebApps platform comes from this exact feature. <strong>You can run background processes (daemons) on the WebApps platform<\/strong>. In effect, this means that you can run almost any type of software that runs on Debian Linux. <\/p>\n\n\n\n<p>Of course, the platform has its specifics; you can find installation instructions for a simple \"Hello World\" Node.js app, Django, MongoDB, and Ruby on Rails in our knowledge base:  <a href=\"https:\/\/www.icdsoft.com\/en\/kb\/webapps_node_js\">https:\/\/www.icdsoft.com\/en\/kb\/webapps_node_js<\/a> <\/p>\n\n\n\n<p>The essence of the WebApps platform is to provide a supervisor process handling the network connections to the background service, and monitoring the background process itself. You can configure the supervisor to do a proxy redirection from a URL on your site to the port where your service is running. <\/p>\n\n\n\n<p>In the following tutorial, we will provide instructions on how to install Python 3.6 (a package that doesn't come standard with the current Debian version on our servers), start a simple web server, and run this web server through a WebApps project. <\/p>\n\n\n\n<p>Before proceeding, you need to enable SSH access for your account. You can do that through the \"SSH Access\" section of the hosting Control Panel. <\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Step 1 - Install Python 3.6<\/h4>\n\n\n\n<p>First, we will install Python 3.6. Log in through SSH to your hosting account, and run the following commands:\n<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">cd ~\/private                     # the private\/ folder isn't web accessible\nmkdir python-temp python36       # create a temporary directory\npip install --user virtualenv    # use the pip package manager to install the \"virtualenv\" package\ncd python-temp\nwget https:\/\/www.python.org\/ftp\/python\/3.6.9\/Python-3.6.9.tgz   # download python 3.6\ntar -xf Python-3.6.9.tgz                                        # extract the archive\ncd Python-3.6.9\n.\/configure --prefix=\"$HOME\/private\/python36\"          # configure &amp; compile Python 3.6 \nmake -j 8\nmake install\ncd ~\/private\nrm -rf python-temp\/                                     # remove the temporary dir and files<\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Step 2 - Create sample pages on the server<\/h4>\n\n\n\n<p>At this point, you have Python 3.6.9 installed. Now, we will test python and create some sample pages: <\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">~\/.local\/bin\/virtualenv myPyApp1 --python ~\/private\/python36\/bin\/python3\n\n. myPyApp1\/bin\/activate\npython --version                      # verify that we are running the correct version - \"3.6.9\"    \n\ncd myPyApp1\nmkdir html\ncd html\necho \"Page1\" &gt; page1.html             # create sample pages\necho \"Page2\" &gt; page2.html             <\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Step 3 - Create a WebApps project to manage our server<\/h4>\n\n\n\n<p>Now, we will create a WebApps project that will manage your web server - it will start the web server automatically if it crashes, and will allow access via your domain name to this web server. <\/p>\n\n\n\n<p>You can create your WebApps project either through the WebApps section of the hosting Control Panel, or through the command line. <\/p>\n\n\n\n<p>To do it via the command line, use the following command:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">sureapp project create --engine custom --engine-version - --release-dir ~\/private\/myPyApp1 --subdomain www --domain your_domain.com --url-path \/ --start-cmd ~\/private\/myPyApp1\/webapps-start pytest<\/pre>\n\n\n\n<p>In this command, the project is set to run in your main domain (www.your_domain.com). If you want to run the web server at another location, you can create a subdomain through the Subdomains section of your hosting Control Panel (eg. python.your_domain.com) and create the project with \"--subdomain python\" instead of \"--subdomain www\". <\/p>\n\n\n\n<p>You can also enable a free Let's Encrypt certificate for your domain\/subdomain, so that you have the web server running over https:\/\/ as well. <\/p>\n\n\n\n<p>Run the following command to list your applications. Take note of the port assigned to the pytest application:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">sureapp project list<\/pre>\n\n\n\n<p>Start the web server for a test with the port from the previous command. We use port 31602 as an example: <\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">python -m http.server 31602<\/pre>\n\n\n\n<p>Now open http:\/\/www.your_domain.com\/ with your browser, and you should be able to see your test pages. Stop the server with CTRL+C. Run: <\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">exit  #exit \"virtualenv\"<\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Step 4 - Making an executable for the WebApps supervisor<\/h4>\n\n\n\n<p>Now that we know that the project is running smoothly, we have to configure it to run with the WebApps supervisor service. To do that, we need to create a file which the webapps supervisor will run. Create a file named \"~\/private\/myPyApp1\/webapps-start\" and paste the following in it:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">#!\/bin\/bash\n. \/home\/myusername\/private\/myPyApp1\/bin\/activate\ncd \/home\/myusername\/private\/myPyApp1\/html\nexec python -m http.server $PORT<\/pre>\n\n\n\n<p>Make sure that you replace \"myusername\" with your actual account username.<\/p>\n\n\n\n<p>Make the file executable:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">chmod +x ~\/private\/myPyApp1\/webapps-start<\/pre>\n\n\n\n<p>Now we will enable the WebApps project, so that it manages our web server: <\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">sureapp project shell pytest         # enter the context of the WebApps project \"pytest\"\nsureapp service status               # check the status of your project \"pytest\"\nsureapp service manage --enable      # this command enables your project\nsureapp service status               # check the status of your project \"pytest\" again, to see it running\nsureapp log follow                   # monitor the log of your project<\/pre>\n\n\n\n<p> You can now see your Python-enabled web server at: <span style=\"text-decoration: underline;\">https:\/\/www.your_domain.com<\/span>.<\/p>\n\n\n\n<p>To stop the supervisor, use the following commands:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">sureapp service manage --stop\nsureapp service status<\/pre>\n\n\n\n<p>and to start the service again use:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">sureapp service manage --start\nsureapp service status<\/pre>\n\n\n\n<p>If you would like to experiment with this system yourself, open your WebApps account now at:<\/p>\n\n\n\n<p><a href=\"https:\/\/www.icdsoft.com\/en\/hosting\/webapps\" target=\"_blank\" rel=\"noreferrer noopener\" aria-label=\"https:\/\/www.icdsoft.com\/en\/hosting\/webapps (opens in a new tab)\">https:\/\/www.icdsoft.com\/en\/hosting\/webapps<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Our WebApps platform is very versatile and allows you to deploy many different types of software. Here we&#8217;ll show you how to run Python 3.6 with a simple web server.<\/p>\n","protected":false},"author":1,"featured_media":5715,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"advgb_blocks_editor_width":"","advgb_blocks_columns_visual_guide":"","footnotes":""},"categories":[5,3],"tags":[],"class_list":{"0":"post-5663","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-tech","8":"category-how-to"},"author_meta":{"display_name":"ICDSoft","author_link":"https:\/\/www.icdsoft.com\/blog\/author\/icdsoft\/"},"featured_img":"https:\/\/www.icdsoft.com\/blog\/wp-content\/uploads\/2019\/09\/code-108-300x169.jpg","featured_image_src":"https:\/\/www.icdsoft.com\/blog\/wp-content\/uploads\/2019\/09\/code-108.jpg","featured_image_src_square":"https:\/\/www.icdsoft.com\/blog\/wp-content\/uploads\/2019\/09\/code-108.jpg","author_info":{"display_name":"ICDSoft","author_link":"https:\/\/www.icdsoft.com\/blog\/author\/icdsoft\/"},"coauthors":[],"tax_additional":{"categories":{"linked":["<a href=\"https:\/\/www.icdsoft.com\/blog\/category\/tech\/\" class=\"advgb-post-tax-term\">Technology<\/a>","<a href=\"https:\/\/www.icdsoft.com\/blog\/category\/how-to\/\" class=\"advgb-post-tax-term\">How To<\/a>"],"unlinked":["<span class=\"advgb-post-tax-term\">Technology<\/span>","<span class=\"advgb-post-tax-term\">How To<\/span>"]}},"comment_count":"0","relative_dates":{"created":"Posted 7 years ago","modified":"Updated 6 years ago"},"absolute_dates":{"created":"Posted on October 7, 2019","modified":"Updated on September 3, 2020"},"absolute_dates_time":{"created":"Posted on October 7, 2019 10:07 am","modified":"Updated on September 3, 2020 5:28 am"},"featured_img_caption":"","series_order":"","_links":{"self":[{"href":"https:\/\/www.icdsoft.com\/blog\/wp-json\/wp\/v2\/posts\/5663","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.icdsoft.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.icdsoft.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.icdsoft.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.icdsoft.com\/blog\/wp-json\/wp\/v2\/comments?post=5663"}],"version-history":[{"count":24,"href":"https:\/\/www.icdsoft.com\/blog\/wp-json\/wp\/v2\/posts\/5663\/revisions"}],"predecessor-version":[{"id":8186,"href":"https:\/\/www.icdsoft.com\/blog\/wp-json\/wp\/v2\/posts\/5663\/revisions\/8186"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.icdsoft.com\/blog\/wp-json\/wp\/v2\/media\/5715"}],"wp:attachment":[{"href":"https:\/\/www.icdsoft.com\/blog\/wp-json\/wp\/v2\/media?parent=5663"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.icdsoft.com\/blog\/wp-json\/wp\/v2\/categories?post=5663"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.icdsoft.com\/blog\/wp-json\/wp\/v2\/tags?post=5663"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}