1

First of all, sorry for my bad english!

Hello, I'm learning web development all alone, and so I don't really know everything.

My problem is that after I used a edited (I don't think that this had a error) form to download and edit files. After that ALL of my .php files (that works before this perfectly fine) are now giving the http 500 error and I don't know what's the problem is.

I don't have a .htaccess.

I know that I don't send any information, but I don't know what information is relevant for this case and not, so I hope you all can say which information I should send you.

I'll then edit this post, and send it in the comments.

Thanks for any helps from you all!

Edit 1:

I found some php error logs, but I don't understand it exaclty:

And I found something really weird..

File(/var/www/html/index.php) is not within the allowed path(s): (1) in Unknown on line 0

It says that to all my .php files, but I don't know why, because the only thing I've done was to use on of my form inputs to test something, and then this error came up...

Edit 2:

I modified two .php files before the error appeared.

This one:

<?php
    $levelID = $_POST["levelid"];
    $description = $_POST["description"];
    $levelCreator = $_POST["creator"];

    shuffle($array);

    $arrayLength = count($array) - 1;

    $folder_name = $levelID;
    $rand = 3;


    $directoryFile = "/var/www/html/ng/mm/levels/" . $folder_name . "/";
    $directoryCache = "/var/www/html/ng/mm/cache/";
    $file = $directoryCache . basename($_FILES["FileToUpload"]["name"]);

    $allowed =  array('image/jpeg','image/png' ,'image/gif', 'image/x-icon', 'image/bmp');

    $counter = 0;

    for($i = 0; $i <= sizeof($allowed) - 1; $i++){
        if($_FILES["FileToUpload"]["type"] == $allowed[$i]){
            if(move_uploaded_file($_FILES["FileToUpload"]["tmp_name"], $file)){
                if(!mkdir($directoryFile, 0700, true)){
                    echo "<h2>Das erstellen des Ordners schlug fehl!</h2>";
                }
                else{
                    echo "<h2>Level erfolgreich hochgeladen!</h2>";

                    $levelidfFile = fopen($directoryFile . "levelID.txt", "w");
                    fwrite($levelidfFile, $levelID);
                    fclose($levelidfFile);
                    $descriptionFile = fopen($directoryFile . "description.txt", "w");
                    fwrite($descriptionFile, $description);
                    fclose($descriptionFile);
                    $creatorFile = fopen($directoryFile . "creator.txt", "w");
                    fwrite($creatorFile, $levelCreator);
                    fclose($creatorFile);

                    rename($directoryCache . $_FILES["FileToUpload"]["name"], $directoryFile . "thumbnail.png");
                    echo "Level ID: " . $levelID . " Beschreibung " . $description . " DateiName: " . $_FILES["FileToUpload"]["name"];
                    break;
                }
            }
            else{
                echo "<h2>Du hast kein Level-Thumbnail hochgeladen!</h2>";
            }       
        }
        else{
            $counter++;
            if($counter == sizeof($allowed) - 1){
                echo "<h2>Lade ein Bild/GIF hoch, keine andere Dateien!";
            }
        }
    }
?>

I added in this code

$creatorFile = fopen($directoryFile . "creator.txt", "w");
                    fwrite($creatorFile, $levelCreator);
                    fclose($creatorFile);

and:

<body>
<form method="post" action="mm.php" enctype="multipart/form-data">
    <input type="file" name="FileToUpload"> <br>
    <input type="text" name="creator" placeholder="Level-Creator.."> **ADDED** <br>
    <input type="text" name="levelid" placeholder="Level-ID.."> <br>
    <input type="text" name="description" placeholder="Beschreibung.."> <br>
    <input type="submit" value="Verschicken">
</form>
</body>

Moreover here is a pastebin link with my php error log: https://pastebin.com/f96LyNrZ

I really appreciate any help!

Edit 3:

I've found out how to make the error directly display on my site, and this is the result:

Warning: Unknown: open_basedir restriction in effect. File(/var/www/html/ng/mm/index.php) is not within the allowed path(s): (1) in Unknown on line 0

Warning: Unknown: failed to open stream: Operation not permitted in Unknown on line 0

Fatal error: Unknown: Failed opening required '/var/www/html/ng/mm/index.php' (include_path='.:/usr/share/php') in Unknown on line 0

In my php.ini open_basedir is on:

open_basedir = On

Edit 4:

I tested my script on my Raspberry Pi B+ and it works perfectly fine, so this script wasn't the problem why my whole php gives now this problem..

So I looked at my php.ini and then I saw that open_basedir should be commented, but I and really IDIOT doesn't knowed that I should restart apache2 that my server will use the new save...

Thanks to anyone who was helping me!

Traijan
  • 11

1 Answers1

1

The webserver gives a 500 Internal Server Error when it can't process the file because of a severe error.

Depending on how the server is configured, it can throw in an error if you have a simple typo to avoid showing errors on screen. In this case, the errors are usually logged somewhere.

It is also possible the interpreter can't understand the file. This can happen if you open the file with a text editor and save it in a different layout, eg. UTF-8 BOM vs plain text, Unix vs windows, etc.

You will want to create a new textfile with just a simple:

<?php
      echo 'Hello World';
?>

to rule out any php config errors and to test that you have the right layout. If that does work, copy the script that is no longer working to that file and save. If its not working, then you have a typo in your script. You will want to enable errors somehow to see what the error is.

EDIT: You gave the error now, which was not present before. It is actually apache (or whatever the webserver is running) that throws in the 500 Internal Server Error. It can be due to how php is configured, but it can also happen because php is not running at all.

You will want to verify your installation and configuration. Is the webserver actually running? Does it display html files? That sort of thing. A reboot could actually work too, you may want to try that.

LPChip
  • 66,193