How to configure sudoers to allow PHP execute with parameters

Posted on 2009-02-22
Last Modified: 2012-06-21
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
Question by:xuzhaogang
    LVL 16

    Accepted Solution

    What if you extend you sudoers configuration to:

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

    allowing for 2 (wildcard) parameters?

    Author Comment

    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.

    LVL 16

    Expert Comment

    And if you create 2 entries? One without parameters and one with them?

    Featured Post

    Maximize Your Threat Intelligence Reporting

    Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

    Join & Write a Comment

    Hi, in this article I'm going to teach you how to run your own site, and how to let people in (without IP). I'll talk about and explain each step... :) By the way, everything in this Tutorial is completely free and legal. This article is for …
    I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
    The viewer will learn how to dynamically set the form action using jQuery.
    The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

    733 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    23 Experts available now in Live!

    Get 1:1 Help Now