System() and Exec() Not Working?

Whether you are using Linux on the desktop or as a server, it's still good that you're using Linux. Linux related questions go here.

Moderator: General Moderators

Post Reply
Vik
Forum Newbie
Posts: 13
Joined: Sun May 23, 2004 1:12 pm
Location: Los Angeles, CA

System() and Exec() Not Working?

Post by Vik »

When executed from the terminal, the following command works perfectly:

gnuplot '/Applications/IPG/htdocs/ftp/company_name/Charts/gnuPlotCommandFile.gp'

However, when I run it from inside PHP with:

exec("gnuplot '/Applications/IPG/htdocs/ftp/company_name/Charts/gnuPlotCommandFile.gp'");

...or:

system("gnuplot '/Applications/IPG/htdocs/ftp/company_name/Charts/gnuPlotCommandFile.gp'");

...nothing seems to happen. How can I correct this?

Note - exec is enabled on my system, according to the following function:

function exec_enabled() {
$disabled = explode(', ', ini_get('disable_functions'));
return !in_array('exec', $disabled);
}

Thanks very much in advance to all for any info.
Doug G
Forum Contributor
Posts: 282
Joined: Sun Sep 09, 2007 6:27 pm

Re: System() and Exec() Not Working?

Post by Doug G »

There are many possible reasons for the failure, probably all permissions related in one way or another. Start by reviewing the server logs for any error messages that help you identify the problem. Maybe your server php has an open_basedir restriction, more likely the web server user doesn't have permission to run the script.
Vik
Forum Newbie
Posts: 13
Joined: Sun May 23, 2004 1:12 pm
Location: Los Angeles, CA

Re: System() and Exec() Not Working?

Post by Vik »

I am running Apache via MAMP, a local amp stack running on my development system on my iMac. I am running MAMP and the Terminal in my own user account. Will Apache have different permissions for accessing files on the disk, than I have when I am running a command via the Terminal?
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: System() and Exec() Not Working?

Post by VladSun »

Vik wrote:Will Apache have different permissions for accessing files on the disk, than I have when I am running a command via the Terminal?
Yes.

Try debugging it:

Code: Select all

echo exec("gnuplot '/Applications/IPG/htdocs/ftp/company_name/Charts/gnuPlotCommandFile.gp' 2>&1");
Also, always use absolute paths, including the command itself (i.e. gnuplot in this case)
There are 10 types of people in this world, those who understand binary and those who don't
Vik
Forum Newbie
Posts: 13
Joined: Sun May 23, 2004 1:12 pm
Location: Los Angeles, CA

Re: System() and Exec() Not Working?

Post by Vik »

That solved it! Using the exec command per your sample code revealed the error "sh: gnuplot: command not found". Providing full path to gnuplot, (on my system, "/usr/local/bin/gnuplot"), then fixed that. It's working now. I really appreciate your help. Thanks very much!
Post Reply