Skip to main content

How to Change a PHP Setting With a php.ini or .user.ini File

You can modify specific PHP configurations for a single website by creating or editing a .user.ini or php.ini file. This method allows you to override global server settings for a specific directory without affecting other websites on the same server.

You can modify specific PHP configurations for a single website by creating or editing a .user.ini or php.ini file. This method allows you to override global server settings for a specific directory without affecting other websites on the same server.

Before you begin

You will need:

  • Access to the website's files via an FTP client or a File Manager.

  • The specific PHP setting name and the desired value (e.g., memory_limit, post_max_size, or max_execution_time).

Create and edit a .user.ini file

The .user.ini file is the preferred method for changing PHP settings for a specific website because it is processed by the PHP engine on a per-directory basis.

  1. Connect to your server using an FTP client or your hosting control panel's File Manager.

  2. Navigate to the root directory of the website you wish to modify.

  3. Create a new file named .user.ini (ensure the leading dot is included).

  4. Open the file and enter the desired configuration. Use the following format:

    memory_limit = 256M
    post_max_size = 128M
    max_execution_time = 300

  5. Replace the values above with the specific settings required for your application.

  6. Save the file and upload it to your server if you created it via an FTP client.

Using a php.ini file

In some specific environments, a php.ini file may be used instead of .user.ini.

Note: While php.ini is a standard configuration file, its behavior can vary depending on the server's PHP configuration. If your changes in a php.ini file do not take effect, use the .user.ini method described above.

  1. Navigate to the root directory of the website.

  2. Create a file named php.ini.

  3. Enter the desired settings using the same format as the .user.ini example.

  4. Save the file.

Confirm the result

To verify that the changes have been applied, you can use a PHP information script or a tool like php_info().

  1. Create a file named info.php in your website's root directory.

  2. Add the following code to the file:

    <?php php_info(); ?>

  3. Open the file in your web browser by navigating to http://example.com/info.php.

  4. Locate the specific setting (e.g., memory_limit) in the table to confirm it reflects the value you entered in your .user.ini or php.ini file.

  5. Warning: Delete the info.php file immediately after checking, as it reveals sensitive server configuration details to the public.

Limitations

  • File Naming: Ensure the filenames are exactly .user.ini or php.ini. A missing dot or a typo in the extension will prevent the server from recognizing the file.

  • Propagation: Changes to these files typically take effect immediately, but some server configurations may require a PHP process restart to recognize changes.

  • Scope: These files only affect the directory they are located in and any subdirectories. They do not affect other websites on the server.

Did this answer your question?