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?
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:
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:
More information on these config variables can be found here: http://php.net/manual/en/ini.sect.safe-mode.php