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.
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 isĀ /var/www/html/
:
cd /var/www/html
Then, create the info.php
file:
sudo nano /var/www/html/info.php
Paste the following lines into this file and save it:
<?php
phpinfo();
?>
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.

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.
Locating php.ini
File for Nginx on ubuntu
Depending on the PHP version you are using, the php.ini
file is typically located in one of the following directories:
/etc/php/7.4/fpm/php.ini # For PHP 7.4
/etc/php/8.0/fpm/php.ini # For PHP 8.0
/etc/php/8.1/fpm/php.ini # For PHP 8.1
We can use the command php --ini
in the terminal to find the path of the php.ini
file.
root@ubuntu:~# php --ini
Configuration File (php.ini) Path: /etc/php/8.1/cli
Loaded Configuration File: /etc/php/8.1/cli/php.ini
Scan for additional .ini files in: /etc/php/8.1/cli/conf.d
Additional .ini files parsed: /etc/php/8.1/cli/conf.d/10-mysqlnd.ini,
To find the exact path, run:
php --ini | grep "Loaded Configuration File"
This is the output:
root@ubuntu:~# php --ini | grep "Loaded Configuration File"
Loaded Configuration File: /etc/php/8.1/cli/php.ini
Modifying the PHP Configuration
PHP configurations are managed through theĀ php.ini
Ā file. Editing this file allows you to customize various PHP settings such as enabling or disabling short tags, setting memory limits, and more.
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.):
sudo nano /etc/php5/apache2/php.ini
The default lines that control the file size upload are:
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:
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
:
memory_limit = 128M
or max_execution_time
, which defines how many seconds a PHP process can run for:
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:
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.
Restart Nginx Services To Apply Changes
After making the changes, we need to restart the services to apply the changes.
For Nginx:
sudo systemctl restart php8.1-fpm
sudo systemctl restart nginx
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.