PHP is a widely-used scripting language. It relies on configuration files to define various settings. These settings control how PHP behaves. The configuration file is commonly known as php.ini. The location of this file can vary based on the platform and installation method. Below is a detailed guide to help you find the php.ini file across different platforms.

Common Locations of PHP Configuration Files

The table below shows typical locations where the php.ini file can be found on various platforms:

Platform Location
xampp {installation directory}/php/php.ini
macOS /private/etc/php.ini
Ubuntu < 16.10 /etc/php5/{cli,apache2,cgi}/php.ini
Ubuntu >= 16.10 /etc/php7/{cli,apache2,cgi}/php.ini
Ubuntu >= 18.04 /etc/php/{version}/{cli,apache2,cgi}/php.ini
RedHat/CentOS/Fedora /etc/php.ini

Understanding the Structure of php.ini

The php.ini file is structured in a simple key-value format. Each directive controls a specific aspect of PHP's behavior. For example:

memory_limit = 128M
upload_max_filesize = 2M
post_max_size = 8M

In this example:

  1. memory_limit defines the maximum memory a script can allocate.
  2. upload_max_filesize sets the maximum file size allowed for uploads.
  3. post_max_size limits the total size of POST data.

Finding Your PHP Configuration File

The location of the php.ini file can vary not just by platform, but also by PHP version and web server. To find the exact location of your php.ini file on Unix-based systems, use the terminal. Run the following command:

php -i | grep 'Loaded Configuration File'

This command shows the location of the loaded php.ini file. An example output might look like this:

$ php -i | grep 'Loaded Configuration File'
Loaded Configuration File => /etc/php.ini

Using .user.ini Files

In shared hosting environments, you may not have access to the main php.ini file. PHP allows per-directory configuration using .user.ini files. Place these files in the root directory of your web application. They can override certain settings defined in the global php.ini.

Example .user.ini:

memory_limit = 64M
upload_max_filesize = 5M
Discuss the article:

Comment anonymously. Login not required.