Apache crashes when PHP is down

I was wondering if anyone knows of a method for configuring apache to return to a static HTML page, should it (Apache) determine that PHP is dead? This would provide the developer with an elegant solution for displaying the error page, and not (the worst case scenario) the source code of the PHP page that was to be executed.

Thanks.

+4
source share
4 answers

PHP source code is only displayed when apache is not properly configured to handle php files. That is, when the correct handler is not defined.

In case of errors, what is shown can be set to php.ini, basically the display_errors variable. This should be disabled and log_errors enabled in the production environment.

If php does die, apache will return the appropriate HTTP status code (usually 500) with the page specified by the ErrorDocument directive. If he is not dead, but stuck in a loop, you cannot do as far as I know.

You can specify a different page for different error codes.

+8
source

I would suggest that this usually results in a 500 error, and you can configure the apaches 500 handler to display a static page:

ErrorDocument 500 / 500error.html

You can also read about error handlers on the apaches documentation site.

+3
source

The real problem is that fatal PHP errors do not cause Apache to return 500 code. Errors except E_FATAL and E_PARSE can be handled, however you like to use set_error_handler() .

+1
source

There are two ways to use PHP and apache. 1. Install PHP as an Apache module: thus, php execution is a thread inside the apache process. therefore, if php execution fails, the apache process will fail. no alternative strategy. 2. Install PHP as a CGI script handler: this way apache will start a new PHP process for each request. I am doing PHP execution, apache knows this, and there may be a way to handle the error. no matter how you install PHP, when PHP is not executing, you can handle erros in the php.ini file.

0
source

Source: https://habr.com/ru/post/1276683/


All Articles