I set up an Apache server on my system. I want to run commands and files using the website running on my local system. How do I trigger a file running using browser?

What i want to do: I have a file test.py on my computer. I want to run this file triggered by a button on my website.

1 Answer 1


I fear from the phrasing of your question that you might be unaware of the very substantial security implications. Don't do this lightly on an Internet facing server.

There are a few ways of doing this. The "Apache level" way is to set up "cgi" functionality in Apache. One way to do this us to add a stanza like below to your Apache config:

<Directory "/var/www/cgi-bin">
    AllowOverride None
    Options +ExecCGI
    AddHandler cgi-script .py
    Require all granted

The above will allow you to run files ending in .pl scripts which exist in /var/www/cgi-bin

A simpler way would be to do some kind of shell call from PHP if that is configured (a command like shell_exec or similar would do it.)

  • The question asks about Python (test.py) but you are suggesting making Perl (.pl) scripts executable. Shouldn't that be .py in your AddHandler rule? Commented Mar 25, 2021 at 11:30
  • @StephenenOstermiller - yes Good catch.
    – davidgo
    Commented Mar 25, 2021 at 17:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.