bitnami / vms

Bitnami VMs
https://bitnami.com
Other
200 stars 44 forks source link

[LAMP] Custom HTTP 500 Error Page #1536

Closed kotobakards closed 2 weeks ago

kotobakards commented 1 month ago

Platform

AWS

bndiagnostic ID know more about bndiagnostic ID

02399490-027a-7d25-a11d-c3d3b72745f1

bndiagnostic output

===== Begin of bndiagnostic tool output =====

? Resources: Found possible issues
  ? Connectivity: Found possible issues
  ? Mariadb: Found possible issues
  ✓ Processes: No issues found
  ? Apache: Found possible issues
  ✓ Php: No issues found

[Resources]

Your instance has little available RAM memory.
 total used free shared buff/cache available Mem: 975 402 66 15 505 416 Swap: 
634 156 477

You could try to increase your instance's memory. Please check your cloud 
provider's documentation for more information.

Press [Enter] to continue:
[Connectivity]

Server ports 22, 80 and/or 443 are not publicly accessible. Please check the 
following guide to open server ports for remote access:

https://docs.bitnami.com/general/faq/administration/use-firewall/

[Mariadb]

Found recent error messages in the MariaDB error log:
2024-05-17 20:58:05 1728338 [Warning] Aborted connection 1728338 to db: 'app' 
user: 'root' host: '**ip_address**' (Got an error reading communication packets)

Please check the following guide to troubleshoot MariaDB issues:

https://docs.bitnami.com/aws/apps/wordpress/troubleshooting/debug-errors-m
ariadb/

[Apache]

Found recent error or warning messages in the Apache error log.
Press [Enter] to continue:
[Sat May 18 20:05:42.466569 2024] [authz_core:error] [pid 3312273:tid 
140586560419584] [client **ip_address**:33256] AH01630: client denied by server 
configuration: /opt/bitnami/apache/cgi-bin
 [Sat May 18 21:28:42.934744 2024] [authz_core:error] [pid 3312273:tid 
140586459707136] [client **ip_address**:60258] AH01630: client denied by server 
configuration: /opt/bitnami/apache/cgi-bin
 [Sat May 18 23:28:24.384428 2024] [authz_core:error] [pid 3312273:tid 
140586493277952] [client **ip_address**:46598] AH01630: client denied by server 
configuration: /opt/bitnami/apache/cgi-bin

Please check the following guide to troubleshoot server issues:

https://docs.bitnami.com/general/apps/wordpress/troubleshooting/debug-erro
rs-apache/

===== End of bndiagnostic tool output =====

bndiagnostic was not useful. Could you please tell us why?

None of the output categories were related to my issue

Describe your issue as much as you can

I'd like to display a custom error page for HTTP 5XX errors. However, for now I would settle with just displaying a custom message (let alone trying to display an actual error page). I can get the custom error message to display for 4XX errors, but not for 5XX errors.

When I visit a page that I know doesn't exist on the server, the custom 404 message displays. image

However, when I visit a page where I intentionally put a bug in some PHP code, the custom 500 error message does not display. image image

Relevant portion of my /opt/bitnami/apache/conf/httpd.conf file:

<VirtualHost _default_:80>
  DocumentRoot "/opt/bitnami/apache/htdocs"
  <Directory "/opt/bitnami/apache/htdocs">
    Options Indexes FollowSymLinks
    AllowOverride All
    Require all granted
  </Directory>

  # Error Documents
  ErrorDocument 500 "The server made a boo boo. (bitnami.conf)"
  ErrorDocument 404 "We can't find the page (bitnami.conf)"
  ErrorDocument 503 /503.html
</VirtualHost>

Relevant portion of my /opt/bitnami/apache/conf/bitnami/bitnami.conf file:

<VirtualHost _default_:80>
  DocumentRoot "/opt/bitnami/apache/htdocs"
  <Directory "/opt/bitnami/apache/htdocs">
    Options Indexes FollowSymLinks
    AllowOverride All
    Require all granted
  </Directory>

  # Error Documents
  ErrorDocument 500 "The server made a boo boo. (bitnami.conf)"
  ErrorDocument 404 "We can't find the page (bitnami.conf)"
  ErrorDocument 503 /503.html
</VirtualHost>

Relevant portion of my /opt/bitnami/apache/conf/bitnami/bitnami-ssl.conf file:

<VirtualHost _default_:443>
  DocumentRoot "/opt/bitnami/apache/htdocs"
  SSLEngine on
  SSLCertificateFile "/opt/bitnami/apache/conf/bitnami/certs/server.crt"
  SSLCertificateKeyFile "/opt/bitnami/apache/conf/bitnami/certs/server.key"

  <Directory "/opt/bitnami/apache/htdocs">
    Options Indexes FollowSymLinks
    AllowOverride All
    Require all granted
  </Directory>

  # Error Documents
  ErrorDocument 500 "The server made a boo boo. (bitnami-ssl.conf)"
  ErrorDocument 404 "We can't find the page (bitnami-ssl.conf)"
  ErrorDocument 503 /503.html
</VirtualHost>
jotamartos commented 1 month ago

Hi @kotobakards,

You deployed a WordPress app on top of the LAMP solution and it's probably managing the errors by itself. You will need to take a look at the app's documentation to get more information about that.

Regarding the Apache's conf files to edit, the changes you made in the bitnami.conf and bitnami-ssl.conf files should be enough.

kotobakards commented 1 month ago

@jotamartos - I definitely didn't deploy a WordPress site, unless it came with the image? I do have other WordPress instances in my Lightsail account, but I spun up this LAMP stack instance specifically for testing the 5XX error messages.

I had started on a different LAMP instance that I had been using for a while. When I couldn't get the 500 error message to show on that instance, I created a new fresh instance in case it was in fact something that was already installed on the server that was interfering. The screenshots in my original comment are from that brand new instance.

Screenshot showing that I'm using a LAMP image through Lightsail instead of the WordPress one. image

Loom video demonstrating the issue. https://www.loom.com/share/3607dbd327744d9282bf4b611a864cd6

jotamartos commented 1 month ago

Hi @kotobakards,

Sorry, I thought it was a WordPress app when I accessed your domain. I just performed a quick test and deployed a sample "Hello world" website using PHP under apache/htdocs. I also edited the apache/conf/bitnami/bitnami.conf file (I didn't configure http->https redirections) and added the line to manage the 404 errors

...
  # Error Documents
  ErrorDocument 503 /503.html
  ErrorDocument 404 "Oops! We can't find that file. Sorry."
</VirtualHost>
Include "/opt/bitnami/apache/conf/bitnami/bitnami-ssl.conf"

The test succeeded

$ curl -LI localhost/index2.php
HTTP/1.1 404 Not Found
Date: Thu, 23 May 2024 07:37:32 GMT
Server: Apache
Content-Type: text/html; charset=iso-8859-1

Screenshot 2024-05-23 at 09 40 09

In your case, the app may be managing the errors and that's why you get the app's error message instead of the one you configured in Apache. You will need to review that.

kotobakards commented 1 month ago

@jotamartos - thanks for getting back to me! Please see the previously provided screenshots and Loom video.

On the test instance you deployed, can you get the 500 error message to show if you have a bug in your PHP code (such as a missing semicolon)?

jotamartos commented 1 month ago

On the test instance you deployed, can you get the 500 error message to show if you have a bug in your PHP code (such as a missing semicolon)?

I get the 500 error code but Apache doesn't show the custom error.

$ curl localhost/index.php
$ curl -LI localhost/index.php
HTTP/1.1 500 Internal Server Error
Date: Mon, 27 May 2024 08:17:46 GMT
Server: Apache
Connection: close
Content-Type: text/html; charset=UTF-8

I do not know why Apache is not managing the error the way we configured. I suggest you take a look at the documentation and the forums online to get more information about why Apache doesn't manage that the expected way.

github-actions[bot] commented 3 weeks ago

This Issue has been automatically marked as "stale" because it has not had recent activity (for 15 days). It will be closed if no further activity occurs. Thanks for the feedback.

github-actions[bot] commented 2 weeks ago

Due to the lack of activity in the last 5 days since it was marked as "stale", we proceed to close this Issue. Do not hesitate to reopen it later if necessary.