Site5 - Built For Designers & Developers MENU
Home  ›  PHP  ›  PHP: Make Custom PHP Changes Using A .user.ini File

PHP: Make Custom PHP Changes Using A .user.ini File

52 Comments

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).

File Manager public_html

  • Then, click the New File link at the top of the page to access the tool to create your new .user.ini file.

File Manager New 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.

File Manager new userini file

  • 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.

File Manager userini file

  • Once the .user.ini file has been highlighted, click the Edit link at the top of the page.

File Manager Edit File

  • 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.

File Editor userini config

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.

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.

Still have a question? Or need help?
If you need technical support with your account, please email us or chat live with a representative.

52 Comments

  • 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.

  • 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!

    • 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 :)

      • It is not recursive through folders.

        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.

        • 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.

          • 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.

            • 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.

            • 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.

              • 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.

  • Sorry, May I ask a question, Can I enable allow_url_fopen with .user.ini?

    • Hello,

      Absolutely, yes. It actually should be enabled by default with the standard PHP configuration, though.

      • 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 :)

        • 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.

  • 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

    • 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.

      • Thanks James,

        I’ve just sent in a ticket.

        Andrew

      • That is quite strange, as you should be able to set any value in a .user.ini file.

        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.

        • 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.

  • Must be .user.ini?
    or i can add my custom name as .steven.ini?

    Cheers

    • Hello Steven,

      Yes, it does need to be .user.ini, as that is the filename that Apache is configured to look for.

  • 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?

    • 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.

  • 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.

    • 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.

    • 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.

      • 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.

        • 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/

          • 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.

            • 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

            • 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]

              • 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.

                • 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.

                  • 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.

  • I just question: how much is limited time of max_input_time?

    Thanks,
    Loc

    • 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.

  • 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.

  • 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?

    • 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.

      • 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?

        • 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.

  • Hi ty I did but they tell me they didn’t help for that, ok thanks a lot you are really kind
    ty
    Regards

    • Hi Francesca,

      The steps here should work, but I cannot guarantee that. I do not have access to their servers to confirm their setup.

    • 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:

      • It looks like the KB is trimming your code. Try it in plain text :)

  • 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?

    • 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.

  • 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

    • 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.

  • That really worked! a created the file .user.ini under public_html folder and changed was done.

    :-)

  • Yes! this was the answer for me! thanks so much

  • Does this still work? Ever since the servers changed over to nginx, the .user.ini seems to be ignored.

    • 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!

Money Back Guarantees