Where is php.ini file located?

When you are working with various flavors of Linux servers, you may not know where the php.ini file is located. The php.ini file is a PHP configuration file that is used to customize the behaviors and features of the PHP scripting language. A php.ini file is placed in different directory locations of a server depending on the flavor and version of the Linux server you're working with.

Finding the location of the php.ini file in a PHP development environment involves a few different methods. Here are some common ways to locate the php.ini file:

1. Command Line

If you have shell access, you may use the following Linux commands to locate the php.ini file.

%> whereis php
php: /usr/bin/php /etc/php.ini /etc/php.d /usr/lib/php /usr/include/php /usr/share/man/man1/php.1.gz

%> php -i |grep php.ini

# Or, you may use a brute force "find" command to search the entire filesystem
%> find / -type f -name "php.ini" -print

2. Using phpinfo()

You may also create a php info file to find the php configuration of a server. Create a file called "phpinfo.php", and add the following content:

The phpinfo() not only shows you where the php.ini file is located but also reveals details of your server and PHP configurations as well as installed modules and their versions.

<?php
phpinfo();
?>

Alternatively, you may run:
<?php
echo ini_get('loaded_configuration_file');
?>

Save the file, and run it on your server.

3. Common Locations

Depending on your operating system and PHP installation, php.ini is commonly located in the following directories.

/etc/php.ini (Red Hat/Centos)

/etc/php/php.ini
/etc/php7/php.ini

/etc/php7/apache2/php.ini (SuSE)

/usr/bin/php7/bin/php.ini

/usr/local/Zend/php.ini
/usr/local/lib/php.ini

C:\php\php.ini or C:\Windows\php.ini (Windows)

Conclusion

The exact path may vary based on your server setup, PHP version, and operating system. If you're using a local development environment, the php.ini file might be in the PHP installation directory. For production servers, it's often in system-specific directories.

By using these methods, you should be able to identify the location of the php.ini file in your PHP development environment.

Share this post

Comments (0)

    No comment

Leave a comment

All comments are moderated. Spammy and bot submitted comments are deleted. Please submit the comments that are helpful to others, and we'll approve your comments. A comment that includes outbound link will only be approved if the content is relevant to the topic, and has some value to our readers.


Login To Post Comment