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

Automaton's avatar

over written php.ini in laravel

It's has been a challenge for a lot of laravel newbie to overwrite php.ini setting in laravel but here is a simple one: The below code has the ability to overwrite .ini in PHP. these will be very useful for those hosting their laravel app on a shared hosting.

Route::group(['middleware'=>'custom_middleware'], function () {

ini_set('upload_max_filesize', '500M');
ini_set('max_execution_time', 600);
ini_set('post_max_size', '500M');

});

0 likes
9 replies
bobbybouwmann's avatar

It would be even better to move this to a middleware class. This way you can set it per route or for your whole application ;)

Automaton's avatar

@bobbybouwmann Great idea but that sounds complicated to laravel beginner so at the moment this will do just fine

bobbybouwmann's avatar
Level 88

@automaton Just run php artisan make:middleware PHPIniMiddleware and add all those calls to the handle method. Then register the middleware in app/Http/Kernel.php and you're done ;)

1 like
Cruorzy's avatar

@bobbybouwmann Do you rather find this as a solution when it comes to changing php.ini values.

I was always debating with myself that i have to find a solution where it's clear after a year that i did it a specific way. Was alreayd thinking like making a laravel template php.ini then change per project find tools to compare them but seems like a hassle.

But this seems perfectly fine too, haven't thought about it.

bobbybouwmann's avatar

@cruorzy You can for example put every php.ini change in a separated middleware and give it a clear name. This way you can easily see what's going on ;)

1 like
ezzer87's avatar

I know this is an old one, but it's an issue Im currently having as I'm hosting my app with Railway.app and don't have access to the php.ini file and my app required image uploading. Currently getting a 413 on uploads larger than 1mb.

I've tried doing all the above, but still getting the error. I think it's that upload_max_filesize isn't able to be modified using ini_set — https://stackoverflow.com/questions/13442270/ini-setupload-max-filesize-200m-not-working-in-php.

Please or to participate in this conversation.