How to change PHP.ini on Nginx

How to Change php.ini Settings on Nginx for PHP Configuration

  • December 20, 2023
  • in Web Tech
  • by AW Bali Digital
  •  | 405 views

The php.ini file plays a crucial role in configuring PHP settings for web servers. If you are using Nginx as your web server to run PHP applications, modifying the php.ini file allows you to customize PHP settings to suit your application’s requirements.

In this guide, we’ll walk you through the step-by-step process of changing the php.ini settings on an Nginx server.

Step 1: Locate the php.ini

The first step is to find the php.ini file on your server. Typically, PHP configuration files are located in the /etc/php/ directory, and the exact path may vary based on your server setup and PHP version. Use the following command to locate the appropriate file:

sudo find /etc/php/ -name php.ini

Once you’ve identified the correct php.ini file for your PHP version, proceed to the next step.

Step 2: Edit php.ini

Use a text editor of your choice to open the php.ini file. For example, you can use nano or vim:

sudo nano /etc/php/{PHP_VERSION}/fpm/php.ini

Replace {PHP_VERSION} with the actual version number of PHP installed on your server. This command opens the file for editing.

Step 3: Modify Settings

Within the php.ini file, you can modify various PHP settings. Common parameters include upload_max_filesize, post_max_size, and max_execution_time. Adjust these values to meet the requirements of your PHP application. For example:

upload_max_filesize = 20M
post_max_size = 20M
max_execution_time = 120

Save the changes and exit the text editor.

Step 4: Restart PHP-FPM

After making changes to the php.ini file, it’s essential to restart PHP-FPM to apply the new configurations. The command varies depending on your PHP version:

sudo service php{PHP_VERSION}-fpm restart

Replace {PHP_VERSION} with the actual PHP version number.

Step 5: Verify Changes

To ensure that the changes have taken effect, create a simple PHP file (e.g., info.php) with the following content:

<?php
phpinfo();
?>

Place this file in your web server’s document root and access it through a web browser. Look for the updated values in the PHP configuration section.

Conclusion:

By following these steps, you can successfully change the php.ini settings on an Nginx server, allowing you to tailor PHP configurations to the specific needs of your web applications. Regularly reviewing and adjusting these settings is essential for optimizing performance and ensuring smooth operation of PHP-based websites. (ART)

AW Bali Digital

© 2024 awbalidigital.com by PT BIKIN INOVASI TEKNOLOGI, All Rights Reserved.