How to Configure PHP Settings on Your Server: A Clear and Practical Guide 

PHP powers most dynamic websites today, from popular content management systems like WordPress and Joomla to custom-built applications. To ensure your site runs smoothly and efficiently, sometimes you need to adjust PHP’s behavior, whether that means increasing memory limits, allowing larger file uploads, or extending script execution times. These settings are controlled through the php.ini configuration file on your server. 

This post explains how to locate, edit, and apply PHP settings on your server, based on Contabo’s tutorial and official guidance.  

What Is PHP and Why Configure Its Settings? 

PHP (Hypertext Preprocessor) is the scripting language behind many interactive and dynamic websites. It handles everything from user logins and form submissions to database interactions. 

The php.ini file is PHP’s main configuration file. It controls important aspects like: 

  • How much memory PHP scripts can use (memory_limit) 
  • The maximum size of uploaded files (upload_max_filesize) 
  • The maximum size of POST requests (post_max_size) 
  • How long scripts are allowed to run (max_execution_time) 
  • Whether PHP displays errors (display_errors), useful for debugging 

Tweaking these settings helps your website perform better and avoid common errors related to resource limits. 

Step 1: Identify Your PHP Version and Configuration File Location 

Before editing, you need to know which PHP version your server uses. Run this command in your terminal: 

 
bash 
php -v 
 

This will display the PHP version number, which helps you locate the correct configuration file. 

Depending on your server setup, the main php.ini file is usually found in one of these locations: 

  • For Apache: 
    /etc/php/[version]/apache2/php.ini 
  • For PHP-FPM (commonly used with NGINX): 
    /etc/php/[version]/fpm/php.ini 
  • For command-line PHP: 
    /etc/php/[version]/cli/php.ini 

Replace [version] with your PHP version (e.g., 8.1)

Step 2: Open and Edit the php.ini File 

Use a text editor like nano to open the file. For example, if you’re using PHP-FPM version 8.1: 

 
bash 
sudo nano /etc/php/8.1/fpm/php.ini 
 

Inside the file, you can search for specific settings by pressing CTRL + W and typing the setting name. 

Here are some common settings you might want to adjust: 

  • memory_limit — Controls how much RAM PHP scripts can use. 
    Example: 

text 
memory_limit = 256M 
 

  • upload_max_filesize — Maximum size of uploaded files. 
    Example: 

text 
upload_max_filesize = 64M 
 

  • post_max_size — Maximum size of POST data, including file uploads. 
    Example: 

text 
post_max_size = 64M 
 

  • max_execution_time — Maximum time a script is allowed to run (in seconds). 
    Example: 

text 
max_execution_time = 60 
 

  • display_errors — Show errors on the screen (useful during development). 
    Example: 

text 
display_errors = On 
 

Make the necessary changes by editing the values, then save (CTRL + O) and exit (CTRL + X). 

Step 3: Restart PHP and Your Web Server 

For your changes to take effect, restart PHP and your web server. 

  • If you use PHP-FPM with NGINX, run: 

bash 
sudo systemctl restart php8.1-fpm 
sudo systemctl reload nginx 
 

  • If you use Apache, run: 

bash 
sudo systemctl restart apache2 
 

Make sure to replace 8.1 with your actual PHP version. 

Step 4: Verify Your Changes 

To confirm your new PHP settings are active, create a simple PHP info file in your website’s root directory: 

php 
<?php phpinfo(); ?> 
 

Save this as info.php and access it in your browser at http://yourdomain.com/info.php. This page displays all current PHP configuration values, including those you just changed. 

Important: Delete this file after checking, as it exposes sensitive server information. 

Additional Tips 

  • Always back up your php.ini file before making changes. 
  • Only enable display_errors on development or staging servers to avoid exposing errors to visitors. 
  • If you’re unsure which php.ini file is active, the phpinfo() page shows the “Loaded Configuration File” path. 
  • For advanced setups, you might also want to check PHP-FPM pool configuration files for per-pool settings. 

Summary

Configuring PHP settings allows you to tailor your server environment to your website’s specific needs. By editing the php.ini file and restarting your services, you can improve performance, increase upload limits, and troubleshoot issues more effectively. 

For a detailed visual guide, watch the Contabo tutorial here: 

Helpful Resources: 

Fine-tuning your PHP environment is a straightforward way to keep your website running smoothly and efficiently. 

Scroll to Top