tags:

views:

191

answers:

1

I have write a website,what confused me is when i run the website,first i need start the the app, so there are 3 ways:

  1. sudo python xxx.py
  2. python xxx.py
  3. xxx.py

I didn't clear with how to use each of them,the NO.3 method currently in my computer dosen't work well

+5  A: 

sudo will run the application with superuser permissions. Considering that you're referring to a website, this is certainly not what you want to do. (For a webapp, if it requires superuser permissions, it's broken. That's far, far too big of a security risk to consider actually using.)

Under other circumstances you might have a python program that does some sort of system maintaince and requires being run as root. In this case, you'd use sudo, but you would never want to do this for something that's publicly accessible and could potentially be exploited. In fact, for anything other than testing, you should probably run the webapp as a separate user with very limited access (e.g. with their shell set to /dev/null, no read or write access to anything that they don't need, etc...).

The other two are effectively identical (in therms of what they do), but the last option (executing the script directly) will require:

  1. the executable bit to be set (on unix-y systems) (e.g. chmod +x whatever.py)
  2. a shebang on the first line(e.g. #! /usr/bin/python) pointing to the python execuctable that you want to run things with (again, this only applies to unix-y systems)

Calling python to run the code (python whatever.py) and following the steps above (resulting in a script that you can call directly with whatever.py) do exactly the same thing (assuming that the shebang in the python file points to the same python executable as "python" does, anyway...)

Joe Kington