Skip to main content
added 147 characters in body
Source Link

On my website, I have a javascript function that has a POST ajax call to a PHP file on the server (a GoDaddy VPS running CentOS 6), which executes a python script via shell_exec() and returns the output.

Javascript function:

function submitdivsheet()
{
    $.post("test.php", {}, function(data,status){
        console.log(data);
    }); 
}

PHP script: test.php

<?php
    $command = escapeshellcmd('python3.6 test.py');
    $output = shell_exec($command);
    echo $output;
?> 

Python script: test.py

import sys
print("This is the output")

When I try to run the php file from the bash terminal on CPanel, there are no issues, as shown here. However, upon running the javascript function, only an empty string is output to the console. I'm not sure why it would only run on the CPanel terminal, but I suspect it could be a permissions issue somewhere. How can I fix this issue?

NOTE: This works fine on both the server and from the POST call if shell_exec() is not present. It seems that shell_exec is causing the problem.


EDIT: Upon changing the PHP script to:

<?php print shell_exec('echo $PATH'); ?>

This is the output.

On my website, I have a javascript function that has a POST ajax call to a PHP file on the server (a GoDaddy VPS running CentOS 6), which executes a python script via shell_exec() and returns the output.

Javascript function:

function submitdivsheet()
{
    $.post("test.php", {}, function(data,status){
        console.log(data);
    }); 
}

PHP script: test.php

<?php
    $command = escapeshellcmd('python3.6 test.py');
    $output = shell_exec($command);
    echo $output;
?> 

Python script: test.py

import sys
print("This is the output")

When I try to run the php file from the bash terminal on CPanel, there are no issues, as shown here. However, upon running the javascript function, only an empty string is output to the console. I'm not sure why it would only run on the CPanel terminal, but I suspect it could be a permissions issue somewhere. How can I fix this issue?


EDIT: Upon changing the PHP script to:

<?php print shell_exec('echo $PATH'); ?>

This is the output.

On my website, I have a javascript function that has a POST ajax call to a PHP file on the server (a GoDaddy VPS running CentOS 6), which executes a python script via shell_exec() and returns the output.

Javascript function:

function submitdivsheet()
{
    $.post("test.php", {}, function(data,status){
        console.log(data);
    }); 
}

PHP script: test.php

<?php
    $command = escapeshellcmd('python3.6 test.py');
    $output = shell_exec($command);
    echo $output;
?> 

Python script: test.py

import sys
print("This is the output")

When I try to run the php file from the bash terminal on CPanel, there are no issues, as shown here. However, upon running the javascript function, only an empty string is output to the console. I'm not sure why it would only run on the CPanel terminal, but I suspect it could be a permissions issue somewhere. How can I fix this issue?

NOTE: This works fine on both the server and from the POST call if shell_exec() is not present. It seems that shell_exec is causing the problem.


EDIT: Upon changing the PHP script to:

<?php print shell_exec('echo $PATH'); ?>

This is the output.

added 175 characters in body
Source Link

On my website, I have a javascript function that has a POST ajax call to a PHP file on the server (a GoDaddy VPS running CentOS 6), which executes a python script via shell_exec() and returns the output.

Javascript function:

function submitdivsheet()
{
    $.post("test.php", {}, function(data,status){
        console.log(data);
    }); 
}

PHP script: test.php

<?php
    $command = escapeshellcmd('python3.6 test.py');
    $output = shell_exec($command);
    echo $output;
?> 

Python script: test.py

import sys
print("This is the output")

When I try to run the php file from the bash terminal on CPanel, there are no issues, as shown here. However, upon running the javascript function, only an empty string is output to the console. I'm not sure why it would only run on the CPanel terminal, but I suspect it could be a permissions issue somewhere. How can I fix this issue?


EDIT: Upon changing the PHP script to:

<?php print shell_exec('echo $PATH'); ?>

This is the output.

On my website, I have a javascript function that has a POST ajax call to a PHP file on the server (a GoDaddy VPS running CentOS 6), which executes a python script via shell_exec() and returns the output.

Javascript function:

function submitdivsheet()
{
    $.post("test.php", {}, function(data,status){
        console.log(data);
    }); 
}

PHP script: test.php

<?php
    $command = escapeshellcmd('python3.6 test.py');
    $output = shell_exec($command);
    echo $output;
?> 

Python script: test.py

import sys
print("This is the output")

When I try to run the php file from the bash terminal on CPanel, there are no issues, as shown here. However, upon running the javascript function, only an empty string is output to the console. I'm not sure why it would only run on the CPanel terminal, but I suspect it could be a permissions issue somewhere. How can I fix this issue?

On my website, I have a javascript function that has a POST ajax call to a PHP file on the server (a GoDaddy VPS running CentOS 6), which executes a python script via shell_exec() and returns the output.

Javascript function:

function submitdivsheet()
{
    $.post("test.php", {}, function(data,status){
        console.log(data);
    }); 
}

PHP script: test.php

<?php
    $command = escapeshellcmd('python3.6 test.py');
    $output = shell_exec($command);
    echo $output;
?> 

Python script: test.py

import sys
print("This is the output")

When I try to run the php file from the bash terminal on CPanel, there are no issues, as shown here. However, upon running the javascript function, only an empty string is output to the console. I'm not sure why it would only run on the CPanel terminal, but I suspect it could be a permissions issue somewhere. How can I fix this issue?


EDIT: Upon changing the PHP script to:

<?php print shell_exec('echo $PATH'); ?>

This is the output.

Source Link

PHP shell_exec() script running from CPanel terminal but not from ajax POST call

On my website, I have a javascript function that has a POST ajax call to a PHP file on the server (a GoDaddy VPS running CentOS 6), which executes a python script via shell_exec() and returns the output.

Javascript function:

function submitdivsheet()
{
    $.post("test.php", {}, function(data,status){
        console.log(data);
    }); 
}

PHP script: test.php

<?php
    $command = escapeshellcmd('python3.6 test.py');
    $output = shell_exec($command);
    echo $output;
?> 

Python script: test.py

import sys
print("This is the output")

When I try to run the php file from the bash terminal on CPanel, there are no issues, as shown here. However, upon running the javascript function, only an empty string is output to the console. I'm not sure why it would only run on the CPanel terminal, but I suspect it could be a permissions issue somewhere. How can I fix this issue?