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
</Directory>
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.)