尝试使用“heroku run”运行php文件,我得到“bash权限被拒绝”[关闭]

问题描述:

I'm trying to run a file with heroku run path/to/file.php and I get a reponse:

bash: path/to/file.php: Permission denied

I've tried chmod 755 on the file and directory, but it seems that heroku changes it back to 600... After running chmod 755 it shows 755, but then when I exit bash and then come back the permissions are reset to 600.

What am I missing?

Also some people have suggested heroku run php path/to/file.php but I get an error saying bash: php: command not found

我正在尝试使用 heroku run path / to / file.php code运行文件 >我收到了回应: p>

bash:path / to / file.php:Permission denied code> p>

我' 我在文件和目录上尝试了chmod 755,但似乎heroku将其更改为600 ...运行chmod 755后显示755,但是当我退出bash然后再返回时,权限将重置为600。 p>

我错过了什么? p>

也有人建议 heroku运行php path / to / file.php code>但是我收到一条错误,说 bash:php:command not found p> div>

There are a couple of things you need to do.

  • When creating the Heroku application, you have to make sure that the PHP buildpack is used. This is what will inject the PHP runtime into your application slug. Either add a index.php file (which is how PHP is detected) or hard-code it like this: heroku config:add BUILDPACK_URL=https://github.com/heroku/heroku-buildpack-php.git
  • Set the library path as detailed in this question: heroku config:add LD_LIBRARY_PATH=/app/php/ext:/app/apache/lib
  • Run your stuff: heroku run ./php/bin/php --version

To sum up:

heroku config:add BUILDPACK_URL=https://github.com/heroku/heroku-buildpack-php.git
heroku config:add LD_LIBRARY_PATH=/app/php/ext:/app/apache/lib
heroku run ./php/bin/php --version

A useful way to debug this is to bash into the running Heroku dyno: heroku run bash. That will let you poke around, see where things are at and experiment.

Have you tried running the command with sudo privileges:

sudo heroku run path/to/file.php

If your shell can't use the php command (i.e. its alias), you will need to provide the absolute path:

sudo /usr/bin/php path/to/file.php 

That's where it's usually located. To find your PHP bin location, try:

whereis php