PHP: Make Custom PHP Changes Using A .user.ini File
At times, you will want to use software that requires a custom php.ini file or custom PHP configuration changes such as increasing the memory limit or upload limit that your site is allowed. Since these are settings that we can not change on a server-wide basis, you would need to make these changes locally on your account. Fortunately, with these easy to follow steps, you can have a .user.ini file created and customized within minutes!
Please note: This would mean, for example, if you were to create the .user.ini within their public_html, the changes are applied to the software that is installed in that particular folder only. Any subsequent PHP installations such as WordPress in a public_html/blog/ folder, wouldn’t be affected by said changes. In order to apply changes to subsequent sub folders within a directory, a separate .user.ini is necessary for each directory.
- Open up File Manager through your control panel (SiteAdmin or cPanel) and ensure you are in the public_html (www) directory (also ensure that hidden files are visible).
- Then, click the New File link at the top of the page to access the tool to create your new .user.ini file.
- You will be presented with a popup allowing you to name and configure the new file. In the New File Name box, add the text .user.ini . Be sure to include the dot before “user” in the filename.
- Now, your .user.ini file has been created! The next step is to edit the file and add the lines that you would like to customize. Locate the file in the list and click on it 1 time to highlight it.
- Once the .user.ini file has been highlighted, click the Edit link at the top of the page.
- This will then open up the file editor so you can input your custom configuration settings. Since we’ve just created the .user.ini file, it will be blank. All you would need to do is add the line from the server-wide php.ini file you wish to change and the new value such as the example image below.
And that’s it! You’ve now created your .user.ini file and all of your custom PHP configuration changes added to the file will be used by your website! Below are some of the most common lines that are altered when making custom PHP changes.
- memory_limit
- upload_max_filesize
- post_max_size
- max_execution_time
- max_input_time
- register_globals
- magic_quotes_gpc
Changing Your Memory Limit
This guide will show you how to increase the memory limit in PHP. While we don’t have a technical limit on how high you can set the php memory limit, we highly recommend that you not exceed 256M(128M for Legacy Servers).
If your .user.ini file is setup, all you need to do is open up your .user.ini file in your favourite command line editor (vi/vim/emacs/nano) and add the following line:
memory_limit = 256M |
The changes will take place immediately. The web server does not need to be restarted.
Changing Your Max Upload
This guide will show you how to increase the max upload size in PHP (upload_max_filesize). By default it is 1024M(128M on Legacy Servers) on our shared/reseller/managed VPS but this can be increased as high as 2GB (max).
If your .user.ini file is setup, all you need to do is open up your .user.ini file in your favourite command line editor (vi/vim/emacs/nano), FTP or through the File Manager and add the following line:
upload_max_filesize = 1024M |
The changes will take place immediately and can be set to whatever value you like. The web server does not need to be restarted.
Notice: If you will be uploading files via the “POST” method (most common), you will likely need to increase the post_max_size configuration value in conjunction with the upload_max_filesize value, if you have not already done so. PHP recommends that you set the post_max_size value higher than the upload_max_filesize value. Experiment with increasing it slightly above upload_max_filesize and increase it further if your uploads are failing.
Changing Your Post Max Size
This guide will show you how to increase the max upload size in PHP (post_max_filesize). By default it is 1024M(128M on Legacy Servers) on our shared/reseller/managed VPS but this can be increased as high as 2GB (max).To ensure the changes
you’ve made have been properly configured, you’ll need to increase the limit for this value to be higher than
the upload_max_filesize.
If your .user.ini file is setup, all you need to do is open up your .user.ini file in your favourite command line editor (vi/vim/emacs/nano), FTP or through the File Manager and add the following line:
post_max_size=1024M |
The changes will take place immediately and can be set to whatever value you like. The web server does not need to be restarted
Changing Your Max Execution Time
This guide will show you how to increase the time out limit in PHP (max_execution_time).This value sets the maximum time, in seconds, the PHP script is allowed to run. By default the limit is 300 seconds(30 seconds in Legacy Servers) and if a script runs longer than 300 seconds, it will be stopped and you encounter a PHP related error. For large or multiple files, or users on slower connections, the default of 300 seconds(60 seconds in Legacy Servers) may be exceeded.
If your .user.ini file is setup, all you need to do is open up your .user.ini file in your favourite command line editor (vi/vim/emacs/nano), FTP or through the File Manager and add the following line:
max_execution_time=300 |
Note: This value can be set to whatever time limit you wish, however please note that our server is configured to kill off PHP connections that last longer then 30 minutes, so please keep that in mind when setting the limit.
Changing Your Max Input Time
This guide will show you how to increase the time out limit in PHP max_input_time. This value sets the maximum time, in seconds, the script is allowed to receive input; this includes file uploads. For large or multiple files, or users on slower connections, the default of 300 seconds(60 seconds on Legacy Servers) may be exceeded.
If your .user.ini file is setup, all you need to do is open up your .user.ini file in your favourite command line editor (vi/vim/emacs/nano), FTP or through the File Manager and add the following line:
max_input_time=300 |
Note: This value can be set to whatever time limit you wish, however please note that our server is configured to kill off PHP connections that last longer then 30 minutes, so please keep that in mind when setting the limit.
Changing Your Register Globals Value
Most of your scripts should not need this enabled, but some older scripts like to have it. It is NOT recommended that you enable this option in php 5.3 as it was deprecated in that version and it is removed from PHP 5.4.
Changing Your Magic Quotes
Most of your scripts should not need this enabled, but some older scripts like to have it. It is NOT recommended that you enable this option in php 5.3 as it was deprecated in that version and it is removed from PHP 5.4.
Bogdan February 13, 2014 at 9:05 am
Just a note, this option works for php 5.3 and higher. Also now hosting companies (including me) allow clients to create a custom php.ini directly and change their php settings from there. Of course, not everywhere it is allowed, but you can ask your hosting company.
Bogdan February 13, 2014 at 9:06 am
Also, if you can include in my first reply, this option is not recurrent within folders, works only in the specific folder you created the file!
James Davey February 13, 2014 at 9:55 am
Hi Bogdan,
This is absolutely correct, yes. It is not recursive through folders. As well, you can certainly create your own php.ini file, and we have a kb article for that as well, but we are moving toward using .user.ini instead. Eventually, there will come a time when using php.ini – with the .htacces lines needed for that – may result in site errors. We are taking steps to prevent this for existing users already with the .htaccess rules in place, but it is safer to use .user.ini going forward :)
Josh July 17, 2014 at 7:59 pm
Does that mean we need a .user.ini file in every directory on the site to avoid memory errors? It seems like that would be a lot of code duplication.
James Davey July 18, 2014 at 7:26 am
Hello Josh,
You will need the .user.ini file in any folder that needs these changes, yes. If the script runs in two folders, you would need the file in both of them – not every folder on your site.
Matt August 14, 2014 at 11:01 am
heh, yeah that means I’m totally screwed.
Our backend system uses a custom error reporting that is prepended to every script through php.ini
I have been a customer for over ten years at site5 but this is going to make me quit.
Absolutely NO GO!
Matt.
James Davey August 14, 2014 at 12:17 pm
Hi Matt,
I am very sorry to hear that. There will be no change to php.ini on the servers due to this. The only change will be to adjusting variables using a custom php.ini file – this is being replaced with a .user.ini file, for security. If you still need to use php.ini, you can use the server-wide file and simply make adjustments in folders where they are needed using .user.ini.
Bogdan October 4, 2014 at 8:14 am
Try setting in your script your memory_limit using ini_set()
http://uk1.php.net/ini_set
That would solve your issue. James can confirm, but I think it would be allowed so you will be fine like that.
James Davey October 6, 2014 at 6:32 am
Hi Bogdan,
That may work, yes. I’ve not tried it myself, but there is no reason for this to fail, that I can see.
soiqualang_chentreu April 2, 2014 at 12:56 am
Sorry, May I ask a question, Can I enable allow_url_fopen with .user.ini?
James Davey April 2, 2014 at 7:39 am
Hello,
Absolutely, yes. It actually should be enabled by default with the standard PHP configuration, though.
soiqualang_chentreu April 7, 2014 at 4:11 am
Thanks for replying ^^, I did it but through php.ini file. I make a file .user.ini and placed in my folder, but nothing happened so I make a file php.ini with same the contents and everything gone well :)
James Davey April 7, 2014 at 7:49 am
Hello,
While a php.ini file will work for the moment, it has some built-in insecurities, which is why we are moving toward the .user.ini solution. Eventually, the php.ini file you create will no longer work.
Andrew May 2, 2014 at 6:39 pm
Hmm… This didn’t work when I went to change the realpath_cache_size and realpath_cache_ttl settings. CMS sites that tend to load a lot of files but the files don’t change can benefit from a bump in memory + longer TTL and it really only takes a little adjustment to make a huge gain. I like to profile the site first to see the actual requirements but regardless of the setting I put in, there was no change. It sits at 16k.
I suspect the server would be much happier at something like:
realpath_cache_size = 32k
realpath_cache_ttl = 3600
Rather than the OEM settings of:
realpath_cache_size = 16k
realpath_cache_ttl = 120
James Davey May 5, 2014 at 7:28 am
Hi Andrew,
That is quite strange, as you should be able to set any value in a .user.ini file. Please note that the changes you specify are folder-specific, so the file will need to be in the folder you need these settings in (and in each subsequent folder).
If you are still having trouble with this, I would recommend you contact our support team so we can have a closer look at what is happening.
Andrew May 5, 2014 at 12:43 pm
Thanks James,
I’ve just sent in a ticket.
Andrew
Jesin A April 25, 2015 at 3:24 pm
That isn’t correct, you cannot change “PHP_INI_SYSTEM” type directives in the .user.ini file.
This link has a complete list of directives and their configurable modes – http://php.net/manual/en/ini.list.php
This is why a custom php.ini file is very much required.
James Davey April 27, 2015 at 5:42 am
Hello Jesin,
Any value that would normally be changeable, I should have said. Yes, some values require a php.ini file, but we are moving away from that altogether, and .user.ini will be required going forward.
Steven May 2, 2014 at 9:43 pm
Must be .user.ini?
or i can add my custom name as .steven.ini?
Cheers
James Davey May 5, 2014 at 7:29 am
Hello Steven,
Yes, it does need to be .user.ini, as that is the filename that Apache is configured to look for.
Ken Yau May 18, 2014 at 3:10 am
Hello,
Should we only add the part we need to modify to the .user.ini or we need to copy the global php.ini from /usr/local/lib/ then modify the part we need?
James Davey May 19, 2014 at 7:59 am
Hi Ken,
You should only need to add the variable that you are looking to change. You do not need to copy the whole file over.
Daniela June 24, 2014 at 4:34 am
Hi, I’m using Visual Form Builder Pro https://vfbpro.com/ in my WordPress Installation and I would need to increse the maximum amout of data allowed by the server in the php.ini file.
I increased the max_input_vars in my user.ini file but that seems to have no effect on the Visual Form Builder Pro.
I still get the following error message:
Error saving form. The maximum amount of data allowed by your server has been reached. Please update max_input_vars in your php.ini file to allow more data to be saved. Current limit is 1000.
James Davey June 24, 2014 at 7:47 am
Hi Daniela,
That is very strange, as that should be more than enough. Can I get you to open a ticket with our support team, via BackStage? We’d be more than happy to take a look for you.
Andrew June 24, 2014 at 1:24 pm
Hi Daniela,
I ran into the same issue when I tried to change the setting for realpath_cache_size and realpath_cache_ttl. I was told by the guys at support that there are some settings they’ve got set in stone. max_input_vars may be one of those settings.
James Davey June 24, 2014 at 2:33 pm
Hi Andrew,
No, that is not one of the variables that is ‘set in stone’. Actually, most settings listed in a php.ini file are changeable using .user.ini – I would recommend contacting our support team to see what we can do for you.
Andrew June 24, 2014 at 2:54 pm
Hi James,
Perhaps not with max_input_vars but certainly it is the case with the changes I wanted to make. I contacted support on May 5th 2014 and was told the following:
Unfortunately some PHP parameters cannot be modified via .user.ini like they were via php.ini and these is the reason you are unable to increase the above values.
At this time you will need to use the default value which unfortunately cannot be adjusted on a managed server.
If you need to be able to manage/adjust the global values we recommend you one of our unmanaged services where you have root access and can configure the server as needed:
http://www.site5.com/vps/unmanaged/
James Davey June 24, 2014 at 3:16 pm
Hi Andrew,
I am very sorry to hear that. It certainly is possible, and has been all along. I apologise for the incorrect information you were provided, and if you still require this adjustment be made, please contact our support team and we will be happy to do so for you.
Andrew June 24, 2014 at 5:34 pm
Hi James,
That is very cool to hear! I’ll get back in touch with support and let them know that you’ve advised that I should be able to make that adjustment. Awesome!
Andrew
Andrew June 25, 2014 at 3:01 am
Ok, so…. The bad news is that no… Those values are indeed set in stone. I sent in another ticket, explained that I was advised that these settings were adjustable and after several replies moving it up the chain I received a replay with the following:
[quote]
Thanks for your reply and please allow me to extend my sincere apologies on the confusions created.
The two variables you have advised on earlier are indeed set in stone and cannot be altered. These are variables that are directly implemented into the system php.ini.
You can find a list of variables that can be altered using a .user.ini at the link bellow. Note that for ones that you see PHP_INI_SYSTEM under the Changeable column, you will not be able to adjust them locally:
http://www.php.net/manual/en/ini.list.php
[/quote]
James Davey June 25, 2014 at 7:25 am
Hello Andrew,
Again, I am very sorry. What values are you attempting to change? It seems that you were looking to change max_input_vars, which certainly is adjustable, but based on this I may be incorrect in that assumption.
Andrew June 25, 2014 at 12:34 pm
Yes, it looks to me that max_input_vars is adjustable through a .user.ini file but the settings I wanted to change are not (realpath_cache_size and realpath_cache_ttl)
I’ve already tested max_input_vars and I can change them by setting a value and checking against phpinfo(). I changed mine from 1000 to 1020 and the change did stick.
James Davey June 25, 2014 at 1:18 pm
Hello Andrew,
You are correct, and I apologise for my assumption. Those variables do not appear to be adjustable, no. I am very sorry for the confusion.
Loc_rabbirt August 29, 2014 at 5:06 pm
I just question: how much is limited time of max_input_time?
Thanks,
Loc
James Davey September 1, 2014 at 7:23 am
Hello Loc,
While there is no hard limit on this, from PHP, you will likely start to run into issues at 120 or so. The server firewall will start kicking in around there, though you can request that we allow certain processes through this, if you contact our support team.
Vk August 30, 2014 at 7:07 am
You are the LIFE SAVER. I was stuck with this issue from a very long time, but u solved with 3 line and a file name. Thx
Great Tip.
Francesca February 26, 2015 at 10:23 am
Hi can you help me please? I have a lot of Strict Standards: Non-static method DC::….. only in the index, I have to personalize my .user.ini in Godaddy hosting, but I really I didnìt know what I have to do, can you help me please?
James Davey February 26, 2015 at 11:50 am
Hello Francesca,
I am not sure what you are looking for. Do you need to add some custom rules in a .user.ini file? If so, this article should walk you through it pretty easily. Or you can contact our support team with your requested changes, and we can certainly help you with it.
Francesca February 26, 2015 at 12:16 pm
Hi thanks for the answer, I have to disable strict error messages in my php.ini file ( in my case I have to create .user.ini because in Godaddy I can’t have the php.ini), or turn off display of the messages and send them to the error_log. But I didn’t know what I have to do can you help me please?
James Davey February 26, 2015 at 1:27 pm
Hi Francesca,
Are you hosted with GoDaddy? If so, you would need to contact their support team on this, as they may have specific requirements in place for you to do this.
Francesca February 26, 2015 at 2:12 pm
Hi ty I did but they tell me they didn’t help for that, ok thanks a lot you are really kind
ty
Regards
James Davey February 27, 2015 at 6:25 am
Hi Francesca,
The steps here should work, but I cannot guarantee that. I do not have access to their servers to confirm their setup.
Stavros February 26, 2016 at 6:51 am
Hello Francesca,
Should you want to turn off PHP error display in your web pages, place the following codes into your .user.ini
display_startup_errors = Off
display_errors = Off
html_errors = Off
docref_root = 0
docref_ext = 0
Alternatively, you may add the following code at the top of your php web pages:
James Davey February 26, 2016 at 11:23 am
It looks like the KB is trimming your code. Try it in plain text :)
Drake Christensen December 4, 2015 at 6:27 am
I had to install a custom PEAR environment. Therefore, I need to modify the include_path variable. Not every PHP module will need access to the PEAR modules I’ve installed. But, I didn’t write this software, so I can’t know which do and which don’t without a lot of work.
Is there a “Best Practices” on how to handle this situation? Should I write a utility which takes a canonical .user.ini and propagates it down my directory tree into every folder that contains a .php file? Is there a better way to do this?
James Davey December 4, 2015 at 8:06 am
Hello Drake,
That is a question that we can’t really answer here, as it really comes down to what works for you. Your solution of a script that automatically drops your custom .user.ini file into all folders containing a .php file is actually a great idea, and is probably the fastest way to do this. I would recommend setting up a cron job to periodically check new folders for .php files, as well.
Bill December 26, 2015 at 7:14 pm
Hi, after inputting my code in the user.ini file, do I then need to go back into my php.ini file and delete those lines in that file?
Thanks,
Bill
Corey Mahon December 28, 2015 at 8:07 am
Hi Bill!
Since custom php.ini files are no longer supported in the most recent version of PHP, you would just need to make the modification in your user.ini file and then remove (or rename) the custom php.ini file since it should no longer be read and all custom settings will be picked up from the user.ini file.
Ariel Barrales February 25, 2016 at 12:42 pm
That really worked! a created the file .user.ini under public_html folder and changed was done.
:-)
martin March 16, 2016 at 11:19 pm
Yes! this was the answer for me! thanks so much
Tony August 8, 2016 at 9:43 pm
Does this still work? Ever since the servers changed over to nginx, the .user.ini seems to be ignored.
Corey Mahon August 19, 2016 at 4:26 pm
Hi Tony!
That is an odd issue indeed. .user.ini files should still work with no problems at all on our new upgraded servers. If you are still running into issues with your .user.ini file being ignored, please open a ticket through your backstage panel, our team will be glad to check it out!