'Synology webstation settings to run python

On my synology I have webstation up and running (tested) Default server is Apache 2.4. By default, on DSM 7, Python is installed. Now I created a simple test.py script which I call from my browser:

#!/usr/bin/python
import os

print ("Content-type: text/html\n\n")
print ("<html>Hello world!</html>")

if 'REQUEST_METHOD' in os.environ :
  print ("This is a webpage")
else :
  print ("This is not a webpage")

When I run this "192.bla.bla/web/test.py" the code is not executed but just displayed. So I get this in my browser:

#!/usr/bin/python
import os

print ("Content-type: text/html\n\n")
print ("<html>Hello world!</html>")

if 'REQUEST_METHOD' in os.environ :
  print ("This is a webpage")
else :
  print ("This is not a webpage")

Obviously Python is not executed so I searched the internet and found this, outdated German, topic: Link to Topic

Telling me to change some config files. However the directories these files should contain are not on my system. I'm also not sure if this even is the solution as this topic is outdated.

Does anyone have Python running on Synology webstation?



Solution 1:[1]

Try using a php server and page and then using this in the index.php

<?php 

$command = escapeshellcmd('/usr/custom/test.py');
$output = shell_exec($command);
echo $output;

?>

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1