PHP limits how long a request can spend executing a script. Raising max_execution_time gives the affected PHP request more script time, provided another runtime or proxy limit does not end it first.
The limit is the max_execution_time setting, in seconds. It can be raised for a whole server or site in php.ini, for one directory in .htaccess or .user.ini, or for one script with ini_set() or set_time_limit().
Check the value through the website rather than the command line, because CLI PHP has no limit by default and can load a different php.ini file.
Steps to increase PHP maximum execution time:
Use php.ini on a server you manage, .htaccess or .user.ini when you can change only the site's own files, or a line of code when one script needs more time.
Change PHP maximum execution time limit in php.ini
The paths and service name below are for PHP 8.4 with PHP-FPM on Debian 13, and app.example.test stands for your own site.
A phpinfo() page shows server details to anyone who can reach it, so delete it as soon as the check is done.
- Open https://app.example.test/info.php in a browser and find the Server API and Loaded Configuration File rows.
With the Apache module, Server API shows Apache 2 Handler and the file is /etc/php/8.4/apache2/php.ini. Use that path in the next steps and reload apache2 instead of php8.4-fpm.
- Back up the php.ini file shown on that page.
$ sudo cp /etc/php/8.4/fpm/php.ini /etc/php/8.4/fpm/php.ini.bak
- Open the php.ini file in your text editor.
$ sudoedit /etc/php/8.4/fpm/php.ini
- Replace the max_execution_time value with the number of seconds the script needs.
max_execution_time = 300
A value such as 300 allows five minutes. Setting 0 removes the limit, so a stuck request can tie up a worker indefinitely.
max_input_time is a separate limit on reading uploaded and posted data before the script starts.
Related: How to increase the PHP file upload limit - Save the file and close the editor.
- Reload PHP-FPM to apply the new value.
$ sudo systemctl reload php8.4-fpm
- Refresh the info.php page and confirm the max_execution_time row shows the new value.
If the old value still shows, a PHP-FPM pool file in /etc/php/8.4/fpm/pool.d, a .user.ini file, or an Apache php_value line is overriding php.ini.
- Delete the info.php page.
$ sudo rm /var/www/app.example.test/public/info.php
- Retry the import, report, or export that failed and confirm it finishes without the Maximum execution time exceeded error.
If it still ends early with a timeout or gateway error, PHP-FPM's request_terminate_timeout or a web-server or proxy timeout is a separate limit that ended it first.
Change PHP maximum execution time limit in .htaccess or .user.ini
.htaccess works with the Apache module and .user.ini with PHP-FPM and other FastCGI setups, so check which one the site uses first. On cPanel hosting, set the limit in cPanel instead.
- Open the page in a browser and note the Server API row.

- Add this line to .htaccess in the application directory when Server API shows Apache 2 Handler.
- .htaccess
php_value max_execution_time 300
On FPM/FastCGI this line makes Apache return a 500 Internal Server Error, so use .user.ini there.
- Add this line to .user.ini in the application directory when Server API shows FPM/FastCGI.
- .user.ini
max_execution_time = 300
- Refresh the info.php page and confirm the first value in the max_execution_time row shows the new limit.
A .user.ini change can take up to five minutes to appear. The second value, Master Value, stays at the php.ini setting.
- Delete the info.php page.
- Retry the import, report, or export that failed and confirm it finishes without the Maximum execution time exceeded error.
If it still ends early with a timeout or gateway error, PHP-FPM's request_terminate_timeout or a web-server or proxy timeout is a separate limit that ended it first.
Change PHP maximum execution time limit in a PHP script
set_time_limit() raises the limit only for the request that runs the script, so the rest of the server keeps its setting.
- Add this line near the top of the script, before the slow work starts.
set_time_limit(300);
On WordPress, add the line to wp-config.php above the line that loads wp-settings.php.
In a long loop, call set_time_limit(30); inside the loop instead, because each call restarts the timer and gives each batch a fresh time window.
If the host disables set_time_limit(), use ini_set('max_execution_time', '300'); instead. A host that sets the limit with php_admin_value ignores both.
- Retry the import, report, or export that failed and confirm it finishes without the Maximum execution time exceeded error.
If it still ends early with a timeout or gateway error, PHP-FPM's request_terminate_timeout or a web-server or proxy timeout is a separate limit that ended it first.