LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 12-27-2005, 01:54 PM   #1
abdul_zu
Member
 
Registered: Feb 2005
Posts: 71

Rep: Reputation: 15
PHP executing System command


Hi All,

I was trying to execute some linux command using PHP but i found that from html folder i cannot execute all linux command. I have my Asterisk running on the Same Server, i wanted to check it from web browser using PHP if asterisk not working the system function of PHP will start my asterisk.

But i think i cannot run full command from PHP uising web browser. here is the code which i was trying to run.

PHP Code:

<?php
echo '<pre>';
$last_line system('asterisk''-rx'$retval");
echo '
</pre>
<hr />Last line of the output: ' . 
$last_line . '
<hr />Return value: ' . 
$retval;
?>
Can anyone help me how i can give this file for root access permission?
 
Old 12-27-2005, 03:10 PM   #2
bulliver
Senior Member
 
Registered: Nov 2002
Location: Edmonton AB, Canada
Distribution: Gentoo x86_64; Gentoo PPC; FreeBSD; OS X 10.9.4
Posts: 3,760
Blog Entries: 4

Rep: Reputation: 78
Check your php.ini file. You are almost certainly in "Safe mode", in which any executables you wish to run from a 'system' or exec' call must be in a "safe_mode_exec_dir"

See this for more info:
http://ca.php.net/manual/en/features.safe-mode.php
 
Old 12-28-2005, 01:28 AM   #3
abdul_zu
Member
 
Registered: Feb 2005
Posts: 71

Original Poster
Rep: Reputation: 15
Hi bulliver,

I put my php script path in safe_mode_exec_dir but still i am not able to execute.

This is my php.ini

Quote:
safe_mode = Off
safe_mode_gid = Off
safe_mode_include_dir =
safe_mode_exec_dir = /var/www/html/asterisk/gui
And this is my PHP script.

PHP Code:
echo '<pre>';

$last_line system('ps -aux|grep asterisk'$retval); #Working

$last_line system('asterisk -rc reload'$retval); #Not working

echo '
</pre>
<hr />Last line of the output: ' 
$last_line '
<hr />Return value: ' 
$retval
Any idea please?

Last edited by abdul_zu; 12-28-2005 at 01:29 AM.
 
Old 12-28-2005, 06:33 AM   #4
Guttorm
Senior Member
 
Registered: Dec 2003
Location: Trondheim, Norway
Distribution: Debian and Ubuntu
Posts: 1,453

Rep: Reputation: 447Reputation: 447Reputation: 447Reputation: 447Reputation: 447
My guess is that the PATH environment variable does not include the directory where asterisk is. Could also be that the Apache web server user doesn't have rights to run it.

I'd try a
which asterisk
to find out where it is, and supply a full path in the system statement.
 
Old 12-28-2005, 02:14 PM   #5
abdul_zu
Member
 
Registered: Feb 2005
Posts: 71

Original Poster
Rep: Reputation: 15
Hello,

Still the problem is not solved. may be i am putting the value in wrong variable, please give me the variable name where i should modify.

[root@hatifserver5 sbin]# which asterisk
/usr/sbin/asterisk
[root@hatifserver5 sbin]#

Script path: /var/www/html/asterisk/gui

I did the new following modification.

Code:
safe_mode = Off
safe_mode_gid = Off
safe_mode_include_dir = /usr/sbin/asterisk
safe_mode_exec_dir = /var/www/html/asterisk/gui
safe_mode_allowed_env_vars = /usr/sbin/asterisk
Thak You
Abdul Lateef
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP not Executing Sometimes Herbalist Programming 3 06-20-2005 07:41 PM
How executing c program with php? payal_shah Programming 6 04-08-2005 10:44 PM
executing from command line nodger Linux - Newbie 3 01-20-2004 10:30 AM
Executing Javascript within a PHP page Linh Programming 3 09-26-2003 05:08 PM
Executing command lines in C/C++ ReverseLogic Programming 2 05-28-2002 02:08 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 11:34 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration