i'm running a VPS with Linux CentOs 6 with 4 GB of RAM, 10 GB of HD and 2 virtual CPU Intel(R) Xeon(R)CPU L5640 @ 2.27GHz. As my host says each virtual CPU must be at least 0.5 physical cpu.

At certain times of the day, those with more traffic, trying accessing my php script i receive intermittently "500 internal server error".

I activate logging to debug level from apache, and also the PHP logging with E_ALL, but I can't find reference to Error 500 in any logs(I checked the right logs!).

I haven't got any .htaccess file in path script. The strange thing is that the error start at first php line in the script (the previous html displays correctly, but at the first php line the script send 500 error).

The cpu load is always good (max 0.15 0.08 0.01) and RAM is close to 95% but it arrived to swap just 2 times in a month with 2-5 MB.

Apache works with prefork with this values:

<IfModule prefork.c>
  StartServers       8
  MinSpareServers    5
  MaxSpareServers   20
  ServerLimit      280
  MaxClients       280
  MaxRequestsPerChild  4000

Everthing works correctly and I don't get any error in quiet times, but i start receive errors when traffic rises (6-9000 visits per hour).

Can i solve the problem increasing resources? (i can upgrade RAM up to 16 GB).

It can depend from reaching MaxClients (but apache must write it on log, right?)?

If I upgrade RAM to 6 or 8 GB i have to calculate MaxClients value with this?

MaxClients = Total RAM dedicated to the web server / Max child process size

Max child process size is around 20M.

How else can the problem be?

Thanks in advance

Here is the php.ini section about error logging

error_reporting = E_ALL | E_STRICT
display_errors = Off
display_startup_errors = Off
log_errors = On
log_errors_max_len = 1024
ignore_repeated_errors = Off
ignore_repeated_source = Off
report_memleaks = On
track_errors = Off
html_errors = Off
error_log = /var/log/php_errors.log

Everything that is not mentioned is commented.


The first port of call when you encounter 500 errors in PHP is to check the PHP error log; if a 500 error is not reported by apache then it is caused by PHP.

To check if you're hitting resource limits, enable and watch the apache server-status.

  • Thank you! But also in the php log there isn't any error! I set error_reporting = E_ALL | E_STRICT, but i have no errors in php log – Lucio Coire Galibone Aug 30 '12 at 8:29
  • Show the relevant php.ini parts pertaining to mod_php – adaptr Aug 30 '12 at 9:55
  • allow_call_time_pass_reference Off allow_url_fopen On allow_url_include Off error_reporting 32767 log_errors_max_len 1024 max_execution_time 60 max_file_uploads 20 max_input_nesting_level 64 max_input_time 60 max_input_vars 1000 memory_limit 128M output_buffering 4096 post_max_size 8M precision 14 you referring to this? – Lucio Coire Galibone Aug 30 '12 at 10:14
  • That says nothing about logging. Please add the sections pertaining to logging from the php.ini used by mod_php to your original post – adaptr Aug 30 '12 at 10:18
  • A 500 error can also be caused by an error in a .htaccess file. It's not necessarily PHP. – Gerald Schneider Dec 10 '15 at 14:49

This is the cause of the problem:

Max Requests Per Child: 4000

Change MaxRequestsPerChild to a lesser value, try 70 to start with, and all the intermittent 500 internal server error will disappear.

  • That's hardly the ''cause'', as the manual at httpd.apache.org/docs/2.2/mod/… nicely explains - setting it ''limits the amount of memory that process can consume by (accidental) memory leakage.'' – Josip Rodin Dec 10 '15 at 16:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.