If you have followed our previous guides, such as How to Install Apache and PHP on Ubuntu 22.04 Server, then you need to follow this guide for optimum performance of the web server. If you are running a WordPress website or web app with PHP, you may have faced performance problems. Fortunately, these tweaks can make your website fast running.
Which php.ini to Tweak?
Install the mlocate package, update the database and find the php.inifiles:
1 2 3 | sudo apt install mlocate sudo updatedb locate php.ini |
Example output:
---
1 2 3 4 5 6 7 8 9 10 11 12 | locate php.ini /etc/php/7.2/cgi/php.ini /etc/php/7.2/cli/php.ini /etc/php/7.2/fpm/php.ini /etc/php/8.3/apache2/php.ini /etc/php/8.3/cli/php.ini /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/8.3/php.ini-development /usr/lib/php/8.3/php.ini-production /usr/lib/php/8.3/php.ini-production.cli |
If you are using PHP 7.2, then in the above case edit at least /etc/php/7.2/cli/php.ini and /etc/php/7.2/fpm/php.ini. Reload PHP-FPM after editing with service php7.2-fpm reload command.

Essential php.ini Tweaks
These are all the required settings which you can change:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | memory_limit = 256M ... max_execution_time = 120 ... display_errors = Off ... upload_max_filesize = 64M post_max_size = 64M allow_url_fopen = Off ... realpath_cache_size = 16M realpath_cache_ttl = 120 ... session.save_handler = files session.save_path = /var/lib/php/sessions session.cache_limiter = public session.cache_expire = 180 |
The above parameters are not in one place, you have to find the settings, uncomment if commented out and change the settings. I have seen that these are optimum for stability and performance for a WordPress installation on a 16GB server. These settings probably do not work for multiple server setups.
Tagged With 10 Essential PHP ini Tweaks for Improved Web Performance