user2630325
user2630325

Reputation: 11

Error while executing node command with php exec function

I'm trying to execute a nodejs file from php on a Centos server. When the command is executed from the terminal it works fine (also after switching to apache user with the following command su -s /bin/bash apache), but when the code is executed while browsing the file it throws the following exception:

["","","#","# Fatal error in , line 0","# Check failed: SetPermissions(protect_start, protect_size, PageAllocator::kReadExecute).","#","#","#","#FailureMessage Object: 0x7fffd9b37760"]

php -r 'echo exec("/usr/bin/node /var/www/html/index.js /var/www/html/source_files/ 2>&1");'

 <?php
 try {
       exec("/usr/bin/node /var/www/html/index.js /var/www/html/source_files/ 2>&1", $out, $err);

        if ($err == 0) {
            return 1;
        } else {           
            return 0;
        }
    } catch (Exception $e) {
        error_log($e);
        return 0;
    }
?>

Upvotes: 0

Views: 1492

Answers (1)

Dragonduck
Dragonduck

Reputation: 311

If you are using selinux, try disabling it temporary:

setenforce 0

Try to run your node.js script. If it run, you probably need to change selinux httpd settings. Do following command to list all selinux settings for httpd service:

/usr/sbin/getsebool -a | grep httpd

You will see two relevant settings httpd_ssi_exec and httpd_execmem. Set them on with:

setsebool -P httpd_ssi_exec=1
setsebool -P httpd_execmem=1

After that try to enable selinux again and run your node.js script to see if the change helped:

setenforce 1

Upvotes: 2

Related Questions