The problem is faced while running node command (which generates PDF file for given link) on Linux through PHP exec/passthru/system functions. Actually, I am trying to create PDF file through headless chrome using Puppeteer node module. Everything worked fine in Windows system but as soon as the same code was moved on production server (which uses Linux), the exec/passthru commands began to throw 127 return code errors. Please note that same node command works without any problem when run directly on terminal .
Also, Apache has write permissions in directory where file is being generated and command was also tried by giving the absolute paths but nothing seems to be working
The format of command is like this
"node script-generating-code.js http://www.url-of-page.com/"
Related
I have a design tool extension that is used on a website I'm working on. The design tool uses inkscape command line to export images. There is a php interface to work with the command line operations which ultimately calls shell_exec($inkscapeCmd). After noticing the image files weren't being exported, I created a few tests to try and debug. I changed the execute line to shell_exec($inkscapeCmd . ' 2>&1') in order to see the error message:
sh: inkscape: command not found
...which is odd since it's definitely installed and accessible. I added a check for the user on my test page to make sure the commands were being executed by a user with access to inkscape:
$processUser = posix_getpwuid(posix_geteuid());
echo 'user: ' . $processUser['name'];
Then I ssh'd into the server to confirm that I could run the same commands as that user, and was able to run them without any issues (which also confirmed inkscape was in the PATH). I'm able to run other, basic shell commands from PHP without issue, like so:
echo shell_exec('ls');
But now I'm at a loss; I'm not sure what else to check to determine why I'm getting the 'command not found' error. Any direction would be helpful.
The server (rather old, I know):
CentOS 6.7
PHP 5.3.3
Inkscape v0.47
The process does not have the location for inkscape in it's path.
You will have to supply to full path to the executable.
Example
/usr/bin/inkscape
At the command line type 'whereis inkscape' to find is location.
I'm trying to make a hook on bitbucket, that executes a php file, and this file executes the pull command:
shell_exec('/usr/local/cpanel/3rdparty/bin/git pull');
The pull command works fine on the SSH console, but the PHP returns the error:
Permission denied (publickey). fatal: Could not read from remote
repository.
Please make sure you have the correct access rights and the repository
exists.
The command --version shows the path to git is right, whoiami returns the same user on both, so I don't know if it is a permission issue.
What can be going wrong?
Edit: An additional issue: the alias I added for git don't work on PHP, only the full path as above. Via terminal it works just fine. Maybe it's the same reason why the key don't work in php.
Edit 2: $PATH is different on both.
When you run this command within a PHP script you are not running the command as yourself:
shell_exec('/usr/local/cpanel/3rdparty/bin/git pull');
The reason it works from the terminal console is you run the command as yourself from the console. But on a web server, you are not the user running the command. Remember: When you run PHP on a web server, it is a an Apache module. Meaning the web server user—which could be www-data, root or even apache on some systems—is running the PHP script which then runs the shell_exec command.
So it would never work as you have it setup. Perhaps you can kludge something together that would allow a key-pair to be used by the web server for these purposes, but that seems like a security risk waiting to happen.
I have a problem trying to compile a directory of coffescript files from php. The code looks something like this:
$output = exec_shell("/usr/bin/coffee -c -o public/javascript public/coffeescript");
/usr/bin/coffee is a symblic link to /usr/local/lib/node_modules/coffee-script/bin/coffee, but I've also tried directly using the complete path to the executable.
I've tried all php shell commands I know of (system, passthru, exec, exec_shell).
MAMP is running Apache as my user on Mac OS X.
I'm doing the same thing with compass, which works perfectly (without absolute path, even), and they are both installed using node with -g.
I'm trying to achieve on-demand compilation on page request in a development environment, but now I'm completely stumped.
Any insight into this will be greatly appreciated.
I've installed the LibreOffice RPMS (have tried both 3.5.3 and 3.4.6) on my CentOS machine, and I'm trying to make PHP run a shell script that calls LibreOffice. In the shell script, it runs executes this line:
/opt/libreoffice3.4/program/soffice --headless -convert-to $extension.pdf "$1" -outdir $folder
However, this command will cause the following message to appear:
./createpdf.sh: line 8: /opt/libreoffice3.4/program/soffice: Permission denied
The line itself is fine. If I echo it and run it manually in SSH, it works fine. This is most likely because I'm running it as a different user (note: not as the user that installed it, and not as root), with different permissions.
Desperate as I was, I've already tried chmodding the entire libreoffice folder to 777, and tried to make the 'apache' user the owner. No luck there. Would anyone have a clue as to why it's not letting apache run it, and how I can solve this?
As an alternative to running from the command line, have you considered running UNO (the Open/Libre Office alternative to COM) with the PUNO PHP wrapper. That way, you don't need to worry about permissions
See also Universal Network Objects (UNO): there are Python, Java, etc. bridges for use it. There are applications for simplify the use for convertions, see Docvert and JODConverter (jODconverter and pyODconverter).
All of then can be called as web-service or exec by PHP.
I'm attempting to run an application on the server, invoking it from PHP using the following code.
$application = "D:\\Program Files (x86)\\ScanBoy\\DM ScanBoy.exe";
exec($application);
Right now the application is 'run' however it crashes instantly. If I just run the application (by double clicking the exe) it runs and everything is fine.
When the application crashes the only error I get is
"{application name} has stopped working. Windows is checking for a
solution to the problem"
I have had this problem with running application via c# backend to a ASP.NET page. The solution there was to set the Working Directory. However in php / exec I am unaware of how to set this option.
Any help please?
You can either:
Use exec("cd myworkdir/ && D:\\Program Files (x86)\\ScanBoy\\DM ScanBoy.exe"); to change the working directory for that exec command (only)
Use the php chdir() function to change the working directory of the php process.
You can find chdir documentation here:
http://php.net/manual/en/function.chdir.php
You can chdir() to change current working directory