How to run Python in Shared Hosting | | Gotmyhost
How to Run Python Scripts on Shared Hosting (4 Easy Steps)

Running Python on a shared hosting server doesn’t have to be complicated. If you aren’t using a heavy framework like Django or Flask and just need to execute a standalone script, the CGI (Common Gateway Interface) method is your fastest route.

Follow these four steps to get your script live in minutes:

1. Upload Your Script

Upload your .py file to your desired directory (usually public_html or a subfolder) using FTP or your File Manager.

2. Configure .htaccess

You need to tell the Apache server how to handle Python files. Create a file named .htaccess in the same folder and add this line:

Apache

AddHandler cgi-script .py

3. Add the Shebang Line

The server needs to know where the Python interpreter is located. Open your .py file and ensure the very first line is:

Python

#!/usr/bin/python

4. Set Permissions

For a script to execute, it needs the correct permissions. Set your .py file permissions to 755 (Read/Write/Execute for Owner, Read/Execute for Group/World).

That’s it! You can now navigate to your script’s URL (e.g., yourdomain.com/script.py) to see it in action.

Leave a Reply

Your email address will not be published. Required fields are marked *