Custom PHP INI w/Laravel on Heroku

Branick Weix
Jan 9, 2019 · 2 min read

I was building a new feature on Aryeo that allows users to save their flyer creation process, when I encountered an error on our staging server:

PHP Warning: Unknown: POST Content-Length of 25923563 bytes exceeds the limit of 8388608 bytes in Unknown on line 0

I was trying to upload a 25MB flyer, but out default PHP max post size was only 8MB. No problem I’ll just update the PHP INI file….oh wait, Heroku doesn’t let you do this. They outline a number of solutions in their docs however: https://devcenter.heroku.com/articles/custom-php-settings

After a bit of research and trying their .user.ini file in the root directory, I still couldn’t get my dyno to accept the new settings. It seems this was happening for others, as well as some confusion over the placement of the file in either the public/ root or the application root.

The Solution

I created a user.ini file in the root of my application, aka next to my Procfile. I also didn’t prepend a “.” to the file name, as I ran into problems detecting this file. Here’s what the file consisted of:

upload_max_filesize = 25M
post_max_size = 25M

I then also updated my Procfile (after numerous application failures due to wrong ordering):

web: vendor/bin/heroku-php-apache2 -i user.ini public/

The -i directive tells PHP to load additional ini variables found in the specified file. Note you must direct this before the “public/”. Heroku documentation says that the build should auto-detect the user.ini file, but I found only this to work. Please comment if you have a better solution!

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade