0

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!

  • Thanks for the edit. In order to help you, we need to know how you configured your php. It is likely a misconfiguration or something similar. Is your webserver running properly? Have you tried to reboot the system? Any permissions that got changed since the last time you used the environment? – LPChip Jul 5 at 9:23
  • Hello, try to fetch a .html file. 500 error and in this case too? – user726730 Jul 5 at 9:30
  • @LPChip My Webserver is running properly, every .HTML file is working, and what you mean with "configured your php file"? Rebooted the system have I done too, and no permissions was changed. I was in the middle of programming and everything worked perfectly fine, then I was wondering, because I had forgotten to add a HTML input in the forms, and I should have done the php part right too.. But since I tested the new input form every .php file - the ones too who I wasn't editing are now giving this error.. When I'm home I'll edit the both php files here, and say it here in the comments. – Traijan Jul 5 at 9:55
  • @user726730 yes .html files are working fine. – Traijan Jul 5 at 9:55
  • I edited the question! – Traijan Jul 5 at 13:10
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.

  • First: I really appreciate your help! The problem ist like I said, that all my .php files aren't working anymore, the one too who worked before and I don't modified. The test you gave me don't worked, I think because it's an .php file, but like I said I don't know the error. I'll edit fast the error log I found, and I hope you can help me with this, because I'm not really figuring something out of this log. – Traijan Jul 5 at 9:16
  • You said, you edited files. You were not that specific, so I assumed all the files you edited stopped working. Okay, if all files don't work anymore, this is a different issue. It is confirmed by the test. The error log does help though – LPChip Jul 5 at 9:22
  • Sorry ^^' I'll edit here later when I'm home the both php files which I edited and I except the whole problem came up with them. I'll say it here in the comments when they're edited here! – Traijan Jul 5 at 9:57
  • Sorry! I did not saw your edit! Yes, the Webserver is running .html files are like always. (Will be displayed) I rebooted the system too, but that does not helped.. I found out how to display the erros instead of the error 500 and edited in my question as "Edit 3" I hope you can help me! – Traijan Jul 5 at 15:40

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.