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

rhand's avatar
Level 6

Target class [session] does not exist

On deployment we also empty all caches, run php artisan optimize, reload PHP FPM with sudo /etc/init.d/php7.4-fpm restart. Still we got these errors recently.

[2021-05-21 10:47:25] staging.ERROR: Target class [session] does not exist. {"exception":"[object] (Illuminate\Contracts\Container\BindingResolutionException(code: 0): Target class [session] does not exist. at /home/forge/staging.site.com/releases/551/vendor/laravel/framework/src/Illuminate/Container/Container.php:835)
[stacktrace]
#0 /home/forge/staging.site.com/releases/551/vendor/laravel/framework/src/Illuminate/Container/Container.php(714): Illuminate\Container\Container->build('session')
#1 /home/forge/staging.site.com/releases/551/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(841): Illuminate\Container\Container->resolve('session', Array, true)

any idea what the cause can be?

0 likes
6 replies
CorvS's avatar

What session driver are you using? Where and how is the app being deployed (AWS, Forge, ...)?

1 like
rhand's avatar
Level 6

We are deploying with PHP Deployer. And for session use file:

forge@app-staging:~/staging.domain.com/shared$ cat .env |grep SESSION_DRIVER
SESSION_DRIVER=file
rhand's avatar
Level 6

Found

cache:clear command will clear users' sessions if CACHE_DRIVER is the same as SESSION_DRIVER, I think users should call this task on demand instead of putting it in default deploy task. at https://github.com/deployphp/deployer/pull/1681

so perhaps we need to make session driver use Redis like our regular Cache too. Looking into this. Just odd we never had this issue before.

1 like
rhand's avatar
Level 6

Does seem this happens on staging and not on production which use the same operating system (Ubuntu) and general setup done by Forge. So does feel there is something else going on. Still looking into the issue deeper and we will test with redis on staging and or production for sessions.

rhand's avatar
Level 6

Still having this issue on staging from time to time. Remains odd. Any pointers are still welcome.

rhand's avatar
rhand
OP
Best Answer
Level 6

Using

....
shared_dirs:
    - 'bootstrap/cache'
..

now to avoid the issue and keep cache in shared directory. Should solve the issue.

Please or to participate in this conversation.