lara1376's avatar

Deployment broken when upgrading to Laravel 5.1

Hi there,

I've upgraded my app from Laravel version 5.0 to 5.1. Locally, all my unit tests have passed so I deployed to Heroku and all is seemingly well until I hit a page where one of the methods from Carbon is called.

Here's the error from the logs:

PHP Fatal error:  Carbon\Carbon::setLocale(): Failed opening required '/tmp/build_dd40f31f287e50a947b28cc04088e5dc/vendor/nesbot/carbon/src/Carbon/Lang/en.php' (include_path='.:/app/.heroku/php/lib/php') in /app/bootstrap/cache/compiled.php on line 17053

I've tried running composer update, php artisan clear-compiled and php artisan optimize but still getting the same error.

Could anyone help?

0 likes
11 replies
bashy's avatar

Seems silly but have you actually checked that that file exists?

ls -lah /tmp/build_dd40f31f287e50a947b28cc04088e5dc/vendor/nesbot/carbon/src/Carbon/Lang/en.php
lara1376's avatar

@bashy, it's a good point - vendor/nesbot/carbon/src/Carbon/Lang/en.php exists but /tmp/build_dd40f31f287e50a947b28cc04088e5dc/vendor/nesbot/carbon/src/Carbon/Lang/en.php does not, or at least can't be accessed. Starting to think this a problem with Heroku's build...

bashy's avatar

Well where's the site files and why is it looking /tmp? :P

Sounds something along those lines. Probably nothing to do with Laravel as such!

lara1376's avatar

@bashy I have no idea - like I said this works fine locally so I imagine it's got to be something to do with the environment.

Thanks to all for taking a look.

ellefsen's avatar

I have the exact same issue, but I have also encountered this on Laravel 5.0 about a week ago. I don't believe it's related to the 5.1 release.

This doesn't happen every time I deploy to Heroku, but if the server sleeps and then boots back up it will fail. I've tried deploying the same site to a Forge server without every having any problems there. Maybe we should investigate the PHP Buildpack Env for Heroku instead.

Example from 5.0

Symfony\Component\Debug\Exception\FatalErrorException Carbon\Carbon::setLocale(): Failed opening required '/tmp/build_fb8c0b68de97f4785af889eccb527055/vendor/nesbot/carbon/src/Carbon/Lang/en.php' (include_path='.:/app/.heroku/php/lib/php')
    vendor/compiled.php:16900 [main]

Example from 5.1

Symfony\Component\Debug\Exception\FatalErrorException Carbon\Carbon::setLocale(): Failed opening required '/tmp/build_aef66afaec007c7450d823d387fc3a56/vendor/nesbot/carbon/src/Carbon/Lang/en.php' (include_path='.:/app/.heroku/php/lib/php')
    bootstrap/cache/compiled.php:17053 [main]

The new path to compiled.php introduced in 5.1 doesn't seem to make a difference.

zachleigh's avatar

I had the same problem so I went to the Laravel sorce code on git hub and compared the Carbon setLocale method against mine. My version didnt use an interface as a dependancy. So I changed it to require the interface and now its working fine. I dont know if this will solve your issue, but its worth looking into.

ellefsen's avatar

I found some more details about the issue here: https://discussion.heroku.com/t/laravel-5-carbon-file-include-failure/1112

The cause of the error is from when Heroku triggers composer install from with it's 'tmp/build_xxxxx' directory, then moves the application in to the '/app' directory. The 'vendor/compiled.php' file still contains this 'tmp/build_xxxxx' path even though the application has moved, which triggers this error.

I resolved it by adding a boot script to the Procfile

/app/support/app_boot.sh

#!/bin/bash

# Artisan commands
/app/.heroku/php/bin/php /app/artisan clear-compiled
/app/.heroku/php/bin/php /app/artisan optimize

# Boot up!
vendor/bin/heroku-php-nginx -C nginx_app.conf public/

Procfile

web: sh support/app_boot.sh
worker: php artisan queue:listen

This seems to have solved it for me.

lara1376's avatar
lara1376
OP
Best Answer
Level 1

Ok, heard back from Heroku support on this and they have created an issue on the Laravel repo.

Basically __DIR__ and __FILE__ differ when building and at runtime, so this is why it's trying to autoload a file which doesn't exist.

Quick fix is to remove php artisan optimize from the post-install-cmd and post-update-cmd blocks in composer.json.

"scripts": {
  "post-install-cmd": [
    "php artisan clear-compiled"
  ],
  "post-update-cmd": [
    "php artisan clear-compiled"
  ],

Then run heroku run composer update.

Hope this helps!

krob's avatar

@ellefsen to this day, this is the only solution that worked for me as well. Thank you so much, and everyone else, this guy knows his stuff. He solved a very big issue that I don't think heroku has actually documented anywhere. The process I used in my composer install, was

      "post-install-cmd": [
            "php artisan clear-compiled",
            "php artisan view:clear",
            "php artisan route:cache",
            "php artisan config:cache",
            "php artisan install:js:conf",
            "php artisan migrate"
        ],

and that always worked in my laradock container. I had to run each of those in a heroku_boot.sh file.

#!/bin/bash

# Artisan commands
/app/.heroku/php/bin/php /app/artisan clear-compiled
/app/.heroku/php/bin/php /app/artisan view:clear
/app/.heroku/php/bin/php /app/artisan route:cache
/app/.heroku/php/bin/php /app/artisan config:cache
/app/.heroku/php/bin/php /app/artisan install:js:conf
/app/.heroku/php/bin/php /app/artisan migrate

# Boot up!
vendor/bin/heroku-php-nginx -C heroku.nginx.conf public/

Please or to participate in this conversation.