KNOWNHOST BLOG

What Is php.ini?

what is php.ini

The key to good website design is having control over every aspect. One avenue of control comes with a ‘php.ini’ file. But what exactly is it?

In this article, KnownHost explores what php.ini is, how to use it to optimize website performance, and looks at some key considerations in managing file settings.


What Is php.ini? 

The term ‘php.ini’ contains two key ideas, and it’s essential to understand both to learn what the file does.

We’ll start with PHP, which is short for ‘PHP: hypertext preprocessor’, an open-source, server-side programming language used in web development.

PHP is used for multiple purposes, from server-side scripting to command-line scripting and writing desktop applications.

The ‘.ini’ portion is short for initialization and is a basic setup file that contains configuration information for a particular program. ‘.ini’ is essential for the proper setup of software on a computer.

Putting both halves together, we see that a php.ini file is the basic setting and configuration file for a website, using the PHP scripting language and a default initialization file for applications that run using PHP.

The information included in a php.ini file relates to aspects of the runtime of a program, for example, the program execution time, memory limit, or an other variables that affect how PHP handles.


How Can I Optimize PHP Performance Using php.ini Settings?

PHP performance can be optimized through a php.ini file in the following ways:

  • Taking advantage of available PHP features such as ‘disable_functions’ that helps reduce the number of potentially harmful functions available such as ‘exec’, ‘passthru’ and ‘popen’.
    • This helps improve PHP Security
  • Debugging notifications are useful during development as they can help identify errors. However, turn them off before going live to cut down on the processing power needed to perform the debug function and run the server.
  • Know the variables you need to tune in order to help ensure PHP executes smoothly such as ‘max_execution_time’, ‘memory_limit’, gzip compression or enabling opcache.


Where to find php.ini

The configuration for PHP variables lies within the php.ini file.

To find the php.ini file for a particular server in a default setup, you’ll want to know where the file is located. This can be done through console (SSH) by first identifying the file.

# php -i | grep php.ini
Configuration File (php.ini) Path => /opt/cpanel/ea-php82/root/etc
Loaded Configuration File => /opt/cpanel/ea-php82/root/etc/php.ini

From there, it’s just modifying those variables through your preferred text editor (nano, vim, vi)
Alternatively, you can place a ‘php.ini’ file within your public_html directory and modify specific configurations from there.

For more information on how to adjust php.ini settings in DirectAdmin, check out our helpful guide!

How to modify PHP settings

Modifying a PHP file is essential for making changes and tweaks to a functioning program to improve performance or make back-end changes.

Below is a step-by-step guide on how to modify PHP settings:

  • Step 1: Log into your panel (such as cPanel) that provides a file manager
  • Step 2: Locate your file manager and ensure that you’re in it
  • Step 3: Create your ‘php.ini’ file in the ‘public_html’ directory
    • For cPanel users, this may be ‘.user.ini’ — a hidden file.
  • Step 4: Set the configuration variables of PHP that need to be changed.
  • Step 5: Click “save changes” once the necessary edits have been made.

To verify your changes, you can use a PHP Info page which will help you verify if your changes are active.

What Are Some Security Considerations When Configuring php.ini?

When configuring your ‘php.ini’ file, there are some specific variables that you may want to ensure are set to help prevent security concerns.

Some of these are variables such as ‘disabled_functions’ mentioned earlier in this article. There are various functions that could lead to security issues if left open in the event of a compromised website.

Others are variables such as ‘allow_fopen_url’ which allows PHP to accept filenames that operate on remote files using HTTP or FTP URL’s. This can allow malicious content in your applications.

If unsure of what variables you need to enable, always ask your hosting provider or find a specialist who can assist.

How Do I Back Up And Restore php.ini Settings?

Sometimes you want to revert to your original configuration settings, but you don’t want to remove your existing in case the issue isn’t the PHP configurations you have outlined.

Here’s a step-by-step guide on how to back up and restore php.ini settings, so it’s easy to revert to previous file versions in response to errors:

Step 1: Open cPanel or any other file viewer.

Step 2: Open the file manager.

Step 3: Navigate to the public directory.

Step 4: Copy your ‘php.ini’ file and name it ‘php.ini.bak’

You now have a copy of your original configuration file within your directory that you can revert to should you want too.


PHP configuration files assist in ensuring that the proper variables are there for an efficient website. But to get a website up and running there needs to be a hosting provider!

Here at KnownHost, we offer web hosting services, from VPS hosting, to dedicated hosting – with industry leading uptime, so you never have to worry about crashing, whether you’re coding or the website is live.

For more information on our web hosting services – and for help getting started on your website journey – contact our expert team today.

Frequently Asked Questions (FAQs)

Q: How do I enable php.ini extensions?

A: First, locate the php.ini file on your webserver. Navigate to the bottom of the file and paste the following with the extension you’re trying to enable. For example, if it was Redis PHP extension you would use ‘extension=redis.so’, then save the document.

Q: Is a restart required after editing a php.ini file?

A: In most cases, after modifying the ‘php.ini’ file — there should be no restart required. However, depending on the method used such as ‘PHP-FPM’ the PHP service may need to be restarted. When PHP-FPM is not in use, a simple Apache restart is usually quick enough to ensure that PHP gets reloaded.