How run python scripts in Virtualmin
Author: admin admin Reference Number: AA-00436 Views: 31955 Created: 2016-12-02 15:16 Last Updated: 2016-12-02 15:16 0 Rating/ Voters

Python 2 is installed by default on all vps servers. To run python scripts you need to place your python file inside the cgi-bin folder in the home directory of your virtual server:

/home/USERNAME/cgi-bin

where USERNAME  is the username of your virtual server. You should note that:

1- Your python file must have executable permission, you can set executable permission by running the following command in shell:

chmod +x /home/USERNAME/cgi-bin/MY-PYTHON-FILE.py

where MY-PYTHON-FILE.py is your python filename.

2- You must use correct python binary path in the first line of your python file:

#!/usr/bin/python

to find the correct python path, run the following command in SSH:

which python

it returns the python binary path.


If you need python 3, you need to install the packages first:

apt-get install python3 on Debian based distros or yum install python34 on Redhat based distros.

The above commands will install python 3.4 on your server, now you need to update python path in the first line of your python script to the default python3 path, to do so run:

which python3

to get the default python3 path, it should be something like /usr/bin/python3 , now replace the first line of your script with:

#!/usr/bin/python3


If you're going to run Django on your VPS you need to install gunicorn or uwsgi backend on your VPS and then configure the apache service to proxy the requests to them.

Quick Jump Menu