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.
PrestaShop requires anÂ ApacheÂ 1.3 orÂ IISÂ 6 or later server with at leastÂ PHPÂ 5.1.0 andMySQLÂ 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 thePHP 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 theupload_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.