Asked  7 Months ago    Answers:  5   Viewed   30 times

As a prelude, I know what a HTTP 500 is, and I know how to fix them.

On PHP 5.3, i'm running a production environment with show_errors off. When there are any fatal errors, the user gets a plain white 500 page in response. I'm trying to create a 500 error page just in case there any any errors; just so it is more user friendly.

I used to be able to do

ErrorDocument 500 500.html

It doesn't seem to be working anymore, however - even thought my 404

ErrorDocument 404 404.html

Works fine.

Curious to see solutions regarding this - Thank you for your time.

 Answers

66

Fatal errors don't produce 500 errors in and of themselves, they would return 200 with blank page typically (if no output had been flushed to browser at the point of the error) . Plus this will not help you anyway, as Apache would be no longer involved when PHP is having the error.

Maybe you could register a shutdown function to send 500 header (to get 500 result) and display the content you want to display.

Wednesday, March 31, 2021
 
fillobotto
answered 7 Months ago
85
# Turn On ReWrite Engine
RewriteEngine On

# Exclude url.php and index.php from redirecting
RewriteCond %{REQUEST_URI} !^/(index|url).php

# Redirect to url.php
RewriteRule . url.php [NC,L]
Wednesday, March 31, 2021
 
Skipper
answered 7 Months ago
73

Important:

Please change the version number to get more security if you have phpMyAdmin exposed to the public or need features from newer phpMyAdmin versions.

This was taken from a chat. Some things might be inaccurate, but this solved the OP's problem

Install PHPMyAdmin using the following tutorial:

1.

apt purge phpmyadmin -y
cd /path/to/somefolder
wget https://files.phpmyadmin.net/phpMyAdmin/5.1.0-rc1/phpMyAdmin-5.1.0-rc1-all-languages.zip && unzip phpMyAdmin-5.1.0-rc1-all-languages.zip && 
cd phpMyAdmin-5.1.0-rc1-all-languages
apt install pwgen -y
  1. Make note of the output of this command, I will refer to it as pw
pwgen -s 32 1
cp config.sample.inc.php config.inc.php
  1. Edit config.inc.php with favorite editor, and paste the pw in this line:
. . .
$cfg['blowfish_secret'] = 'STRINGOFTHIRTYTWORANDOMCHARACTERS'; /* YOU MUST FILL IN THIS FOR COOKIE AUTH! */
. . .
vim /etc/apache2/conf-available/phpmyadmin-custom.conf
  1. Paste the following to that previous command:
Alias /phpmyadmin /path/to/that/phpMyAdmin-5.1.0-rc1-all-languages
<Directory "/path/to/that/phpMyAdmin-5.1.0-rc1-all-languages">
Options SymLinksIfOwnerMatch
DirectoryIndex index.php
Require all granted
</Directory>
  1. Save the previous one using :wq, Run the following command
a2enconf phpmyadmin-custom && systemctl restart apache2 && mysql
  1. Replace your_password_here to your own password.
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'your_password_here';
systemctl restart mysql

It should work now.

Additional notes:

To only allow you to view phpMyAdmin, try:

<Directory "/path/to/that/phpMyAdmin-5.1.0-rc1-all-languages">
Options SymLinksIfOwnerMatch
DirectoryIndex index.php
Require local
# Or change it to
# Require ip 127.0.0.1
# change 127.0.0.1 to your personal computers ip address,
# not to the server ip
# if you want to access phpMyAdmin from a public server, but not allow others to access it
</Directory>
Friday, May 28, 2021
 
Gilko
answered 5 Months ago
34

I found where my problem was. For all those who encounter the very nasty error 500, check your logs. Occured to me that once I checked the logs, I found that the method checkhashSSHA() was never being used, and this was causing the following error:

PHP Fatal error:  Call to undefined function checkHashSSA() in /xxx/xxx/xxx/xxx/UserFunctions.php on line 54

Hence I added the following code to decrypt the password:

public function getUserByEmailAndPassword($email, $password) {

    $stmt = $this->conn->prepare("SELECT * FROM users WHERE UserEmail = ?");

    $stmt->bind_param("s", $email);

    if ($stmt->execute()) {
        $user = $stmt->get_result()->fetch_assoc();
        $salt = $user['salt'];
        $userPassword = $user['UserPassword'];
        $hash = $this->checkhashSSHA($salt, $password);

        if ($userPassword == $hash) {
            return $user;
        }
        $stmt->close();
    } else {
        return NULL;
    }
}

This solved my error.

Just for the record, logs for such errors are usually found in the following location: var/log/apache2/error.log You may need to make some change to the php.ini file to log these errors.

Hope this helps anyone with the 500 error ;)

Saturday, May 29, 2021
 
Camsoft
answered 5 Months ago
49

Please make a backup of your .htaccess file. Now remove all lines -- make it empty (there is too much noise there at the moment).

Add these lines to your empty .htaccess (should be in the root folder of your website):

RewriteEngine On
RewriteRule ^opslag/vis/(d+)$ /opslag/view.php?vis=$1 [NC,QSA,L] 

This should treat www.url.com/opslag/vis/11 as www.url.com/opslag/view.php?vis=11.

Please ensure that you have no more .htaccess files in opslag folder.

Saturday, July 31, 2021
 
Gabriele
answered 3 Months ago
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :