Can't find a Perl script from PHP/Apache

428 Views Asked by At

From a PHP script I want to run a Perl script. I can do this fine from the terminal (as root user) but when run from my application (www-data user) I can't.

When developing the application on localhost I was able to do this fine as well, but the problem appeared when I switched to another server.

My webpage calls the PHP script with an AJAX POST request, which works fine for my other PHP scripts that do not make calls to Perl.

I have tried the following commands in my PHP script with no success:

system("/filepath/file.pl");
exec("/filepath/file.pl");
passthru("/filepath/file.pl");

The Apache logs on the server hosting my application show the following error:

sh: /file.pl: not found

From running the following code on my server I see that the web user is seen as www-data:

ps aux | grep apache

To test, I have also set the permissions for all files and directories use by my application to allow any type of access by any user, using chmod 777.

Please note: my application is only available to certain users (I use a .htaccess file to set these permissions and require the user to login) so if there is a way to change how the server sees this user (from www-data, to the credentials of the logged-in user) then perhaps that would help - how would I do this?

2

There are 2 best solutions below

0
On

Thanks for all the suggestions! In the end, it was a problem with security settings in the php.ini file in the Apache directory on the server hosting my application:

/etc/php5/apache2/php.ini

Safe mode was set to 'on', which was preventing php files to access/execute any local files. (The PHP script was also failing when attempting access to another, not-script, file: other.html).

To solve this without removing the safe mode setting for all applications on my server, I changed the above php.ini file to include the following:

safe_mode: on
safe_mode_include_dir: /filepath
safe_mode_exec_dir: /filepath

More information on these config variables can be found here: http://php.net/manual/en/ini.sect.safe-mode.php

1
On

Try something like this

exec("/usr/bin/perl /full-path/script.pl",$output);