kshitij sawhney
kshitij sawhney

Reputation: 21

php script invoking a python script works in the ssh terminal but no output in the browser window

The following pieces of code when executed using php -f phptest.php gave the output (server is a GCP virtual instance running Centos7):

[[1, 2, 3], [4, 5, 6], [7, 8, 9]]
string(34) "[[1, 2, 3], [4, 5, 6], [7, 8, 9]]"

In the terminal window. On the other hand the same code when run using the server IP and appropriate URL gives:

string(0) ""

Here are the two scripts :

#!/usr/bin/env python  
def foo():    
    x=str([[1,2,3],[4,5,6],[7,8,9]])  
    return x  
x=foo()  
print(x)  

and

<?php
$command = "python_location pyfile.py"
escapeshellcmd($commmand);
$output = shell_exec($command);
$strout=print_r($output,true);
echo($strout);
var_dump($strout);
?>

The server doesn't have a directory /var/log/apache2/error.log. Instead i was able to find /var/log/httpd/error_log which contains the following:

[Sun Jun 16 05:04:34.269345 2019] [auth_digest:notice] [pid 21434] AH01757: generating secret for digest authentication ... [Sun Jun 16 05:04:34.284400 2019] [lbmethod_heartbeat:notice] [pid 21434] AH02282: No slotmem from mod_heartmonitor [Sun Jun 16 05:04:34.284500 2019] [mpm_prefork:notice] [pid 21434] AH00163: Apache/2.4.6 (CentOS) PHP/7.3.6 configured -- resuming normal operations [Sun Jun 16 05:04:34.284505 2019] [core:notice] [pid 21434] AH00094: Command line: '/usr/sbin/httpd -D FOREGROUND' [Sun Jun 16 05:11:53.245377 2019] [autoindex:error] [pid 32206] [client 187.10.191.110:35833] AH01276: Cannot serve directory /var/www/html/: No matching DirectoryIndex (index.html,index.php) found, and server-generated directory index forbidden by Options directive [Sun Jun 16 07:08:12.657568 2019] [autoindex:error] [pid 32210] [client 138.99.101.198:49444] AH01276: Cannot serve directory /var/www/html/: No matching DirectoryIndex (index.html,index.php) found, and server-generated directory index forbidden by Options directive [Sun Jun 16 09:09:49.507235 2019] [autoindex:error] [pid 32209] [client 170.130.187.26:54699] AH01276: Cannot serve directory /var/www/html/: No matching DirectoryIndex (index.html,index.php) found, and server-generated directory index forbidden by Options directive [Sun Jun 16 09:10:47.289063 2019] [autoindex:error] [pid 32207] [client 190.29.16.112:57449] AH01276: Cannot serve directory /var/www/html/: No matching DirectoryIndex (index.html,index.php) found, and server-generated directory index forbidden by Options directive [Sun Jun 16 13:50:02.964126 2019] [autoindex:error] [pid 32209] [client 95.141.135.6:34567] AH01276: Cannot serve directory /var/www/html/: No matching DirectoryIndex (index.html,index.php) found, and server-generated directory index forbidden by Options directive [Sun Jun 16 14:27:36.383175 2019] [autoindex:error] [pid 32207] [client 139.162.119.197:35716] AH01276: Cannot serve directory /var/www/html/: No matching DirectoryIndex (index.html,index.php) found, and server-generated directory index forbidden by Options directive

'server-generated directory index forbidden by Options directive' leads me to believe that this could possibly be changed through httpd.conf possibly?

Ideally the output in the browser would match the one I get in the ssh terminal

Thanks and Regards

Upvotes: 1

Views: 104

Answers (1)

Manish
Manish

Reputation: 11

I think maybe your PHP version is not updated and I tried in my pc and it is working fine. Try to update PHP

Upvotes: 0

Related Questions