Php ini ubuntu location

There are several ways to find the php.ini file location in Ubuntu and Centos Linux servers. It is also interesting to note that there are usually several php.ini files on the server. Here will show you how to find the file and determine which one is the active configuration file.

Using Locate to Find php.ini File Location

Use the following command to get a list of all of the php.ini files.

$ locate php.ini

This will give an output similar to this:

/etc/php/7.2/apache2/php.ini
/etc/php/7.2/cli/php.ini
/etc/php/7.2/fpm/php.ini
/etc/php/7.3/cli/php.ini
/etc/php/7.4/apache2/php.ini
/etc/php/7.4/apache2/php.ini.save
/etc/php/7.4/apache2/php.ini.ucf-dist
/etc/php/7.4/cli/php.ini
/etc/php/7.4/cli/php.ini.ucf-dist
/etc/php/7.4/fpm/php.ini
/etc/php/7.4/fpm/php.ini.ucf-dist
/etc/php/8.0/cli/php.ini
/usr/lib/php/5.6/php.ini-development
/usr/lib/php/5.6/php.ini-production
/usr/lib/php/5.6/php.ini-production.cli
/usr/lib/php/7.0/php.ini-development
/usr/lib/php/7.0/php.ini-production
/usr/lib/php/7.0/php.ini-production.cli
/usr/lib/php/7.1/php.ini-development
/usr/lib/php/7.1/php.ini-production
/usr/lib/php/7.1/php.ini-production.cli
/usr/lib/php/7.2/php.ini-development
/usr/lib/php/7.2/php.ini-production
/usr/lib/php/7.2/php.ini-production.cli
/usr/lib/php/7.3/php.ini-development
/usr/lib/php/7.3/php.ini-production
/usr/lib/php/7.3/php.ini-production.cli
/usr/lib/php/7.4/php.ini-development
/usr/lib/php/7.4/php.ini-production
/usr/lib/php/7.4/php.ini-production.cli
/usr/lib/php/8.0/php.ini-development
/usr/lib/php/8.0/php.ini-production
/usr/lib/php/8.0/php.ini-production.cli

The above output may not be very helpful in drilling down to the active php.ini file location.

You can use the PHP CLI to get the configuration file that is being used in your setup with the following command:

$ php -i | grep 'php.ini'

From the output look for the line similar to this:

Loaded Configuration File => /etc/php/7.4/cli/php.ini

You can also use the following to retrieve the same output:

$ php -r "echo php_ini_loaded_file().PHP_EOL;"

With the expected result being:

/etc/php/7.4/cli/php.ini

You can use PHPs phpinfo function as follows:

$ php -r "phpinfo();" | grep php.ini

With the following as the result.

Configuration File (php.ini) Path => /etc/php/7.4/cli
Loaded Configuration File => /etc/php/7.4/cli/php.ini

In case you need to get the php.ini file location for the settings used by the webserver you will need to use the following function from within a PHP file created in the web server document root and accessed from a web browser.

echo php_ini_loaded_file().PHP_EOL;

There you have it you should now be able to find the php.ini file location in Ubuntu and Centos Linux servers including determining the one that is active.

Found this article interesting? Follow Brightwhiz on Facebook, Twitter, and YouTube to read and watch more content we post.

Introduction

PHP is a server side scripting language used by many popular CMS and blog platforms like WordPress and Drupal. It is also part of the popular LAMP and LEMP stacks. Updating the PHP configuration settings is a common task when setting up a PHP-based website. Locating the exact PHP configuration file may not be easy. There are multiple installations of PHP running normally on a server, and each one has its own configuration file. Knowing which file to edit and what the current settings are can be a bit of a mystery.

This guide will show how to view the current PHP configuration settings of your web server and how to make updates to the PHP settings.

Prerequisites

For this guide, you need the following:

  • Ubuntu 14.04 Droplet
  • A non-root user with sudo privileges (Initial Server Setup with Ubuntu 14.04 explains how to set this up).
  • An understanding of editing files on a Linux system. The Basic Linux Navigation and File Management tutorial explains how to edit files.
  • A web server with PHP installed.

There are many web server configurations with PHP, but here are two common methods:

  • How To Install a LAMP stack on Ubuntu 14.04
  • One-Click Install LAMP on Ubuntu 14.04 with DigitalOcean

This tutorial is applicable to these DigitalOcean One-click Apps as well:

  • LAMP
  • LEMP
  • WordPress
  • PHPMyAdmin
  • Magento
  • Joomla
  • Drupal
  • Mediawiki
  • ownCloud

Note: This tutorial assumes you are running Ubuntu 14.04. Editing the php.ini file should be the same on other systems, but the file locations might be different.

All the commands in this tutorial should be run as a non-root user. If root access is required for the command, it will be preceded by sudo.

Reviewing the PHP Configuration

You can review the live PHP configuration by placing a page with a phpinfo function along with your website files.

To create a file with this command, first change into the directory that contains your website files. For example, the default directory for webpage files for Apache on Ubuntu 14.04 is /var/www/html/:

  1. cd /var/www/html

Then, create the info.php file:

  1. sudo nano /var/www/html/info.php

Paste the following lines into this file and save it:

info.php


Note: Some DigitalOcean One-click Apps have an info.php file placed in the web root automatically.

When visiting the info.php file on your web server (http://www.example.com/info.php) you will see a page that displays details on the PHP environment, OS version, paths, and values of configuration settings. The file to the right of the Loaded Configuration File line shows the proper file to edit in order to update your PHP settings.

Php ini ubuntu location

This page can be used to reveal the current settings your web server is using. For example, using the Find function of your web browser, you can search for the settings named post_max_size and upload_max_filesize to see the current settings that restrict file upload sizes.

Warning: Since the info.php file displays version details of the OS, Web Server, and PHP, this file should be removed when it is not needed to keep the server as secure as possible.

Modifying the PHP Configuration

The php.ini file can be edited to change the settings and configuration of how PHP functions. This section gives a few common examples.

Sometimes a PHP application might need to allow for larger upload files such as uploading themes and plugins on a WordPress site. To allow larger uploads for your PHP application, edit the php.ini file with the following command (Change the path and file to match your Loaded Configuration File. This example shows the path for Apache on Ubuntu 14.04.):

  1. sudo nano /etc/php5/apache2/php.ini

The default lines that control the file size upload are:

php.ini

post_max_size = 8M
upload_max_filesize = 2M

Change these default values to your desired maximum file upload size. For example, if you needed to upload a 30MB file you would changes these lines to:

php.ini

post_max_size = 30M
upload_max_filesize = 30M

Other common resource settings include the amount of memory PHP can use as set by memory_limit:

php.ini

memory_limit = 128M

or max_execution_time, which defines how many seconds a PHP process can run for:

php.ini

max_execution_time = 30

When you have the php.ini file configured for your needs, save the changes, and exit the text editor.

Restart the web server to enable the changes. For Apache on Ubuntu 14.04, this command will restart the web server:

  1. sudo service apache2 restart

Refreshing the info.php page should now show your updated settings. Remember to remove the info.php when you are done changing your PHP configuration.

Conclusion

Many PHP-based applications require slight changes to the PHP configuration. By using the phpinfo function, the exact PHP configuration file and settings are easy to find. Use the method described in this article to make these changes.

Where is the PHP ini file located?

user. ini file is the default configuration file for running applications that require PHP. It is used to control variables such as upload sizes, file timeouts, and resource limits. This file is located on your server in the /public_html folder.

Where is PHP ini file Linux?

ini is usually located in /etc/php/8.1/fpm/php.