call shell script from php exec()

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
catgovind
Forum Newbie
Posts: 2
Joined: Tue May 27, 2008 2:35 pm

call shell script from php exec()

Post 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
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: call shell script from php exec()

Post 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.
There are 10 types of people in this world, those who understand binary and those who don't
catgovind
Forum Newbie
Posts: 2
Joined: Tue May 27, 2008 2:35 pm

Re: call shell script from php exec()

Post 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
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: call shell script from php exec()

Post 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?
There are 10 types of people in this world, those who understand binary and those who don't
Post Reply