-2

How to run python scripts in centos via browser.. Python version 2.6.6 And it's working from command line but I want to run via browser.

Sameer
  • 91
  • 2
  • 7

1 Answers1

0

Thats a great question: making the leap between a command line script and a web-site script isn't obvious. There are a few ways of converting a 'shell-script' into a web-view:

  1. CGI scripts. This is the 'old' way of doing it. Basically you configure Apache (or some other web server) that when a url gets called, it runs your script. This way you have to produce 'cgi' stuff including headers. Its a bit of a pain to do, but works. There are some other posts which show how to do this, but you need to configure a web server as well as add in cgi bits into your code

  2. Use a framework (like flask, or django or...) Flasks are the easiest to understand. They run as a script, and run up a mini webserver that you can poke a browser at. when run in this 'dev' mode, they're usually single threaded, but great for developing. Flasks also have a 'routing' function which allws you to have different url's go to different functions, so you can make more then one url. see http://flask.pocoo.org

  3. Use a 'process manager' such as uwsgi. The great thing about flasks/django is that they can be ported onto uwsgi, which is a proper production process manager which will run multiple threads and do caching and other cool stuff that you need in production servers.

  4. You could also hand-crank a tiny webserver, either using a framework like Twisted, or even by doing the socket stuff by hand. I wouldn't recommend this for any serious work (although its a great learning exercise in threads etc).

I would recommend you look at using something like Flasks or Django - I use Django the moment I have a DB to look after, otherwise Flasks for little script type things. They both have excellent tutorials.

Good luck!

Jmons
  • 1,766
  • 17
  • 28
  • Thanks for reply .. – Sameer Oct 12 '16 at 10:37
  • Could you explore me how can I set up ..Me have already installed lampp,python – Sameer Oct 12 '16 at 10:38
  • Which option are you heading towards? With something like fabric, you can get the tutorial running easily using pip to install packages and manage dependanices. you should also look at virtualenv's as well (its annoying to begin with, but really helps you when you have multiple projects running later) Have a look at http://www.fabfile.org/installing.html – Jmons Oct 12 '16 at 10:49