Hi,
I am new to php and web development. I wanted to run a system command from php script. I am using shell_exec() to run the command, but i need root privileges to execute it. I dont want to make 'Apache' a 'sudo user' nor do I want to change the default 'apache user' to root.
Please can someone suggest me a way in which I will be able to execute the command with root privileges.
Thanks in Advance,
Amul
Running a system command from php
Moderator: General Moderators
-
Amul Adagale
- Forum Newbie
- Posts: 2
- Joined: Thu Jun 25, 2009 10:05 am
Re: Running a system command from php
What is the command?Amul Adagale wrote:... the command, but i need root privileges to execute it...
Well, it is the best way to do it - sudo has a powerful wrapper.Amul Adagale wrote:... I don't want to make 'Apache' a 'sudo user' ...
I doubt, one is even able to do itAmul Adagale wrote:... nor do I want to change the default 'apache user' to root...
You may make your executable file SUID-ed (this means that any user on the system can execute it with root privileges) ...
Or you can write a wrapper script (arguments validation, user ID check, etc.) and SUID it - i.e. to "write" a small sudo-like tool
There are 10 types of people in this world, those who understand binary and those who don't
-
Amul Adagale
- Forum Newbie
- Posts: 2
- Joined: Thu Jun 25, 2009 10:05 am
Re: Running a system command from php
Hi,
Thanks for your reply.
The command actually is my executable in which I am calling 'mkdir' and some other file handling commands. I have been trying to setuid for the script and the executable but it didnt seem to work.
I have found a solution to the problem though. I am writing a wrapper to my executable which is owned by a sudo user. In this wrapper I am calling the executable with a sudo in it. It seems to be doing the job.
Thanks
Amul
Thanks for your reply.
The command actually is my executable in which I am calling 'mkdir' and some other file handling commands. I have been trying to setuid for the script and the executable but it didnt seem to work.
I have found a solution to the problem though. I am writing a wrapper to my executable which is owned by a sudo user. In this wrapper I am calling the executable with a sudo in it. It seems to be doing the job.
Thanks
Amul