简体   繁体   中英

linux php exec() msgget:Permission Denied

I'm trying to run a linux executable from a php script (ie sendMsg.php). The executable (ie msgr) uses SYS V msg queue to communicate with another running process.

sendMsg.php

<?php
    exec('./msgr 0987654321 1234 2>&1', $output, $return_var);

    var_dump($return_var);
    var_dump($output);
?>

msgr.c

  int msqid;
  key_t key;

  if ((key = ftok("/usr/local/bin/app", 'k')) == -1) {
      perror("ftok");
      exit(1);
  }

  if ((msqid = msgget(key, 0644)) == -1) {
      perror("msgget");
      exit(1);
  }

When I run the script from terminal, it works fine, but when I run it from the browser (via a ajax call or otherwise), I get an error:

msgget: Permission denied

Looks like some problem with file permissions. How can I solve this?

You might want to refer who the owner is running the execution. Refer to PHP.net

The owner should be www-data, but that could only be for linux-debian/ubuntu systems.

Otherwise a sudo chown and sudo chmod should work for your problem

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM