With the many varying PHP configurations on different hosts, it can be difficult to get all the features in PrestaShop working correctly.
Below you’ll find 12 tips to optimise your php.ini file for PrestaShop including an introductory video to help you really see how to make the changes.
Watch this video first to get an understanding of what you should be looking for and learn how to make the changes that are described in detail in the Tips below.
PrestaShop requires an Apache 1.3 or IIS 6 or later server with at least PHP 5.1.0 and MySQL 5 installed and the GD Library enabled. Most hosts’ servers meet these requirements, but check on your host’s website to make sure the package you purchase lists these as features. When you run the PrestaShop Installer, it will check to make sure your server meets the requirements on the second step. If your server meets all the requirements, then you should see the following in the “Required set-up” section:
If you see a red X instead of a green tick for any of the options, then you won’t be able to install PrestaShop. If “Is PHP 5.1.0 or later installed?” or “Is MySQL support is on?” has a red X, then your host’s server isn’t capable of running PrestaShop. If it’s “Is GD Library installed?” that has a red X, then you’ll need to ask your host to install the GD Library on your server. If it’s “Can create new files and folders?” that has a red X, make sure your host account has permission to create new files and folders. If it’s “Can upload files allowed?” that has a red X, then your server’s default PHP configuration will prevent you from installing PrestaShop.
Fortunately, most hosts let you override the default PHP configuration. When a PHP file is executed, PHP will look for a php.ini file in the same directory as the file that is being executed. If it finds one, it will read it and override the default PHP settings. PrestaShop doesn’t automatically create these files for you, since many of the settings are optional, and some users may have other software like WordPress installed that requires different settings.
For this reason, you need to manually copy your php.ini file to three different places. First, you must put a copy in the root directory, which is read whenever the Front Office is viewed. Second, you must put a copy in the renamed admin directory, which is read whenever the Back Office is accessed. Lastly, you must put a copy in the install directory, so that the installer reads the file, displays green ticks instead of red Xs, and lets you proceed with the installation. What you enter in your php.ini file depends on which items have red Xs.
Tip 1: If the “Can upload files allowed?” item has a red X, you should search for and change the file_uploads setting in php.ini, or add it if it doesn’t exist:
; Allow files to be uploaded
file_uploads = On
If you’ve done this correctly, then the red X should change to a green tick and you will be able to continue with the installation. That doesn’t necessarily mean that all of PrestaShop’s features will work. There is another “Optional set-up” section with more configuration options that should be met for PrestaShop to run optimally.
The optional set-up section has many items that will improve the security and performance of PrestaShop:
Tip 2: The “Can open external URLs?” item checks whether PrestaShop can connect to external URLs to display the latest news and help information and automatically update currency rates. If you have a red X for this item, you should search for and change the allow_url_fopen setting in php.ini, or add it if it doesn’t exist:
; Allow external URLs to be opened
allow_url_fopen = On
Tip 3: The “Is PHP register global option deactivated (recommended)?” item recommends that you disable the register global option in PHP to improve security. The register global option automatically turns query strings in the URL into global variables. If you forget to initialise a variable, it is possible for anyone to initialise it with whatever value they like just by adding a query string to the URL, which could be misused by hackers. For that reason, if you have a red X for this item, you should search for and change the register_globals setting in php.ini, or add it if it doesn’t exist:
; Disable PHP register globals
register_globals = Off
Tip 4: The “Is GZIP compression activated (recommended)” item checks whether PrestaShop can extract GZIP files on your server, which is done when installing modules and localisation packs from the Back Office. If this item has a red X, you should search for and change the zlib.output_compression setting in php.ini, or add it if it doesn’t exist:
; Enable GZIP compression at the default level
zlib.output_compression = On
zlib.output_compression_level = 6
The compression level can be set between 1 and 9, where 1 is the least compression and 9 is the most compression. It is best to leave the compression level at 6, which provides the best compression without degrading server performance.
Tip 5: The “Is Mcrypt extension available (recommended)?” item checks whether PrestaShop can encrypt its cookies using Mcrypt, which is faster than the Blowfish that is used by default. If this item has a red X, you should search for and change the following setting in php.ini, or add it if it doesn’t exist:
; Load mcrypt extension
Tip 6: The “Is PHP magic quotes option deactivated (recommended)?” item recommends that you disable magic quotes, which automatically escapes all variables so that ‘, ” and \ are converted to \’, \” and \\. Although automatically escaping strings may sound useful, it is better to disable it to manually escape strings instead, so that you can choose exactly which strings you want escaped. If this item has a red X, you should search for and change the magic_quotes settings in php.ini, or add them if they don’t exist:
; Disable PHP magic quotes
magic_quotes_gpc = Off
magic_quotes_runtime = Off
magic_quotes_sybase = Off
Tip 7: The “Is Dom extension loaded?” item checks whether PrestaShop can use the PHP Dom extension to read XML files, which has more features than SimpleXML. If this item has a red X, you should ask your host to install this extension on your server.
Tip 8: The “Is PDO MySQL extension loaded?” item checks whether PrestaShop can use the PDO MySQL extension, which provides a uniform API so that SQL code can continue to work even if the database type is changed. If this item has a red X, you should search for and change the following settings in php.ini, or add them if they don’t exist:
; Load PDO MySQL extension
After following these tips, you should now have all items ticked in the installer and be able to use PrestaShop in its optimal configuration.
Memory and Size Limits
There are times when you may encounter an error because you’ve exceeded a PHP limit that is set on your server. You can increase these limits in your php.ini file.
Tip 9: One common limit that is exceeded is the memory limit. One case where you may encounter this limit is when you upload a full-resolution image and PHP is unable to load the entire image into memory. In this case, you could manually reduce the size of the image before uploading it, or you could increase the memory limit by searching for and changing the memory_limit setting in php.ini, or add it if it doesn’t exist:
; Set memory limit in megabytes
memory_limit = 128M
If you are using shared hosting, which is common with inexpensive hosting packages, try to set the smallest limit you can that stops the memory limit error. If you set the memory limit too high, it is possible for inefficient code to use up too much memory and cause performance issues for other users on your server. In that case, your host may shut down your account until you reduce your memory usage.
If you find yourself needing a high memory limit, it may be better for you to upgrade to a virtual private server (VPS) or a dedicated server so that you don’t have to share the server’s RAM. You can then increase the RAM as high as you like, as long as it doesn’t exceed the total RAM that is available in the server.
Tip 10: The other common limit that is exceeded is the maximum execution time. One case where you may encounter this limit is when you import a large number of products. Once the maximum execution time has elapsed, PHP will stop the script and display an error message. You can increase the maximum execution time by searching for and changing the max_execution_time setting in php.ini, or add it if it doesn’t exist:
; Set maximum execution time in seconds
max_execution_time = 120
Like the memory limit, if you are using shared hosting, you should try to set the shortest time you can that stops the timeout error. If you set the maximum execute time too high, it is possible for inefficient code to cause many PHP scripts to be running at the same time for an extended period, using up a lot of the server’s resources. In that case, your host may shut down your account until you reduce the number of PHP scripts that are running.
If you find yourself needing a high maximum execution time, it may be better for you to upgrade to a VPS or a dedicated server so that you don’t have to share the server’s resources.
Tip 11: When uploading a large product image, you may also encounter the maximum file upload size limit. In this case, you could manually reduce the size of the image, or you could increase the maximum file upload size by searching for and changing the upload_max_filesize setting in php.ini, or add it if it doesn’t exist:
; Set maximum file upload size in megabytes
upload_max_filesize = 32M
Set the value to the size of the largest product image or downloadable product you expect to upload through the Back Office. That way, you will get an error message if you accidentally upload a product image that is too high resolution. It is best to resize product images to the resolution they are displayed in the Fancybox before uploading to minimise the amount of disk space used on the server. Downloadable products should also be compressed as ZIP files to reduce the amount of space used.
Tip 12: Two more limits that may be encountered are the maximum post size and maximum input time. One case where you may encounter these limits is when you are saving a large number of module translations. In this case, you will need to increase the maximum post size and maximum input time by searching for the post_max_size and max input time settings in php.ini, or adding them if they don’t exist:
; Set maximum post size in megabytes
post_max_size = 32M
; Set maximum input time in seconds
max_input_time = 180
If you are using shared hosting, you should try to set the smallest values you can that stop the error messages. A value that is too high may use up too much disk space or other resources on the server, causing performance issues for other users on your server.
So there you go. That’s 12 tips on how to get the php.ini file working for you instead of against you. Please let us know what your experiences have been with php.ini files in the comments below.
If you enjoyed this article, you’ll be interested to know that we’ve created a video version of these tips as part of our premium training – PrestaShop 1.4 Tutorials. This is just one of the many tutorials to help you get your PrestaShop store up and running the easy way.
Along with this tutorial, you’ll find over 36 other tutorials on the installation, setup, and configuration of a PrestaShop store. Check out PrestaShop 1.4 tutorials.