PHP: Common configuration changes

PHP works straight out of the box with a default configuration setup specified by the PHP group which is quite restrictive; it is common for developers and server administrators to adjust the PHP settings to enable PHP applications to run smoothly or successfully. The PHP configuration settings are in a file called php.ini, the location of this file differs from each web server setup and operating system. To find out you can create a php file with the following code to view all the details about the PHP installation.

The loaded php.ini file can be found by looking through the data which is outputted from above PHP function, you are looking for the following two fields (Configuration File Path and Loaded Configuration File) usually located near the top of the list. If the loaded configuration file is none then PHP was unable to find a configuration file and so has reverted to the default PHP settings, to adjust the settings we need to create a php.ini in the location it is looking PHP comes with two standard php.ini files one for development and the other for production, all we need to do is rename the file we want to use to php.ini and then adjust the required settings.

Here is a link to the official PHP website manual for this file http://php.net/manual/en/ini.core.php this is a massive list of all the possible settings and there default value. Normally a setting not specified will revert to the default.

Important Information
Shared hosts have limits in place and my not allow you to directly modify the PHP configuration this depends entirely on the host and different server setups may or may not allow you to modify this file. If it is not possible to adjust the PHP configuration directly there are alternatives such as htaccess files and PHP built in method. I have written this post to tell you how to adjust your settings using alternative methods and why your hosts won’t allow you modify this file directly.

Common Changes
Your most common changes will be related to the execution times and script resource usage which if not changed cause allot of scripts which either allow uploading, image handling or large execution times to end prematurely. This is my recommendation of common changes and if you believe I have missed anything please post a comment.

Setting What it does
max_execution_time This is the maximum amount of time a PHP script can run before automaticly being killed and recieveing a timeout error message. The default is 30 seconds which is suitable for most websites but it is quite common for a script to need to run longer due to file uploading.
memory_limit This is how much memory a individual PHP script can use at once, normally the default setting is adequate but if you are handling images, file uploads and large amounts of data (database or files) this setting will need adjusted. PHP will give you a error message tell you that the memory usage it to high.
post_max_size This is the maximum size which PHP will allow for post data, normally this setting is ok by default but if you are uploading files or sending large amounts of data via POST you may need to increase this setting. Remember this is the total post size not individual post elements, meaning if you upload a 8MB file and a large string content which is 1MB the total post will be 9MB.
upload_max_filesize As well as having the max post setting above there is also a limit on the max file size which can be uploaded via PHP, this setting is per file so if your script uploads multiple files you should be ok as long as each file is below this limit. You must remember to adjust the other settings above to be able to successfully upload large files or compensate for slow internet connections (which will require your script to wait longer for successfully upload).
max_input_time This is the maximum time a PHP script will spend processing data received via POST and will need adjusting if large amounts of data is being transferred.
sendmail_path This is the default PHP setting for Linux servers it specifies the mail path used by PHPs mail() function. This will only work under Linux and must be commented and the two settings below used for Windows.
SMTP This is used to tell PHPs mail() function which SMTP server to use to send emails, this is only required on Windows servers and the setting above should be used for Linux servers. Due to PHP lacking the ability to use authentication you need to specify a SMTP server which will allow usage without authentication, most good SMTP servers have the ability to allow unauthorised connections internally.
sendmail_from This is the from email address which will be used when sending an email via PHPs mail() function, this setting is only required to be set on Windows servers and will cause errors if not set.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.