Pushing Laravel App to heroku fails - valid cache path error - php

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.

Related

Deployment issue with Laravel on Heroku

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.

Invalid characters passed for attempted conversion, these have been ignored - Pushing Laravel project to heroku

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.

Can PHP applications hosted on Heroku be edited using Cloud9?

If I push my PHP app from Cloud9 to Heroku, my application will be deployed on Heroku. The question is that in the future, if I have to perform some bug fixing or update etc., will I be able to edit the application hosted/deployed on Heroku?
EDIT:
zeldish:~/workspace/appzeld (master) $ git push heroku master
Counting objects: 3, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 381 bytes | 0 bytes/s, done.
Total 3 (delta 2), reused 0 (delta 0)
remote: Compressing source files... done.
remote: Building source:
remote:
remote: -----> Using set buildpack heroku/php
remote: -----> PHP app detected
remote:
remote: ! WARNING: No 'composer.json' found.
remote: Using 'index.php' to declare app type as PHP is considered legacy
remote: functionality and may lead to unexpected behavior.
remote:
remote: -----> Bootstrapping...
remote: -----> Installing platform packages...
remote: NOTICE: No runtime required in composer.lock; using PHP ^5.5.17
remote: - apache (2.4.20)
remote: - nginx (1.8.1)
remote: - php (5.6.22)
remote: -----> Installing dependencies...
remote: Composer version 1.1.2 2016-05-31 19:48:11
remote: -----> Preparing runtime environment...
remote: NOTICE: No Procfile, using 'web: vendor/bin/heroku-php-apache2'.
remote: -----> Checking for additional extensions to install...
remote:
remote: -----> Discovering process types
remote: Procfile declares types -> web
remote:
remote: -----> Compressing...
remote: Done: 13.9M
remote: -----> Launching...
remote: Released v4
remote: https://*******.herokuapp.com/ deployed to Heroku
remote:
remote: Verifying deploy... done.
To https://git.heroku.com/********.git
59f63a5..4375225 master -> master
Simple answer is yes. You will be able to push every changes you make to your application. in order to do that you can simply run below command and you will be able to see all the changes you have made after you push to your repository.
$ git init
$ heroku create
$ echo '{}' > composer.json
$ heroku buildpacks:set heroku/php
(you will need to run above commands when you deploying your app first time. This command will create repository on heroku for you and it will set php buildpack on heroku.)
$ git add .
$ git commit -am "some comment"
$ git push heroku master
$ heroku open
to getting started click here

Issue when pushing PHP/Laravel to Azure with Git

I am developing a PHP-Laravel Web App in Microsoft Azure Cloud. I set up a Local Git in the cloud for version control. I am also using PHP Storm by JetBrains as the IDE.
Each time I push files from my computer to azure, git performs some operations which delay my deployment. Even if I change a single file it will take around a minute to finish. I am new to Laravel and Composer so I was wondering if it is a normal thing to do or is it my mistake?
Counting objects: 7, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (7/7), done.
Writing objects: 100% (7/7), 1.35 KiB | 0 bytes/s, done.
Total 7 (delta 6), reused 0 (delta 0)
remote: Updating branch 'master'.
remote: Updating submodules.
remote: Preparing deployment for commit id '0f7a0fa743'.
remote: Running custom deployment command...
remote: Running deployment command...
remote: Install Dependencies with Composer
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: ...........................
remote: > Illuminate\Foundation\ComposerScripts::postInstall
remote: > php artisan optimize
remote: ..
remote: Generating optimized class loader
remote: ..............................
remote: Handling Basic Web Site deployment.
remote: ...
remote: KuduSync.NET from: 'D:\home\repository' to: 'D:\home\site'
remote: Copying file: '.idea\workspace.xml'
remote: Copying file: 'app\Http\routes.php'
remote: Copying file: 'vendor\autoload.php'
remote: Copying file: 'vendor\composer\autoload_classmap.php'
remote: Copying file: 'vendor\composer\autoload_files.php'
remote: Copying file: 'vendor\composer\autoload_namespaces.php'
remote: Copying file: 'vendor\composer\autoload_psr4.php'
remote: Copying file: 'vendor\composer\autoload_real.php'
remote: Copying file: 'vendor\composer\autoload_static.php'
remote: Copying file: 'vendor\composer\ClassLoader.php'
remote: Copying file: 'vendor\composer\installed.json'
remote: Copying file: 'vendor\composer\LICENSE'
remote: Finished successfully.
remote: Running post deployment command(s)...
remote: Deployment successful.
When you deploy your PHP application to Azure App Services via Git. The deployment task not only upload and copy the code scripts on the root directory on Azure, but also will run composer commands if you have composer.json configuration file on your root directory and enabled the composer extension on Azure App Services.
It will run composer install, which will install the dependencies and run the custom commands set in scripts section.
So it will take time.
Azure App Services as a PaaS for hosting production applications, you can push your code to Azure after you have finished a stage of developing work.
Meanwhile, you can try the suggestion provided by #Achraf Khouadja, leverage the GitHub repository as a middle layer. with which, you can only upload your codes to GitHub, and Azure fabric will sync the code and run the deployment task automatically.
You will not need to wait the response in your IDE, it will save your time.

Heroku doesn't recognize my Laravel app as PHP app, and does not do composer install

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.

Categories