This guide provides you with steps to setup and run Python scripts in cPanel.
Step 1- Login to cPanel
- Please see our article on logging into cPanel here.
Step 2 - Click on File Manager under your Files section.
INFO: Python scripts can be run inside ‘public_html‘ or in ‘cgi-bin‘ folder.The cgi-bin folder contains executable CGI scripts. If you are placing the file outside of the cgi-bin folder, ‘.htaccess‘ file should be created additionally to make the script work. For this example we will create the file inside ‘cgi-bin’ folder.
Step 3 - Create a test Python file in /public_html/cgi-bin
Step 4 - Edit the file to add test script
#!/usr/bin/python
print "Content-type: text/html\n\n"
print "Python is working fine on your server."
Step 5 - Edit file permissions
- Right click on the test file and select change Permissions
- The permissions must be updated to 755 for the test script to work.
- Click change permissions
Step 5 - Test the file via your browser
INFO: If you would like to run the Python file not in the cgi-bin folder (in public_html or any other directory), it is necessary to add the following code to the .htaccess file in the same directory where the Python script is uploaded:
Options +ExecCGI
AddHandler cgi-script .py
TIP: For more articles on cPanel please see our cPanel category. Alternatively should you wish to contact our Support Center please click here.