dousi2553 2019-04-26 18:30 采纳率: 0%
浏览 96
已采纳

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.
HTTP ERROR 500

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="174.65.133.198" 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]: 10.51.197.106 - - [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:
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:
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:
remote: -----> Installing dependencies...
remote:        Composer version 1.8.4 2019-02-11 10:52:10
remote:
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:
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:
remote: -----> Compressing...
remote:        Done: 16.2M
remote: -----> Launching...
remote:        Released v3
remote:        https://cloud-buddy.herokuapp.com/ deployed to Heroku
remote:
remote: Verifying deploy... done.
To https://git.heroku.com/cloud-buddy.git
 * [new branch]      master -> master
  • 写回答

1条回答

  • duanchandun1860 2019-05-02 15:04
    关注

    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:

    .git
    public
    --index.php
    src
    vendor
    --autoload.php
    composer.json
    composer.lock
    Procfile
    

    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';
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 本题的答案是不是有问题
  • ¥15 关于#r语言#的问题:(svydesign)为什么在一个大的数据集中抽取了一个小数据集
  • ¥15 C++使用Gunplot
  • ¥15 这个电路是如何实现路灯控制器的,原理是什么,怎么求解灯亮起后熄灭的时间如图?
  • ¥15 matlab数字图像处理频率域滤波
  • ¥15 在abaqus做了二维正交切削模型,给刀具添加了超声振动条件后输出切削力为什么比普通切削增大这么多
  • ¥15 ELGamal和paillier计算效率谁快?
  • ¥15 蓝桥杯单片机第十三届第一场,整点继电器吸合,5s后断开出现了问题
  • ¥15 file converter 转换格式失败 报错 Error marking filters as finished,如何解决?
  • ¥15 Arcgis相交分析无法绘制一个或多个图形