In my php program, i want excute some system command ,eg.fdisk,df etc.So i try to use exec() or shell_exec() to excute it ,but it's can't work.
my env. is apache+php,in apache configure ,user=nobody,group=nobody.Can i change it to root?
[/b]
problem with excute shell command!
Moderator: General Moderators
Create a shell script called testme.sh in a directory where you have full control of and the user nobody can r+x on.
then chmod a+s on that file. This will cause that file to run under your credentials when it's executed. Then do your system call on this scrip and not the actual executable.
At least, I think it's a+s. It's been a while.
Code: Select all
#!/bin/sh
echo `df -k`
exit 0At least, I think it's a+s. It's been a while.
I know can use shell script to excute common command,but if this command is the special command ,eg.fdisk -l hda,which only access or excute by root, it's can't work either in php file or shell script.
Because my apache run in nobody,haven't power run these comands,so i want to let this user ,eg.nobody,to become the user which have same privilege ,how can i do it?[/b]
Because my apache run in nobody,haven't power run these comands,so i want to let this user ,eg.nobody,to become the user which have same privilege ,how can i do it?[/b]
You can't run Apache as root unless you recompile and specify that it can run as root. I know there are ways to make perl/cgi's run as root but I'm not sure how. So far I haven't been able to get a PHP script to run as root under Apache and haven't gotten much feedback on the subject.
Sorry that I couldn't be more helpful.
G
Sorry that I couldn't be more helpful.
G
But my project must to go,so i'm plan to write a program to run as demon (it's run in root privilege),which creat a socket,through this socket interface ,it can communicate with php,get the user request ,then excute these request,return the result to web user.
what are you think about my new idea?
We did something similar. We have created a daemon that checks an apache database every so often (every 30 seconds). We have a table that contains a list of comamnds to be executed. Each entry in the database is an XML list of this to do.
We wen't with the database approach because we need to be able to use apache to make modifications to other machines. We we have the daemons listening on these "other" machines to a database on the master machine. The process that we have in place works great. If you need more detail PM me.
One of the goals that we needed to accomplish was to be able to change user passwords in PHP from a centralized server. At best we were hoping to to something like rsh but then we came with the idea above.
G-
We wen't with the database approach because we need to be able to use apache to make modifications to other machines. We we have the daemons listening on these "other" machines to a database on the master machine. The process that we have in place works great. If you need more detail PM me.
One of the goals that we needed to accomplish was to be able to change user passwords in PHP from a centralized server. At best we were hoping to to something like rsh but then we came with the idea above.
G-
meet New problem
I meet a problem now, the detail is this:In my web page,i am send a IP address to apache server and call a php page,this page open a socket and send "ifconfig eth0 $ip " to my demon ,then demon change the machine's ip and return success to php,but you know the IP my exploer access previously is not The IP now,so my exploer will be error,it don't get any page.I am try to call header() to redirector new IP address,but it's not work. Are you understand my problem? Can you give me some help ?