Configuring php.ini File

This post is about the configuration of the php.ini file. This file contains a lot of important and useful configurations of the PHP Language which can be customized according to your needs and requirements. in Ubuntu php.ini file is located at /etc/php5/apache2/ directory. First, have a look at the file and then we’ll discuss some important configurations one by one. Run the following command in your terminal to open php.ini file in your gedit text editor:

sudo gedit /etc/php5/apache2/php.ini

Look through the file and if you can’t understand what is this all about, then don’t worry, in this section you’ll learn about the some useful directives available in this file.

Note: To easily get to a specific directive you can use the find command of your text editor.

Turning the PHP Scripting Engine On

engine = On

This directive is used to turn the PHP Scripting Engine On or Off. The default value is On obviously.

Setting Your Timezone

date.timezone = Asia/Karachi

This directive is used to set the Timezone for your site. I’m in Pakistan, so I’ll use ‘Asia/Karachi’. You can find the value for your timezone here.

En/Disabling Short Opening Tags

short_open_tag = Off

By default PHP turns off the short opening tags ‘<? … ?>’ and normally we use ‘<?php …. ?>’ opening tags. This is because some server’s don’t support the short opening tags of PHP. But you may use short opening tags if you want by turning this directive ‘On‘.

En/Disabling ASP Opening Tags

asp_tags = Off

This directive allow us to even use the ASP style opening tags ‘<% … %>‘. The default value is ‘Off‘. This directive might be useful for those who have ASP background and now want to use PHP. PHP welcomes those too and provide them the facility to use PHP with their habitual opening tags. The only thing they have to do is turn this directive ‘On‘.

Setting Precision

precision = 14

This directive is used to control the number of significant digits displayed after the decimal point in a floating number. The default value is 14, you can use whatever you want to.

Disable Classes

disable_classes =

This directive is sued to disable some classes if you want. It takes a list of classes separated by comma.

Maximum Execution Time for Each Scripting

max_execution_time = 0

PHP allows us to control the resources on our server to provide better performance to our site visitors. You can use this directive to set the maximum time a script can take to get executed. If, during this time, a script failed to be executed then we shouldn’t wait for that script, go a head and let another script to be executed.

The default value for this directive is 0 seconds, which means there is no time limit for the script and the script can take as many time to be executed as it needed. You can change it according to your site’s requirements.

Maximum Amount of Memory

memory_limit = 128M

Another resource controlling directive. This shows that how much maximum memory a script can take to complete its execution. M means Megabytes. You can change it according to the need of the scripts run on your site.

Turning Errors Displaying On/Off

display_errors = On

This directive allows you to turn On or Off the errors showing. The default value is ‘On’, but you must not use it for your production environment, use instead ‘Off’.

Error Reporting

error_reporting = E_ALL & ~E_NOTICE & ~E_STRICT & ~E_DEPRECATED

It’s important to change this value for the development environment to ‘E_ALL’ as the default value not show all errors and notice. On the other hand ‘E_ALL’  will show the every type of errors and notices, if any, to help you debugging easily.

Start Up Error Displaying

display_startup_errors = Off

It turns on or off the start up errors of PHP occurred during the start up process. The default value is Off, but you should turn it on for the development purpose. Always use ‘Off‘ for the production environment.

Showing Errors in HTML Format

html_errors = On

This directive states that whether the errors should be displayed using HTML to easy read and understanding or not. This obviously should remain ‘On’. But for CLI it’s value is changed to ‘Off’.

Maximum Size of $_POST

post_max_size = 128M

This directive is used to assign the maximum size of the PHP Super Global Array $_POST. The default value is 128MB, you can change it according to your needs.

Allowing File Upload

allow_url_fopen = On

This directive allow the user to upload files on the server. The default value is ‘On’.

Allowing require/include’

allow_url_include = Off

This directive allow us to ‘require’ or ‘include’ http:// or ftp as files in your web pages. The default value is ‘Off’.

In this post you’ve learned a bit about the very important and useful ‘php.ini’ file. You should further dive into this file deeply to know more about it. This would be very useful for you as a PHP a developer.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s