Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

sanjay23's avatar

php artisan command failure and composer update error

Hello,

I have developed one site and recently move it to client server. However when I try to update the composer it giving me some unexpected error as follow

 PHP artisan optimize

  [ErrorException]
  Invalid argument supplied for foreach()
Content-type: text/html; charset=UTF-8

Script PHP artisan optimize handling the post-update-cmd event returned with error code 1

Then when I try to run the command php artisan the error as follow.

[ErrorException]
  Invalid argument supplied for foreach()


Content-type: text/html; charset=UTF-8

Please help me to get it resolve.

Thanks in Advance.

0 likes
8 replies
Devon's avatar

Try running the following commands in the order listed...

composer update --no-scripts
composer dump-autoload -o
composer update
sanjay23's avatar

@Devon Thanks for your comment, However I followed the all commands as you provided but the error is still there.

Devon's avatar

Does your site load, or does it also display an error? If so, what error? Is there anything in your error log that might help?

sanjay23's avatar

Actually my site loading properly. When I logged into the site and navigate some links so it gets automatically log out without clicking on logout button. This is the reason I just want to clear the cache using artisan command. So I found there is some error related to project code which might be creating the problem.

Devon's avatar

As for logging out, ensure you set up your cookie domain properly.

Devon's avatar

It can be set in one of the config files... I believe 'session.php', but I'm not at my computer to confirm that. You can set it to '.example.com', where example is your domain, the prefixed period lets it match all sub domains (eg. 'help.example.com').

I'd put it in my env file since it will vary from development to production...

sanjay23's avatar

Hello @Devon

I did so much research but no use, I have checked with all PHP settings too like "session.use_only_cookies" and "register_argc_argv"

I feel the issue might be the following reason.

Normally site run with public in URL so when I have added some code in .htaccess to remove public like

RewriteEngine On
RewriteRule ^(.*)$ public/$1 [L]

So it runs without public in URL but session gets destroy after some time. So when I remove the .htaccess rule and site get working.

Can anyone guide me the way to remove the public from URL and site will work properly.

Please or to participate in this conversation.