I am trying to deploy a Laravel app to Heroku. I am getting an error relating to a custom compile script in composer.json:
Running 'composer compile'...
remote: > #php -d phar.readonly=0 bin/compile > ~/log.txt
remote: Script #php -d phar.readonly=0 bin/compile > ~/log.txt handling the compile event returned with error code 1
remote:
remote: ! ERROR: Compile step failed!
remote: !
remote: ! Installation of dependencies was successful, but the custom
remote: ! script you're using to perform actions after 'composer install'
remote: ! failed with the error above.
remote: !
remote: ! Check that the 'compile' command(s) in the 'scripts' section of
remote: ! your 'composer.json' are working properly and not running into
remote: ! timeouts or memory limits.
The scripts section of composer.json looks like this:
"scripts": {
"compile": "#php -d phar.readonly=0 bin/compile",
"test": "simple-phpunit"
}
I have no idea what bin/compile is or if it even exists. I took over this project from someone who did not document any of their code so I am struggling to put the pieces together.
Related
I am getting the below error when trying to deploy my Laravel app to heroku. Has anyone experienced this error before?
Running 'composer compile'...
remote: > #php -dphar.readonly=0 bin/compile
remote: Could not open input file: bin/compile
remote: Script #php -dphar.readonly=0 bin/compile handling the compile event returned with error code 1
remote:
remote: ! ERROR: Compile step failed!
remote: !
remote: ! Installation of dependencies was successful, but the custom
remote: ! script you're using to perform actions after 'composer install'
remote: ! failed with the error above.
remote: !
remote: ! Check that the 'compile' command(s) in the 'scripts' section of
remote: ! your 'composer.json' are working properly and not running into
remote: ! timeouts or memory limits.
remote: !
remote: ! For more information on the 'composer compile' step, refer to
remote: ! https://devcenter.heroku.com/articles/php-support
remote: !
remote: ! REMINDER: the following warnings were emitted during the build;
remote: ! check the details above, as they may be related to this error:
remote: ! - Your 'composer.lock' is out of date!
remote:
remote: ! Push rejected, failed to compile PHP app.
Compile Script:
"scripts": {
"compile": "#php -dphar.readonly=0 bin/compile"
}
I am trying to take a laravel project from a server and move it to heroku following all the provided steps, when pushing the repo to heroku, I encounter the following error :
Compiling common classes
remote:
remote:
remote: [ErrorException]
remote: Invalid characters passed for attempted conversion, these have been ignored
I have been looking at a guthub issue that states this error - [PHP 7.4 RC3] Invalid characters passed for attempted conversion, these have been ignored #2003 - Which is one of the few answers I can find.
However the file this issue is referencing does not exist in my project (vendor/dompdf/dompdf/lib/Cpdf.php).
One of the answers suggested turning off error reporting by adding error_reporting(E_ALL ^ E_DEPRECATED); to the file that throws the error. Any idea of where to put that line?
I can't see what file the error is being thrown on. See message :
Script php artisan optimize handling the post-install-cmd event returned with error code 1
remote: ! WARNING: A post-install-cmd script terminated with an error
remote:
remote: ! ERROR: Dependency installation failed!
I may be doing something obvoiusly wrong. Followed these steps for the migration : Deploy Laravel Projects On Heroku
EDIT: Also tried composer update as suggested in the answer to this question printing-preview-doesnt-working-laravel-dompdf
EDIT 2: Below is the the build log :
Package mtdowling/cron-expression is abandoned, you should avoid using it. Use dragonmantank/cron-expression instead.
remote: Generating optimized autoload files
remote: Carbon 1 is deprecated, see how to migrate to Carbon 2.
remote: https://carbon.nesbot.com/docs/#api-carbon-2
remote: You can run './vendor/bin/upgrade-carbon' to get help in updating carbon and other frameworks and libraries that depend on it.
remote: 1 package you are using is looking for funding.
remote: Use the `composer fund` command to find out more!
remote: > Illuminate\Foundation\ComposerScripts::postInstall
remote: > php artisan optimize
remote: Generating optimized class loader
remote: Compiling common classes
remote:
remote:
remote: [ErrorException]
remote: Invalid characters passed for attempted conversion, these have been ignored
remote:
remote:
remote: Script php artisan optimize handling the post-install-cmd event returned with error code 1
remote: ! WARNING: A post-install-cmd script terminated with an error
remote:
remote: ! ERROR: Dependency installation failed!
remote: !
remote: ! The 'composer install' process failed with an error. The cause
remote: ! may be the download or installation of packages, or a pre- or
remote: ! post-install hook (e.g. a 'post-install-cmd' item in 'scripts')
remote: ! in your 'composer.json'.
remote: !
remote: ! Typical error cases are out-of-date or missing parts of code,
remote: ! timeouts when making external connections, or memory limits.
remote: !
remote: ! Check the above error output closely to determine the cause of
remote: ! the problem, ensure the code you're pushing is functioning
remote: ! properly, and that all local changes are committed correctly.
remote: !
remote: ! For more information on builds for PHP on Heroku, refer to
remote: ! https://devcenter.heroku.com/articles/php-support
remote: !
remote: ! REMINDER: the following warnings were emitted during the build;
remote: ! check the details above, as they may be related to this error:
remote: ! - A post-install-cmd script terminated with an error
I've tried updating the mtdowling/cron-expression package - but it keeps reverting to it. Could this, or the Carbon error be causing the "Invalid characters error" ?
Upgrading the dompdf/dompdf to version 0.8.5 will solve this issue: https://github.com/dompdf/dompdf/releases
Installing the latest version can be done with:
composer require dompdf/dompdf
or modifying composer.json manually to 0.8.5 and running:
composer install
Keep in mind this upgrade may contain breaking changes
What fixed this issue the last time it occured was to switch the heroku stack to 'heroku-16' but with it becoming deprecated next month (May 2021) I tried to upgrade the stack and was faced with the same error again.. This time I found that with the later stack (heroku-20) that the two post cmds weren't being run correctly
"post-install-cmd": [
"Illuminate\\Foundation\\ComposerScripts::postInstall",
"php artisan optimize"
],
"post-update-cmd": [
"Illuminate\\Foundation\\ComposerScripts::postUpdate",
"php artisan optimize"
]
I'm assuming these post install commands work for the older stack or something and that's why I was getting the errors originally.. I removed these two steps from the composer.json and the project built perfect. Then I added the post install commands into a new app.json file, in the root directory for heroku to pick up. An example of that file here >
{
"name": "Site name here",
"description": "",
"scripts": {
"postdeploy": "php artisan optimize"
},
"buildpacks": [
{
"url": "https://github.com/heroku/heroku-buildpack-php"
}
]
}
the build pack here is a reference to the newest php stack. After adding this app.json the whole project was deployed successfully.
I'm trying to push a test Laravel application to Heroku but whenever I try to do so I get an error and the deployment stops. This is whats displayed when I do a deploy:
remote: Generating optimized autoload files
remote: > Illuminate\Foundation\ComposerScripts::postInstall
remote: > php artisan optimize
remote:
remote:
remote: [InvalidArgumentException]
remote: Please provide a valid cache path.
remote:
remote:
remote: Script php artisan optimize handling the post-install-cmd event returned with error code 1
remote: ! Push rejected, failed to compile PHP app.
remote:
remote: ! Push failed
remote: Verifying deploy...
What's the issue here? The storage/framework folder has all the needed folders and they're included in the repository. So whats wrong here?
Just check the gitignore file if has /storage/.key or /storage/ remove it and again run commit and push.
I'm trying to deploy a simple app to Heroku, but keep getting this error message:
Alastairs-MacBook-Air:php-getting-started alastair$ git push heroku master
Counting objects: 6, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (6/6), done.
Writing objects: 100% (6/6), 1.23 KiB | 0 bytes/s, done.
Total 6 (delta 5), reused 0 (delta 0)
remote: Compressing source files... done.
remote: Building source:
remote:
remote: -----> PHP app detected
remote: -----> Bootstrapping...
remote: -----> Installing platform packages...
remote:
remote: ! ERROR: Couldn't parse 'composer.lock'; it must be a valid lock
remote: file generated by Composer. Run 'composer update', add/commit
remote: the change, then push again.
remote:
remote: ! Push rejected, failed to compile PHP app
remote:
remote: ! Push failed
remote: Verifying deploy...
remote:
remote: ! Push rejected to arcane-peak-94383.
remote:
To https://git.heroku.com/arcane-peak-94383.git
! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'https://git.heroku.com/arcane-peak-94383.git'
It's this tutorial.
I've ran composer update multiple times, add/committed the change, and reinstalled composer. All with no luck. The composer.lock file was generated by Composer, as I've regenerated it by running composer update.
Here's my composer.json file:
{
"require" : {
"silex/silex": "^1.3",
"monolog/monolog": "^1.4",
"twig/twig": "^1.8",
"symfony/twig-bridge": "^2",
"alrik11es/cowsayphp": "^1.0"
},
"require-dev": {
"heroku/heroku-buildpack-php": "*"
}
}
I know this is a simple solution, but I have been trying to resolve for a couple of hours now. Thanks in advance.
The answer from SO that should do it:
Seems that Heroku supports only latest versions of Composer.
composer self-update and further composer update (+ git add, + git commit) should fix the issue.
I'm trying to publish my Laravel app on Heroku.
I have excluded the composer.lock file from .gitignore, and created a Procfile containing
web: vendor/bin/heroku-php-apache2 public
I created my app with
heroku create myapp;
git push heroku master;
Then I get the following output:
git -c diff.mnemonicprefix=false -c core.quotepath=false -c credential.helper=sourcetree push -v --tags heroku master:master
Pushing to https://git.heroku.com/myapp.git
POST git-receive-pack (1914 bytes)
remote: Compressing source files... done.
remote: Building source:
remote:
remote: -----> Node.js app detected
remote: -----> Resetting git environment
remote:
remote: PRO TIP: Specify a node version in package.json
remote: See https://devcenter.heroku.com/articles/nodejs-support
remote:
remote: -----> Defaulting to latest stable node: 0.10.35
remote: -----> Downloading and installing node
remote: -----> Exporting config vars to environment
remote: -----> Installing dependencies
remote: npm WARN package.json myapp#0.0.0 No repository field.
remote: -----> Cleaning up node-gyp and npm artifacts
remote: -----> Building runtime environment
remote: -----> Discovering process types
remote: Procfile declares types -> web
remote:
remote: -----> Compressing... done, 9.6MB
remote: -----> Launching... done, v5
remote: https://myapp.herokuapp.com/ deployed to Heroku
remote:
remote: Verifying deploy... done.
To https://git.heroku.com/myapp.git
5b1c663..0dff021 master -> master
updating local tracking ref 'refs/remotes/heroku/master'
Completed successfully
If I browse to my app, however I get an application error.
When I look to my logs, it says
app[web.1]: bash: vendor/bin/heroku-php-apache2: No such file or directory
I suspect that somehow, Heroku didn't do composer install, as it's not in my git output, and maybe it didn't even recognize that my app is an PHP app?
To be sure, I also included an empty index.php file in my root. Didn't help.
What am I missing here?
I believe I found it. Should better read the lines ("Node.js app detected").
Solved by firing this command :
heroku config:add BUILDPACK_URL=https://github.com/heroku/heroku-buildpack-php
and pushing again
Haha, just simply drop the package.json in your laravel project.
And then Heroku will detect your app as a php project.
Be sure to include the trailing slash on public: public/. This was my issue - I am using Laravel and got a Image source not readable and NotReadableException in AbstractDecoder.php line 302: because it thought at AbstractDecoder->init('/app/public') in AbstractDriver.php line 64 was a file, not a folder.