Page 1 of 1
exec problem
Posted: Tue May 01, 2007 3:56 pm
by vimadeva
Hi all! I'm new in linux and php. My problem is that i want to create a file (dhcpd.conf) and then copy it to /etc/conf.d.
The problem is that i can't use
exec(cp /var/www/html/dhcpd.conf /etc/dhcp.conf) or
exec(sudo -u root cp /var/www/html/dhcpd.conf /etc/dhcp.conf).
I already added this line to /etc/ sudoers:
ALL ALL=(ALL) NOPASSWD ALL hoping that that would help, but the problem continues.
If I run
exec("whoami") in a php file, it shows apache, but
exec("sudo -u root whoami") dies.
I would appreciate some help, i need this for today

.
Sorry for the bad english.
Please i running out of ideas.
Summary: Hot to mate exec(sudo.... ) works.
I dont care about security, I only wants it to work.
Posted: Tue May 01, 2007 4:19 pm
by arturm
you cannot run
because apache user (usually www-data or nobody) can't login as a root
and you can't copy your files because you don't have permission to the directory you are trying to copy to.
in linux console you can change permissions
but I wouldn't advice that since all apache users will have access to that file.
Posted: Tue May 01, 2007 4:40 pm
by vimadeva
arturm wrote:you cannot run
because apache user (usually www-data or nobody) can't login as a root
and you can't copy your files because you don't have permission to the directory you are trying to copy to.
in linux console you can change permissions
but I wouldn't advice that since all apache users will have access to that file.
Thank you arturm but I think I can, because in a gentoo installation i could do that. What about run
It doesn't works, also
Code: Select all
exec("cp /var/www/html/some.txt /var/www/html/other.txt");
doesn't work, also I "need" to restart a sevice like
I will appreciate any thought.
Posted: Tue May 01, 2007 6:16 pm
by aaronhall
Have you tried simply using
copy()?
Posted: Wed May 02, 2007 8:16 am
by arturm
try to put
at the top of your php page.
At least we will see what error do you have.
Posted: Wed May 02, 2007 12:12 pm
by vimadeva
arturm wrote:try to put
at the top of your php page.
At least we will see what error do you have.
Well, i putted that command at the start of the line but nothing is printed :S. Does it means that there were no erros in the execution of exec('sudo whoami'); ?
I already hace trien with system() and shell_exec().
And now i need to execute something like this: shell_exec(sudo service dhcpd restart);
Posted: Wed May 02, 2007 12:13 pm
by John Cartwright
aaronhall wrote:Have you tried simply using
copy()?
Agreed. Have you?
Re: exec problem
Posted: Wed May 02, 2007 12:18 pm
by volka
vimadeva wrote:I already added this line to /etc/ sudoers: ALL ALL=(ALL) NOPASSWD ALL
by hand or did you use a tool like visudo for that?
Posted: Wed May 02, 2007 12:18 pm
by vimadeva
Jcart wrote:aaronhall wrote:Have you tried simply using
copy()?
Agreed. Have you?
Sorry. I already have, and it works. But it was only an example, I really need to exec commands from php.
Re: exec problem
Posted: Wed May 02, 2007 12:20 pm
by vimadeva
volka wrote:vimadeva wrote:I already added this line to /etc/ sudoers: ALL ALL=(ALL) NOPASSWD ALL
by hand or did you use a tool like visudo for that?
I did both...
Is there a problem??
Posted: Wed May 02, 2007 12:56 pm
by arturm
Ok and what about this syntax:
Posted: Wed May 02, 2007 1:08 pm
by arturm
Error is not on the PHP side but on the Linux side.
I just tested it and I know how to debug the problem.
You have to run the script in a console using binary php
on my machine it is
where test.php is a file with exec function and php5-cgi is a binary version of php.
It can be named as simply as php or php5 depends on the system you are using.
If you don't have it you have to compile it.
Posted: Wed May 02, 2007 1:45 pm
by volka
I've never seen ALL ALL=(ALL) before.
Would the meaning be "everybody can do everything"?
I doubt that's possible with sudo.
Problem solved
Posted: Sat May 05, 2007 12:53 pm
by vimadeva
Hi all! I already solved the problem, I'll just post it:
In the sudoers file, you have to comment the line that says
That was the problem!!! since php isn't running from a tty, and also you have to add the line
to give all the privileges to de server! I hope this is usefull for you, it was for me
Sorry for my english... I think that you understand
