Running Python script on PHP server

I am running the nginx web server along with PHP-CGI.

I would like to know if it is possible to execute a Python script inside PHP pages, which allows you to combine both languages. I tried this briefly, but it didn't work, so I'm not sure how to do this. Here are the two files I used:

index.php

<body> <p>Hello! Here is a message: <?php exec('python hello.py'); ?></p> </body> 

hello.py

 print 'Hello World!' 

Any clues would be appreciated.

+4
source share
1 answer

exec will return the shell command output, but you still need to echo what's on the page. The following code should work for you

 <body> <p>Hello! Here is a message: <?php echo exec('python hello.py'); ?></p> </body> 
+2
source

Source: https://habr.com/ru/post/1415031/


All Articles