• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1233
  • Last Modified:

How to configure sudoers to allow PHP execute with parameters

hi,
i am trying to execute a php (/var/www/server.php) in system folder from a php (/var/www/html/client.php) in web folder.

what i have done is:
in the client.php,  i put exec('sudo /usr/bin/php -f /var/www/server.php',$output,$return);
in the server.php, i just put echo "OK";
in the /etc/sudoers, i put nobody ALL=(ALL) NOPASSWD: /usr/bin/php -f /var/www/server.php

it works fine like above. but i want to pass some parameters to the server.php, so i edit my client.php like exec('sudo /usr/bin/php -f /var/www/server.php '.$src_file_path.' '.$dest_file_path.'',$output,$return); and i cannot get it done and there is no error message shown in my log file.

please kindly advise on the above
0
xuzhaogang
Asked:
xuzhaogang
  • 2
1 Solution
 
RobinSoftware EngineerCommented:
What if you extend you sudoers configuration to:

ALL=(ALL) NOPASSWD: /usr/bin/php -f /var/www/server.php * *

allowing for 2 (wildcard) parameters?
0
 
xuzhaogangAuthor Commented:
how stupid i am ... forgot the wildcard, yeh it works, thank you, robinu.

but only one small drawback. i found if i don't attach any parameters now, it won't run.

ray
0
 
RobinSoftware EngineerCommented:
And if you create 2 entries? One without parameters and one with them?
0

Featured Post

NEW Veeam Backup for Microsoft Office 365 1.5

With Office 365, it’s your data and your responsibility to protect it. NEW Veeam Backup for Microsoft Office 365 eliminates the risk of losing access to your Office 365 data.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now