Ecommerce Blog - The #1 Source for Ecommerce News, Tips and Trends!

Get ecommerce updates, news, and insider tips from the experts at PrestaShop!

Ecommerce Blog - The #1 Source for Ecommerce News, Tips and Trends!
 

< Back to the Blog home

How to Optimize the php.ini File for your Website

The php.ini file is one of the most crucial server configurations. Web-hosts have a variety of specific configurations for their servers. In this article, I’ll explain what the php.ini file is and what specific settings you should pay close attention to in order to bypass common errors and optimize your online store or website.
php.ini

What is the php.ini file and why should you care?

The php.ini file is a PHP server’s main configuration file. When your PHP server is first turned on or restarted, it reads the php.ini to load various settings and configurations. These settings control different server aspects like memory limits, data handling and file uploads.
Your php.ini file is located in your server’s root or public_html folder, not your PrestaShop files. Most hosting companies will allow you to access and change the php.ini file. If you can’t find it or do not have not access to it, contact your hosting company and they will work with you to change these settings.
It’s important to understand the php.ini file because its settings can be customized to solve common server-side errors and speed up your entire PrestaShop store. Let’s review some of the essential settings that you can change to optimize your online store.

Which settings are more important?

  • memory_limit = Maximum amount of memory a script may consume, in megabytes

Webhosts have default values regarding the amount of memory you are allowed on your account. PrestaShop 1.5 recommends 64mb as a minimum, which is very lightweight. However, if you have a more resource intensive store, you may need to change this value. This setting is especially important to consider if you are having a “Fatal Error: Allowed memory size” issue or if your Modules tab in your Back-Office is returning a blank white page.

Let’s increase this value to 128M. If you are still having problems with memory errors, increase the value to 256M to be safe. I’ve seen some extremely large resource intensive stores on dedicated hosting have as much as a 1-2GB of memory; it really depends on your store.
Find your php.ini file and search for “memory_limit”. Some shared hosts will have the default limit at 32M but most will have either 64M or 128M.
When you change it, the line in your php.ini file will look like this
“memory_limit = 128M”

———————————————————————————————————

  • max_input_time = Maximum amount of time each script can wait for requested data, in seconds
  • max_execution_time = Maximum allowed execution time of each script, in seconds.

These two time limits are connected. The “max_input_time” setting controls how long a script can wait to receive data requested from the server while the “max_execution_time” controls how long a script can run on your server after the data has been received. Most hosts have the default setting value to 30 seconds each. As they are both connected, I recommend disabling the “max_input_time” and increasing the “max_execution_time” to 300 seconds.
The maximum execution time is a common limit that is exceeded. It’s better to change this value to something much higher as some special scripts need the extra time to execute and complete. These settings are especially important if you are performing resource intensive scripts like adding a large amount of combinations, backing up a database, importing a CSV file and regenerating images.
Find your php.ini file and search for “max_input_time” and “max_execution_time”. We will use the value -1 to disable the “max_input_time” and 300 to increase the “max_execution_time”.
When you change them, the lines in your php.ini file will look like this,
“max_input_time=-1;” and “max_execution_time=300;”

———————————————————————————————————

  • upload_max_filesize: Maximum file size your server will allowed to be uploaded, in megabytes
  • post_max_size: Maximum data size allowed to uploaded, in megabytes

These two values are intertwined. They control the size of files and data that you are allowed to upload to your server. The post_max_size must be bigger or equal to the value of upload_max_filesize. These settings are especially important if you are having issues uploading large, high resolution pictures for your slideshow or products. Also, downloadable products like digital CD’s and large .pdf files will need to have these settings changed in order to upload them to your store.
Find your php.ini file and search for “upload_max_filesize” and “post_max_size”. By default these settings can be anywhere from 2-5 megabytes. Let’s change them to 25M.
When you change them, the lines in your php.ini file will look like this
“upload_max_filesize=25M;” and “post_max_size=25M;”

———————————————————————————————————

  • max_input_vars: The maximum number of variable form elements that can be submitted to a single page.

The “max_input_vars” setting in the php.ini file is a relatively new option starting last year from PHP 5.3.9. It allows you to control the maximum number of form elements on a page. Some webpages have a large amount of forms/fields for administrative or page configuration purposes. In those cases, we need to increase the number of this value in order to properly view those pages. In PrestaShop, this setting is important if you are having trouble viewing, editing or saving translations in your Back-Office.
Find your php.ini file and search for “max_input_vars”. By default, most hosts have this limit set to 1000. To be safe, we’ll change it to 10000.
When you change it, the line in your php.ini file will look like this
“max_input_vars = 10000;”

[Technical Note: If your hosting provider has the “suhosin” php patch, you will need to change two more values to the same number. These values are
suhosin.get.max_vars = 10000;
suhosin.post.max_vars = 10000; ]

Piecing it all together

Let’s take a look at the summary of different settings we changed to bypass server-side errors and optimize your PrestaShop store’s efficiency.

  • memory_limit = 128M
  • max_execution_time=300;
  • max_input_time=-1
  • upload_max_filesize=25M;
  • post_max_size=20M;
  • max_input_vars=10000
  • suhosin.get.max_vars = 10000;
  • suhosin.post.max_vars = 10000;

php.ini file

Hosting Restrictions

If you are using shared hosting, be careful with how much you increase these values. With so many hosting providers having their own rules and regulations, this guide should not be used as a fool-proof method. It is always good to check with your hosting company to get further information about what configuration changes are allowed.
If you make these edits to the php.ini file and nothing changes, chances are that your host does not allow you to edit it manually. In those situations, you would need to contact your hosting provider and work with them to edit these values.

Thankfully, PrestaShop provides its users two world class Hosting Partners. InMotion Hosting are both fully prepared for easy customization and optimization of your php.ini file. If you are having any trouble at all with your current hosting company, make sure to check out those links for special discounted PrestaShop plans.

Now you are well prepared to customize your PHP Server’s configuration to run at optimum levels. Comment below and let me know how these tips worked for you.

  1. Thank you for your tips :)

  2. Author: Thomas

    Date: June 28, 2013 at 6:28 pm

    Of course, max_input_vars will have a significantly effect on performance, this is the tip that all sysadmin use ;-)

    What about Varnish, MySQL tuning, Linux distribution, atime etc… ? And what the Php version you suggest ?

    • Author: benjamin utterback

      Date: June 28, 2013 at 7:47 pm

      Hi Thomas Decaux thanks for your feedback. These php.ini configurations can be tuned not only to increase performance, but also to bypass common issues some PrestaShop users have trouble figuring out.
      The max_input_vars setting will not improve your servers performance per se but some users have issues saving or editing the Localization>Translation page. Increasing the max_input_vars value will solve that in most cases.
      As for the php version that I suggest, it will be PHP 5.3. What version do you like? Thanks for reading!

  3. Author: designhaus42

    Date: June 28, 2013 at 9:31 pm

    Varnish is a bit tricky to setup with Prestashop. The default install goes fine, the url rewriting has some issues. If you want me to send you the mysql config file I have been testing, send me a msg. the the config of mysql really depends on how your server is set up (memory, ect) and how your prestashop is being used, and what version is being used. If you have ssh access, I would recommend starting with this script, let your shop and mysl run a couple weeks and then check it. https://raw.github.com/major/MySQLTuner-perl/master/mysqltuner.pl

  4. Author: D-Man

    Date: July 9, 2013 at 7:11 pm

    would adjusting:

    •upload_max_filesize: Maximum file size your server will allowed to be uploaded, in megabytes
    •post_max_size: Maximum data size allowed to uploaded, in megabytes

    stop the 413 error code I am currently receiving when trying to upload large size pictures to my prestashop site?

    • Author: benjamin utterback

      Date: July 9, 2013 at 8:59 pm

      Hi D-Man, thanks for the comment. The 413 error code can be solved by using Increase the value of parameters memory_limit and post_max_size in PHP configuration.
      If the module suhosin for PHP is installed on the server, increase parameter suhosin.post.max_value_length. Usually, the value of 32 Mb is enough.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>