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
xuzhaogangAsked:
Who is Participating?
 
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.