1

I got some PHP application on Heroku. While I enable PHP, I also run this command, which I've found somewhere at Stackoverflow:

heroku config:add LD_LIBRARY_PATH=/app/php/ext:/app/apache/lib
Setting config vars and restarting zfq... done, v7
LD_LIBRARY_PATH: /app/php/ext:/app/apache/lib

This command from command line works fine:

heroku run ./php/bin/php -v
Running `./php/bin/php -v` attached to terminal... up, run.3208
PHP 5.3.10 (cli) (built: Mar 26 2012 08:15:52)
Copyright (c) 1997-2012 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2012 Zend Technologies

But this code:

$nickname = $_POST['nickname'];
$filename = "1.txt";
$cmd      = './php/bin/php -v > "' . $filename . '" 2>&1 &';

exec($cmd, $output);
$contents = file_get_contents($filename);
unlink($filename);

exit_ajax($contents);

returns sh: ./php/bin/php: not found

If i change ./php/bin/php to ~/php/bin/php - it returns false

To ./php - returns sh: ./php: not found

Community
  • 1
  • 1
csharp newbie
  • 647
  • 1
  • 12
  • 31
  • Please verify the placed link is where you obtained that from. Then please explain why you added that in specific and what does it do? Then please tell if you execute that code locally on your box or on Heroku. Also I've removed superfluous code, please check that. Also please say what your question is. And if I may ask, why do you expect that `./php/bin/php` is a PHP binary? – hakre Jul 22 '13 at 11:06
  • At my localhost it worked fine with just `php -v ...` command. At terminal, using Heroku toolbelt, `./php/bin/php` also worked (actually i dont know why, because of that ./ in the beginning, telling look for php/bin folder in current folder). My question was - why from terminal same command works, and from php exec - it doesn't. 5 minutes ago i've finally found correct path to php binary - it is `../php/bin/php`. And this http://pastebin.com/6rURR0M3 garbage code works. Now i'm trying to guess, why pretty same code, but in ajax request, doesnt works. But it actually another question to talk. – csharp newbie Jul 22 '13 at 12:30
  • And sorry, i don't get what link and form you wrote me about. – csharp newbie Jul 22 '13 at 12:31
  • link is: http://stackoverflow.com/questions/13792556/herokus-windows-toolbelt-and-ld-library-path - Try the full path to the PHP binary from your PHP script. If you say `../php...` works, then the full path is relative to the script you call it from (or from apache, depends a bit). Try to find out more. – hakre Jul 22 '13 at 12:31
  • 1
    Also keep in mind that heroku has got limitations with the file-system: https://devcenter.heroku.com/articles/read-only-filesystem / https://devcenter.heroku.com/articles/dynos#ephemeral-filesystem – hakre Jul 22 '13 at 12:34
  • Then i should use ../tmp/$filename path to any temporary created files? – csharp newbie Jul 22 '13 at 12:38
  • I don't know from top of my head, but using temp is a good idea on heroku IIRC. – hakre Jul 22 '13 at 12:53

2 Answers2

0

that works fine

$cmd = "/app/php/bin/php -v " ...
nkj
  • 81
  • 1
  • 5
  • Gives me `sh: ./app/php/bin/php: not found ` – csharp newbie Jul 18 '13 at 09:54
  • 1
    that's odd, i gave you absolute path, without leading dot – nkj Jul 18 '13 at 10:19
  • Hmm, i've copy-pasted that, but now i see a dot there... Whatever, w/o dot its returns nothing, empty string. Command is `'/app/php/bin/php -v > "' . $filename . '" 2>&1 &'` – csharp newbie Jul 18 '13 at 10:24
  • 1
    [btw](http://stackoverflow.com/a/12418985/2470264), it seems that you write and then read command output, maybe it'd be better to directly use the output – nkj Jul 18 '13 at 11:22
  • Firstly it was running some script, which parse some urls and write some data into that file. It was running good at localhost, but when i've upload it to heroku, troubles began. So i've simpilfied and commented code as much as possible, finally removed old command and putting some test output. – csharp newbie Jul 18 '13 at 11:36
0

Use /app/php/bin/php and not ./app/php/bin/php

Both are different, as the latter will search for /app folder within the document root, which is /app/www/, and hence wont find app folder within /app/www/

Robin Thomas
  • 1,317
  • 8
  • 15