Jump to content

PHP Code to Execute Command on Linux Server


tom.park89

Recommended Posts

Hi Guys,

 

I'm trying to find a way to run a simple bit of code on My Debian Linux Server using PHP. I wan't to run the following Comannd '/etc/init.d/squid restart'.

 

I currently haven't been able to fingure out how to do this. I'm hoping that someone on this forum can help me with thsi.

 

Regards

Thomas

 

I could use something like

shell_exec('/etc/init.d/squid restart'); or something like this

shell_exec('echo "password of root account" | -U root -S /etc/init.d/squid restart');

 

Also is there a way to catch any erros and display them to the screen. A user has to login to the page before they can run the command anyway.

 

Regards

 

 

That second one I was given by someone else on another forum. I didn't think it looked right. I am a little new to Linux as in I have never granted access for server processes before. I know how to use sudo to install programs and change file permisions, restart services etc but never given access to processes before how would I go about doing this? or where could I find the info on how to do this?

 

also with the shell_exec command how do I output the responce to the screen?

 

Regards

  Quote
I know how to use sudo to install programs and change file permisions, restart services etc but never given access to processes before how would I go about doing this? or where could I find the info on how to do this?

 

Depending on your distro the /etc/sudoers file should be pretty well commented. You can give certain user access to sudo specific commands. You will also need to allow this user to execute sudo without being prompted for a password.

 

There is a good example here: http://www.gratisoft.us/sudo/sample.sudoers which is the first Google result I found.

 

  Quote
also with the shell_exec command how do I output the responce to the screen?

echo shell_exec($cmd);

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.