Introduction
CloudLinux's Python Selector software allows a cPanel user to set up and manage Python web applications ( WSGI applications ) to be served by Apache through the use of Mod Passenger ( mod_passenger ) which is an alternative to other solutions such as Mod WSGI ( mod_wsgi ) and Mod Python ( mod_python ).
The following guide explains the process of setting up a version.py script within the "Setup Python App" icon that you can find in cPanel after you install CloudLinux and CloudLinux's Python Selector software.
This is not a necessary step for creating a Python Application, so if you just want to jump straight into setting an application up, please review the following guide:
How to Register an Application with Python Selector
Procedure
The first two steps are where you set up the version.py file for use.
1. Using FileManager, Terminal, or SSH, as the cPanel user, create an application directory somewhere within the account. Here is an example path that you can use for testing, please note that YOURCPANELUSERNAME would represent the cPanel username that you are using for this task. Also, note that this directory can be under the public_html directory but it does not have to be. In this example the directory is not under the public_html directory:
/home/YOURCPANELUSERNAME/testpython/
2. Upload the following python file inside of your directory and name it version.py:
/home/YOURCPANELUSERNAME/testpython/version.py
import sys
def application(environ, start_response):
status = '200 OK'
output = u''
output += u'sys.version = %s\n' % repr(sys.version)
output += u'sys.prefix = %s\n' % repr(sys.prefix)
response_headers = [('Content-type', 'text/plain'),
('Content-Length', str(len(output)))]
start_response(status, response_headers)
return [output.encode('UTF-8')]
1. Login to the cPanel interface
2. Click on the "Select Python App" icon under the "Software" section to open up the Python Selector interface.
3. Click on the blue "Create Application" button to start the registration process
4. Within the "Application root" text box enter the name of the directory that will hold your test application. For the purpose of this demo just use the following:
testpython
After the registration process is done, Python Selector will have created a new directory at the following location:
/home/YOURCPANELUSERNAME/testpython
This is not particularly important for this step, but we are noting it for future reference.
5. For the "Startup File" textbox, place the name of the version script which is just:
version.py
6. For the "Application Entry Point" you need to use the name of the main function in the script. This is typically called "application" so you should enter it into the text box just like below:
application
7. It's always desirable to have a log setup, especially when testing. If you would like to avoid having to troubleshoot file permissions and ownership for your log file, fill in the log text box with the following filename. Using the logs directory makes things work much more easily.
logs/passenger.log
The low will be created at the following location once the registration process is done:
/home/YOURCPANELUSERNAME/logs/passenger.log
8 Click the Blue Create button in the upper right corner to register the application to finish registering the application.
9 Open the application's new directory that was mentioned in step 4 via the File Manager Icon, Terminal, or SSH, whichever you are most comfortable with:
/home/YOURCPANELUSERNAME/testpython
10 You'll notice that the version.py file already exists in that directory with some basic code. You can use that just to verify that Python is working by visiting your domain now, however, to get the version printed, you will need to replace the contents of the version.py file with the following:
/home/YOURCPANELUSERNAME/testpython/version.py
import sys
def application(environ, start_response):
status = '200 OK'
output = u''
output += u'sys.version = %s\n' % repr(sys.version)
output += u'sys.prefix = %s\n' % repr(sys.prefix)
response_headers = [('Content-type', 'text/plain'),
('Content-Length', str(len(output)))]
start_response(status, response_headers)
return [output.encode('UTF-8')]
11. Once you have updated the code of the file, you must then go back to the "Setup Python App" icon and click on the Pencil icon to edit the application
12. Then click the "Restart" button
13. Now you may visit the application in your browser to see the Python version in use printed.