nitiphone2021 Posted May 25, 2021 Share Posted May 25, 2021 Hi all. I tried to execute command below ` echo '<br/>'.$data. " >=> " . exec("java -jar encrypt.jar ".$data." ".$privateKey, $key);` it's look like we run `java -jar encrypt.jar 192.168.101.1BBB10052 ssdsds` I can run this command on the server by ssh but when I use PHP code, it's nothing. so I need to enale the exec function or different command on this version? Quote Link to comment https://forums.phpfreaks.com/topic/312788-php-exec-not-work-on-php-7234/ Share on other sites More sharing options...
requinix Posted May 25, 2021 Share Posted May 25, 2021 Is exec() enabled? Can you run other commands? Simple commands? Is the command exactly what you think it is? You've confirmed $data and $privateKey have the values you think they have? Are you executing this from the right directory? Do commands like is_file() think that "encrypt.jar" exists where you expect? Quote Link to comment https://forums.phpfreaks.com/topic/312788-php-exec-not-work-on-php-7234/#findComment-1586783 Share on other sites More sharing options...
nitiphone2021 Posted May 25, 2021 Author Share Posted May 25, 2021 yes, I reading on PHP document. seem I need to enable exec command? How to enable it? like PHP extension? Quote Link to comment https://forums.phpfreaks.com/topic/312788-php-exec-not-work-on-php-7234/#findComment-1586785 Share on other sites More sharing options...
requinix Posted May 25, 2021 Share Posted May 25, 2021 No. Do the other troubleshooting steps first. If it turns out that the answer is that exec() is disabled then we can deal with that. Because that is probably not the problem. Quote Link to comment https://forums.phpfreaks.com/topic/312788-php-exec-not-work-on-php-7234/#findComment-1586786 Share on other sites More sharing options...
nitiphone2021 Posted May 25, 2021 Author Share Posted May 25, 2021 yes, I run only easy command but still not work <?php // Use ls command to shell_exec // function $output = shell_exec('ls'); // Display the list of all file // and directory echo "HERE = " . $output; ?> Quote Link to comment https://forums.phpfreaks.com/topic/312788-php-exec-not-work-on-php-7234/#findComment-1586787 Share on other sites More sharing options...
requinix Posted May 25, 2021 Share Posted May 25, 2021 What does var_dump($output); show? Any errors in the error log? Add error_reporting(-1); ini_set("display_errors", true); at the top of the file and try again. Quote Link to comment https://forums.phpfreaks.com/topic/312788-php-exec-not-work-on-php-7234/#findComment-1586790 Share on other sites More sharing options...
nitiphone2021 Posted May 25, 2021 Author Share Posted May 25, 2021 Warning: shell_exec() has been disabled for security reasons in /home/cp227590/public_html/bdb.com.la/phpinfo.php on line 8 Error message Quote Link to comment https://forums.phpfreaks.com/topic/312788-php-exec-not-work-on-php-7234/#findComment-1586791 Share on other sites More sharing options...
requinix Posted May 25, 2021 Share Posted May 25, 2021 Looks like you're on shared hosting. Contact your host to see if you can get that restriction lifted, but don't hold your breath. Quote Link to comment https://forums.phpfreaks.com/topic/312788-php-exec-not-work-on-php-7234/#findComment-1586792 Share on other sites More sharing options...
nitiphone2021 Posted May 25, 2021 Author Share Posted May 25, 2021 Now I enable it but seem I can't run only java echo "linux = '" . exec("ls -l") . "'"; echo "<br>java = '" . exec("/usr/bin/java -version") . "'"; Linux command can work but java not work [root@host ~]# which java /usr/bin/java [root@host ~]# I tried like this but not work Quote Link to comment https://forums.phpfreaks.com/topic/312788-php-exec-not-work-on-php-7234/#findComment-1586793 Share on other sites More sharing options...
nitiphone2021 Posted May 25, 2021 Author Share Posted May 25, 2021 [root@host ~]# java -version openjdk version "1.8.0_292" OpenJDK Runtime Environment (build 1.8.0_292-b10) OpenJDK 64-Bit Server VM (build 25.292-b10, mixed mode) [root@host ~]# [root@host ~]# [root@host ~]# [root@host ~]# /usr/bin/java -version openjdk version "1.8.0_292" OpenJDK Runtime Environment (build 1.8.0_292-b10) OpenJDK 64-Bit Server VM (build 25.292-b10, mixed mode) [root@host ~]# Quote Link to comment https://forums.phpfreaks.com/topic/312788-php-exec-not-work-on-php-7234/#findComment-1586794 Share on other sites More sharing options...
nitiphone2021 Posted May 25, 2021 Author Share Posted May 25, 2021 Updated!!!!! Updated!! Now I can execute java command like java -version but can't execute jar file echo exec("/usr/bin/java -version 2>&1",$output); // Output work echo "<br>"; echo exec("/usr/bin/java -jar encrypt.jar ".$data." ".$privateKey . " 2>&1",$key); Result: OpenJDK 64-Bit Server VM (build 25.292-b10, mixed mode) Error: Unable to access jarfile encrypt.jarArray ( [0] => Error: Unable to access jarfile encrypt.jar ) In the same command, I can run it on my laptop can work properly the file encrypt.jar permission is 777 Quote Link to comment https://forums.phpfreaks.com/topic/312788-php-exec-not-work-on-php-7234/#findComment-1586796 Share on other sites More sharing options...
requinix Posted May 25, 2021 Share Posted May 25, 2021 Back to one of the questions I asked earlier: are you sure PHP is running from the correct location? Does glob/scandir/ls without any path information include encrypt.jar? Are file permissions correct such that Apache and/or PHP can properly access the file? In other words, does var_dump(is_readable("encrypt.jar")); output true? Quote Link to comment https://forums.phpfreaks.com/topic/312788-php-exec-not-work-on-php-7234/#findComment-1586806 Share on other sites More sharing options...
nitiphone2021 Posted May 26, 2021 Author Share Posted May 26, 2021 Now I can exec the command. my point is 1. exec command not allow on php.ini 2. on PHP can't call java command by "java" need to put full location 3. path of jar file, my PHP file and java file in the path but I can't call it like javafile.jar need to put full path. `exec("/usr/bin/java -jar /home/public_html/believe.com/CoVaF/func/encrypt.jar ` Thank you all for support Quote Link to comment https://forums.phpfreaks.com/topic/312788-php-exec-not-work-on-php-7234/#findComment-1586814 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.