Topics Map > Communication and Collaboration > cPanel Web Hosting
cPanel, How to use Python on cPanel
Important difference when hosting Python on cPanel
Python hosted on cPanel is served using Passenger. You cannot specify a port for your application to run on. When visting your application, you will also not include a port number in the URL.
Initial Setup
The cPanel dashboard includes a utility that allows you to choose the Python version and install additional modules.
- Log in to your cPanel account dashboard at https://web.illinois.edu/.
- In the Software section of the dashboard, click on the Setup Python App utility.
- Click the Create Application button
- Choose the Python version you want from those available.
- In Application root, enter the path in your home directory where you would like your application files to be stored.
- In Application URL, select the domain and enter the path (if any) where visitors will access your application
- In Application startup file, enter the name of the file that will start your application
- In Application Entry point, enter a name for your entry point. You may leave this blank for an entry point name of "application"
- In Passenger log file, enter a path for your log file
- If you would like to define Environment variables, do so in the last section by clicking ADD VARIABLE and filling in the relevant information.
- Click Create and wait for the page to update.
When it is done with the configuration, your new application will be listed under the "Existing applications" section.
Post Setup
Once the application is configured, you can change the directory, the URI and the version of Python you are using in the Web Applications section.
The newly created application will be supplied with a stub only. The real application can be developed or put into the application folder now.
Module Installation
You have two options for installing modules.
- Enter the virtual environment and run pip install from the command line
- Use the cPanel interface to run pip install against a specified config file in your application directory
Using the virtual environment to install modules
- From your cPanel dashboard, click Setup Python app
- Find your app in the list on the resulting page and click the pencil to edit the app (you won't be making any edits)
- Copy to command listed at the top of the page and paste it into your terminal window to enter the virtual environment
- For an app called "AnotherDemo" using python 3.5 in the cPanel account "jakramerdemo" the command will look as follows:
source /home/jakramerdemo/virtualenv/AnotherDemo/3.5/bin/activate && cd /home/jakramerdemo/AnotherDemo
From the command line within the virtual environment, you can now run pip install to install your modules
Using the cPanel interface to install modules
- Create your requirements file in your application directory using the cPanel file manager or terminal window
- From your cPanel dashboard, click Setup Python app
- Find your app in the list on the resulting page and click the pencil to edit the app (you won't be making any edits)
- In the Configuration Files section, enter the filename of your config file and click add
- Optional: click Edit next to your configuration file to make changes before installing
- Click the Run Pip Install button and select the appropriate config file from the dropdown list