Location of php.ini on Ubuntu 20.04 Focal Fossa Linux

The objective of this guide is to learn how to find location of the loaded php.ini. file.

In this tutorial you will learn:

  • How to find location of php.ini from command line
  • How to find location of php.ini by using the phpinfo() function

Find the location of php.ini on Ubuntu 20.04 Focal Fossa Linux

Find the location of php.ini on Ubuntu 20.04 Focal Fossa Linux

Software Requirements and Conventions Used

Software Requirements and Linux Command Line Conventions
Category Requirements, Conventions or Software Version Used
System Installed Ubuntu 20.04 or upgraded Ubuntu 20.04 Focal Fossa
Software Apache, Nginx, PHP, PHP-FPM
Other Privileged access to your Linux system as root or via the sudo command.
Conventions # – requires given linux commands to be executed with root privileges either directly as a root user or by use of sudo command
$ – requires given linux commands to be executed as a regular non-privileged user

Location of php.ini on Ubuntu 20.04 step by step instructions

  1. Create a file called phpinfo.php within your web-server’s root directory eg. /var/www/html/ with the following content:
    <?php
    
    // Show all information, defaults to INFO_ALL
    phpinfo();
    
    ?>?


  2. Navigate your web browser to the URL location http://SERVER-HOST-OR-IP/phpinfo.php. Search the page for the loaded php.ini configuration file.
  3. Alternatively execute the following command to locate the loaded php.ini configuration file for the command line (cli) php command:

    php --ini | grep Loaded
    Loaded Configuration File:         /etc/php/7.3/cli/php.ini
    

    Please, note that the above php.ini file location is used by phpcommand. For the Apache web-server the above path will translate to:

    /etc/php/7.3/apache2/php.ini
    

    For Nginx or Apache with PHP-FPM the path will most likely be:

    /etc/php/7.3/fpm/php.ini