Page 1 of 1

call shell script from php exec()

Posted: Tue May 27, 2008 3:12 pm
by catgovind
Hi,

I call a shell script through php.The shell script need root privelages,for this I edit the sudoers file and give the root permission to apache.
Every thing in the shell script working fine except the httpd restart.But when i run it from command lne its working fine.Here is my flow

my client.php in /var/www/html
passthru(" sudo /usr/bin/php -f /home/server.php"")

/home/server.php
exec("cd /home/gaea/shell/;sh LoginMysql.sh", $output ,$returnValue);

my shell script
..
/opt/tomcat/bin/startup.sh
/etc/init.d/httpd restart

apache log
caught SIGTERM, shutting down

please help me out this problem,sorry for my poor english

Thanks
Govindan

Re: call shell script from php exec()

Posted: Tue May 27, 2008 4:33 pm
by VladSun
1. I hope you gave root permission to apache only for executing this command with these parameters.
2. Could you explain what are you trying to achieve in general? Why you need the httpd service restarted, what does "sh LoginMysql.sh" do? Etc.

Re: call shell script from php exec()

Posted: Wed May 28, 2008 2:12 am
by catgovind
The shell script will create a new instance of tomcat,create a database in mysql and set the virtual host in httpd.conf file (listen the newly created tomcat ports).so I start the tomat and restart apache for configuration take effect.
when i run php -f /var/www/html/client.php .the shell script run successfully.The problem is run from browser only.i put exec("whoami") it display root.

Thanks
Govindan

Re: call shell script from php exec()

Posted: Wed May 28, 2008 5:36 am
by VladSun
I've never worked with tomcat, but maybe I'll be still in help:
http://httpd.apache.org/docs/2.0/vhosts/mass.html
Have you looked at it?