In this post, we will provide a tutorial on how to install Python 3.6 with a simple web server on a WebApps hosting account.
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:
- Standard PHP/Perl applications like WordPress, for example.
- Node.js with out-of-the-box support.
- Custom environments such as Django, Ruby.
- MongoDB instances.
- Full support of ICDSoft’s email features, including spam protection and Webmail software.
All the above is combined within a single hosting account on the WebApps platform.
Background processes are usually forbidden on shared hosting platforms, but the power of the WebApps platform comes from this exact feature. You can run background processes (daemons) on the WebApps platform. In effect, this means that you can run almost any type of software that runs on Debian Linux.
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: https://www.icdsoft.com/en/kb/webapps_node_js
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.
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.
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.
Step 1 – Install Python 3.6
First, we will install Python 3.6. Log in through SSH to your hosting account, and run the following commands:
cd ~/private # the private/ folder isn't web accessible mkdir python-temp python36 # create a temporary directory pip install --user virtualenv # use the pip package manager to install the "virtualenv" package cd python-temp wget https://www.python.org/ftp/python/3.6.9/Python-3.6.9.tgz # download python 3.6 tar -xf Python-3.6.9.tgz # extract the archive cd Python-3.6.9 ./configure --prefix="$HOME/private/python36" # configure & compile Python 3.6 make -j 8 make install cd ~/private rm -rf python-temp/ # remove the temporary dir and files
Step 2 – Create sample pages on the server
At this point, you have Python 3.6.9 installed. Now, we will test python and create some sample pages:
~/.local/bin/virtualenv myPyApp1 --python ~/private/python36/bin/python3 . myPyApp1/bin/activate python --version # verify that we are running the correct version - "3.6.9" cd myPyApp1 mkdir html cd html echo "Page1" > page1.html # create sample pages echo "Page2" > page2.html
Step 3 – Create a WebApps project to manage our server
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.
You can create your WebApps project either through the WebApps section of the hosting Control Panel, or through the command line.
To do it via the command line, use the following command:
sureapp project create --engine custom --engine-version - --release-dir ~/private/myPyApp1 --subdomain www --url-path / --start-cmd ~/private/myPyApp1/webapps-start pytest
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”.
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.
Run the following command to list your applications. Take note of the port assigned to the pytest application:
sureapp project list
Start the web server for a test with the port from the previous command. We use port 31602 as an example:
python -m http.server 31602
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:
exit #exit "virtualenv"
Step 4 – Making an executable for the WebApps supervisor
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:
#!/bin/bash . /home/myusername/private/myPyApp1/bin/activate cd /home/myusername/private/myPyApp1/html exec python -m http.server $PORT
Make sure that you replace “myusername” with your actual account username.
Make the file executable:
chmod +x ~/private/myPyApp1/webapps-start
Now we will enable the WebApps project, so that it manages our web server:
sureapp project shell pytest # enter the context of the WebApps project "pytest" sureapp service status # check the status of your project "pytest" sureapp service manage --enable # this command enables your project sureapp service status # check the status of your project "pytest" again, to see it running sureapp log follow # monitor the log of your project
You can now see your Python-enabled web server at: https://www.your_domain.com.
To stop the supervisor, use the following commands:
sureapp service manage --stop sureapp service status
and to start the service again use:
sureapp service manage --start sureapp service status
If you would like to experiment with this system yourself, open your WebApps account now at: