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

Boneshock's avatar

PHP Failed to generate random data

Recently I ran a 'composer update' and now my Laravel project is using paragonie/random_compat.

Since then, my project fails to run and throws an Exception.
"Exception in /sites/lunch/www/vendor/paragonie/random_compat/lib/random_bytes_mcrypt.php line 69: PHP failed to generate random data."

Stack trace:
#0 /sites/lunch/www/vendor/laravel/framework/src/Illuminate/Support/Str.php(249): random_bytes(25)
#1 /sites/lunch/www/vendor/laravel/framework/src/Illuminate/Support/Str.php(230): Illuminate\Support\Str::randomBytes(25)
#2 /sites/lunch/www/vendor/laravel/framework/src/Illuminate/Session/Store.php(197): Illuminate\Support\Str::random(25)
#3 /sites/lunch/www/vendor/laravel/framework/src/Illuminate/Session/Store.php(173): Illuminate\Session\Store->generateSessionId()
#4 /sites/lunch/www/vendor/laravel/framework/src/Illuminate/Session/Store.php(81): Illuminate\Session\Store->setId(NULL)
#5 /sites/lunch/www/vendor/laravel/framework/src/Illuminate/Session/SessionManager.php(172): Illuminate\Session\Store->__construct('laravel_session', Object(Illuminate\Session\FileSessionHandler))
#6 /sites/lunch/www/vendor/laravel/framework/src/Illuminate/Session/SessionManager.php(62): Illuminate\Session\SessionManager->buildSession(Object(Illuminate\Session\FileSessionHandler))
#7 /sites/lunch/www/vendor/laravel/framework/src/Illuminate/Session/SessionManager.php(50): Illuminate\Session\SessionManager->createNativeDriver()
#8 /sites/lunch/www/vendor/laravel/framework/src/Illuminate/Support/Manager.php(87): Illuminate\Session\SessionManager->createFileDriver()
#9 /sites/lunch/www/vendor/laravel/framework/src/Illuminate/Support/Manager.php(63): Illuminate\Support\Manager->createDriver('file')
#10 /sites/lunch/www/vendor/laravel/framework/src/Illuminate/Session/Middleware/StartSession.php(115): Illuminate\Support\Manager->driver()
#11 /sites/lunch/www/vendor/laravel/framework/src/Illuminate/Session/Middleware/StartSession.php(100): Illuminate\Session\Middleware\StartSession->getSession(Object(Illuminate\Http\Request))
#12 /sites/lunch/www/vendor/laravel/framework/src/Illuminate/Session/Middleware/StartSession.php(57): Illuminate\Session\Middleware\StartSession->startSession(Object(Illuminate\Http\Request))
#13 [internal function]: Illuminate\Session\Middleware\StartSession->handle(Object(Illuminate\Http\Request), Object(Closure))
#14 /sites/lunch/www/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(124): call_user_func_array(Array, Array)
#15 /sites/lunch/www/vendor/laravel/framework/src/Illuminate/Cookie/Middleware/AddQueuedCookiesToResponse.php(37): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#16 [internal function]: Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse->handle(Object(Illuminate\Http\Request), Object(Closure))
#17 /sites/lunch/www/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(124): call_user_func_array(Array, Array)
#18 /sites/lunch/www/vendor/laravel/framework/src/Illuminate/Cookie/Middleware/EncryptCookies.php(59): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#19 [internal function]: Illuminate\Cookie\Middleware\EncryptCookies->handle(Object(Illuminate\Http\Request), Object(Closure))
#20 /sites/lunch/www/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(124): call_user_func_array(Array, Array)
#21 /sites/lunch/www/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/CheckForMaintenanceMode.php(42): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#22 [internal function]: Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode->handle(Object(Illuminate\Http\Request), Object(Closure))
#23 /sites/lunch/www/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(124): call_user_func_array(Array, Array)
#24 [internal function]: Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#25 /sites/lunch/www/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(103): call_user_func(Object(Closure), Object(Illuminate\Http\Request))
#26 /sites/lunch/www/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(122): Illuminate\Pipeline\Pipeline->then(Object(Closure))
#27 /sites/lunch/www/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(87): Illuminate\Foundation\Http\Kernel->sendRequestThroughRouter(Object(Illuminate\Http\Request))
#28 /sites/lunch/www/public/index.php(55): Illuminate\Foundation\Http\Kernel->handle(Object(Illuminate\Http\Request))
#29 {main}  

I have no idea what might be causing this, help!

0 likes
5 replies
bobbybouwmann's avatar

I think you need to dive into the code. The package you installed might have changed and that's why it's not working anymore! You can also look at the Github repository and see if they updated something in there?

Also are you sure you are passing the correct variables to the function? You might want to share some code here

Boneshock's avatar

@bobbybouwmann ; thanks, I will look into that.
Edit: I have mcrypt installed and enabled.

The error also occurs in a fresh Laravel project, so it can't be me who is sending variables or executing functions ;)
I checked and created a project on a XAMPP server (instead of my company's development servers) and it runs perfectly on XAMPP. So I might have to poke a server admin here.

Please or to participate in this conversation.