Heroku PHP应用程序在本地工作,如果我推送供应商目录,则在部署时工作,但如果我不推送供应商目录则不行

This is very confusing to me. I have built a simple heroku app. It works fine locally. It actually works fine on Heroku IF I push the vendor directory, but then heroku warns me that I should not push the composer vendor directory. The message directs me to a link that instructs me to use composer.lock file for dependencies. So I added a .gitignore to ignore the vendor directory and pushed again, but when I did that, the app doesn't work. I checked the file structure on the heroku remote and it appears dependencies were installed correctly, but the app doesn't work. I'm trying to do this the right way, so I really want this to work, even though I know I can just push my vendor folder and it will work. Has anyone encountered this?

Here is the code from my composer.json file

    "require": {
        "salesforce-mc/fuel-sdk-php": "1.2.2",
        "guzzlehttp/guzzle": "~6.0",
        "ext-soap": "*",
        "php": "7.1.28",
        "ext-mcrypt": "*"

and my Procfile

web: vendor/bin/heroku-php-apache2

The error I get when I try to load the page is pretty generic

This page isn’t working project.herokuapp.com is currently unable to handle this request.

Here are the heroku logs

    $ heroku logs
    2019-04-26T18:14:40.303998+00:00 app[api]: Initial release by user stan_alach@hotmail.com
    2019-04-26T18:14:40.888724+00:00 app[api]: Enable Logplex by user stan_alach@hotmail.com
    2019-04-26T18:14:40.888724+00:00 app[api]: Release v2 created by user stan_alach@hotmail.com
    2019-04-26T18:14:40.303998+00:00 app[api]: Release v1 created by user stan_alach@hotmail.com
    2019-04-26T18:15:12.000000+00:00 app[api]: Build started by user stan_alach@hotmail.com
    2019-04-26T18:15:21.000000+00:00 app[api]: Build succeeded
    2019-04-26T18:15:22.259480+00:00 heroku[web.1]: Starting process with command `vendor/bin/heroku-php-apache2`
    2019-04-26T18:15:20.868799+00:00 app[api]: Deploy 1f57bbb2 by user stan_alach@hotmail.com
    2019-04-26T18:15:20.868799+00:00 app[api]: Release v3 created by user stan_alach@hotmail.com
    2019-04-26T18:15:20.887739+00:00 app[api]: Scaled to web@1:Free by user stan_alach@hotmail.com
    2019-04-26T18:15:24.264059+00:00 app[web.1]: Optimizing defaults for 1X dyno...
    2019-04-26T18:15:24.284000+00:00 app[web.1]: 4 processes at 128MB memory limit.
    2019-04-26T18:15:24.288460+00:00 app[web.1]: Starting php-fpm...
    2019-04-26T18:15:26.290267+00:00 app[web.1]: Starting httpd...
    2019-04-26T18:15:26.665144+00:00 heroku[web.1]: State changed from starting to up
    2019-04-26T18:15:34.496861+00:00 heroku[router]: at=info method=GET path="/" host=cloud-buddy.herokuapp.com request_id=7fa87fe1-fb53-4ef6-ae75-f14488321528 fwd="" dyno=web.1 connect=0ms service=645ms status=500 bytes=169 protocol=http
    2019-04-26T18:15:34.495116+00:00 app[web.1]: [26-Apr-2019 18:15:34 UTC] PHP Fatal error:  Uncaught Error: Class 'FuelSdk\SQZL_ET_Client' not found in /app/index.php:18
    2019-04-26T18:15:34.495133+00:00 app[web.1]: Stack trace:
    2019-04-26T18:15:34.495135+00:00 app[web.1]: #0 {main}
    2019-04-26T18:15:34.495201+00:00 app[web.1]: thrown in /app/index.php on line 18
    2019-04-26T18:15:34.496655+00:00 app[web.1]: - - [26/Apr/2019:18:15:33 +0000] "GET / HTTP/1.1" 500 - "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.108 Safari/537.36
    2019-04-26T18:16:07.874786+00:00 app[api]: Starting process with command `bash` by user stan_alach@hotmail.com
    2019-04-26T18:16:10.152678+00:00 heroku[run.9911]: State changed from starting to up
    2019-04-26T18:16:10.244363+00:00 heroku[run.9911]: Awaiting client
    2019-04-26T18:16:10.279025+00:00 heroku[run.9911]: Starting process with command `bash`
    2019-04-26T18:20:32.049330+00:00 heroku[run.9911]: State changed from up to complete
    2019-04-26T18:20:32.028902+00:00 heroku[run.9911]: Process exited with status 0

Here is the output I get when I include the vendor folder, and when I do this, the app actually works. I guess for now I'll just let it be, since it's working, but it would be nice to know how to do it the proper way. There must be some sort of file structure issue with the autoload that is not resolving itself when heroku installs the dependencies.

$ git push heroku master
Enumerating objects: 612, done.
Counting objects: 100% (612/612), done.
Delta compression using up to 8 threads
Compressing objects: 100% (595/595), done.
Writing objects: 100% (612/612), 1.08 MiB | 307.00 KiB/s, done.
Total 612 (delta 247), reused 0 (delta 0)
remote: Compressing source files... done.
remote: Building source:
remote: -----> PHP app detected
remote: -----> Bootstrapping...
remote: -----> Installing platform packages...
remote:        - php (7.1.28)
remote:        - ext-mcrypt (bundled with php)
remote:        - ext-soap (bundled with php)
remote:        - apache (2.4.39)
remote:        - nginx (1.14.2)
remote:  !     WARNING: Your app's PHP version is no longer actively maintained
remote:  !
remote:  !     Only security updates will be provided for your PHP version
remote:  !     series by the PHP Group until its end-of-life on 2019-12-01.
remote:  !
remote:  !     It is strongly recommended you update your app to a version of
remote:  !     PHP with "active support" status immediately to ensure you get
remote:  !     the latest bugfixes and security updates each time you deploy.
remote:  !
remote:  !     You may check the list of versions supported by the PHP Group
remote:  !     and their EOL dates here: http://php.net/supported-versions.php
remote:  !
remote:  !     For a list of supported runtimes & extensions on Heroku, please
remote:  !     refer to: https://devcenter.heroku.com/articles/php-support
remote: -----> Installing dependencies...
remote:        Composer version 1.8.4 2019-02-11 10:52:10
remote:  !     WARNING: Composer vendor dir found in project!
remote:  !
remote:  !     Your Git repository contains Composer's 'vendor' directory.
remote:  !
remote:  !     This directory should not be under version control; only your
remote:  !     'composer.json' and 'composer.lock' files need to be added, as
remote:  !     Composer will handle installation of dependencies on deploy.
remote:  !
remote:  !     To suppress this notice, first remove the folder from the index
remote:  !     by running 'git rm -r --cached vendor/'.
remote:  !     Next, edit your project's '.gitignore' file and add the folder
remote:  !     '/vendor/' to the list, then commit the changes.
remote:  !
remote:  !     For more info, refer to the Composer FAQ: 
remote:        Loading composer repositories with package information
remote:        Installing dependencies from lock file
remote:        Nothing to install or update
remote:        Generating optimized autoload files
remote: -----> Preparing runtime environment...
remote: -----> Checking for additional extensions to install...
remote: -----> Discovering process types
remote:        Procfile declares types -> web
remote: -----> Compressing...
remote:        Done: 16.2M
remote: -----> Launching...
remote:        Released v3
remote:        https://cloud-buddy.herokuapp.com/ deployed to Heroku
remote: Verifying deploy... done.
To https://git.heroku.com/cloud-buddy.git
 * [new branch]      master -> master
douping3891 用日志更新
一年多之前 回复
dongsonghen9931 请检查heroku日志
一年多之前 回复
duanniling0018 来自heroku的任何消息记录--tail?
一年多之前 回复
douchongbang6011 感谢您的答复。我在本地运行了一个composer安装。当我推送到heroku时,CLI告诉我正在安装依赖项,所以我没有在远程运行一个(我也不知道如何)。我将用错误更新帖子。
一年多之前 回复
doucheng7808 另外,我假设您已经运行了作曲家安装?
一年多之前 回复
douniuta4783 你得到了什么错误?正在创建的供应商目录是否与您在本地的路径相同?
一年多之前 回复


事实证明,这更多地与文件结构有关。 我的index.php是我的应用程序的根源。 当我在Heroku上实际查看文件结构时,我意识到Heroku期待不同的东西。 所以基本上自动加载由于目录结构而无法正常工作。 我重新构建了将我的html文件放在/ public目录中,并将我的vendor文件夹保留在根目录下。 现在它完美无缺,我不需要上传供应商目录。 我的文件结构现在如下所示:</ p>

  • index.php src vendor
  • autoload.php
    composer .lock
    </ code> </ pre>

    我的Procfile只有这一行:</ p>

      web:vendor / bin /  heroku-php-apache2 public / 
     code>  pre> 

    最后,确保在/ public目录下的php文件中升级到一级以获取php文件 根和子文件夹。 所以该行看起来像: p>


    </ div>



Turns out, this had more to do with file structure. My index.php was at the root of my application. When I actually viewed file structure on Heroku I realized that Heroku was expecting something different. So basically the autoload wasn't working properly because of the directory structure. I restructured to put my html files in a /public directory and left my vendor folder at the root. Now it works flawlessly and I don't need to upload the vendor directory. My file structure now looks like this:


and my Procfile just has this one line:

web: vendor/bin/heroku-php-apache2 public/

And finally, just make sure that in your php files within the /public directory go one level up to get to php files in the root and subfolders. So that line looks like:

require '../vendor/autoload.php';

Csdn user default icon