簡體   English   中英

Heroku PHP應用程序在本地工作,如果我推送供應商目錄,則在部署時工作,但如果我不推送供應商目錄則不行

[英]Heroku PHP app works locally, and works when deployed if I push vendor dir, but not if I don't push vendor dir

這對我來說非常困惑。 我已經構建了一個簡單的heroku應用程序。 它在當地工作正常。 它實際上在Heroku上工作正常如果我推送供應商目錄,但然后heroku警告我,我不應該推送作曲家供應商目錄。 該消息將我指向一個鏈接,指示我將composer.lock文件用於依賴項。 所以我添加了一個.gitignore來忽略供應商目錄並再次推送,但是當我這樣做時,該應用程序無效。 我檢查了heroku遠程的文件結構,看起來依賴關系安裝正確,但應用程序不起作用。 我試圖以正確的方式做到這一點,所以我真的希望這個工作,即使我知道我可以推送我的供應商文件夾,它會工作。 有沒有遇到過這個?

這是我的composer.json文件中的代碼

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

和我的Procfile

web: vendor/bin/heroku-php-apache2

我嘗試加載頁面時得到的錯誤非常通用

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

這是heroku日志

    $ 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

這是我在包含供應商文件夾時得到的輸出,當我這樣做時,該應用實際上是有效的。 我想現在我只是讓它成為,因為它正在工作,但知道如何以正確的方式做到這將是很好的。 當heroku安裝依賴項時,自動加載必須存在某種文件結構問題。

$ 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

事實證明,這更多地與文件結構有關。 我的index.php是我的應用程序的根源。 當我在Heroku上實際查看文件結構時,我意識到Heroku期待不同的東西。 所以基本上自動加載由於目錄結構而無法正常工作。 我重新構建了將我的html文件放在/ public目錄中,並將我的vendor文件夾保留在根目錄下。 現在它完美無缺,我不需要上傳供應商目錄。 我的文件結構現在看起來像這樣:

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

我的Procfile只有這一行:

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

最后,只需確保/ public目錄下的php文件中的某個級別可以獲取根目錄和子文件夾中的php文件。 這條線看起來像:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM