PHP require() giving error 500

Asked

Viewed 768 times

1

I have a system developed recently in PHP7 on Windows, and, I decided to migrate to Debian9. At the moment everything works, but the autoload (psr-4) located in vendor is having problems when requesting the classes, returning error 500 in the browser.

I executed tail -f /var/log/apache2/error.log and he returns PHP Fatal error: require(): Failed opening required 'Src/Core/Router.class.php' (include_path='.:/usr/share/php') in /var/www/html/project/vendor/autoload.php on line 16.

I have tried to use absolute as well as relative path, but none works.

Testing

When executing is_writable or is_readable it also returns the error.

I created an index.php in root (/var/www/html/) and included the index.html file within the project and it worked; so I discarded permissions, which are: Folder (755) / files (644).

In the same file index.php I checked if Router.class.php exists and it returns true. But if you do in autoload returns false.

I have always worked with Debian and this problem had never occurred.

References

https://stackoverflow.com/questions/45569941/php-require-causing-http-500-error?rq=1

https://www.vivaolinux.com.br/topico/PHP/HTTP-500-INTERNAL-SERVER-ERROR-1

1 answer

0


Error 500 is generic, that is no use to search specifically about it, you have to read the error message of the LOG. The error in

PHP Fatal error: require(): Failed Opening required 'Src/Core/Router.class.php'

This means that the archive does not exist, the possible reasons are:

Case-sensitive:

You are using a Linux or Mac OSX server, so:

  • The briefcase ./Src is actually in minuscule and should be ./src

  • Or the file Router.class.php should be router.class.php in your autoload

On Windows systems you it is case-insensitive, so it probably works, but if you do this in the file name Foo.php and no require foo.php in a Debian/Fedora/Mac/etc will not work.

File name is wrong:

It can then be a typo, either in the file name or in the path (ie not in the folder), regardless of whether it is absolute or not.

The only way to be sure is if you inform if you inform the minimum as:

  • this (Router.class.php) is a third-party framework installed via Composer?
  • You who created the Router.class.php and added manually?
  • You have set up as the composer.json? (post him on the question)
  • I actually used "error 500" as a reference, it is easier if someone researches for the same problems; about case-senstive, in autoload I handle it.

  • @Tutoxtutorials Error 500 is Generico, it is an internal error of failure of the software of interpretation or dependency, I only explained this to specify better how to seek the problems, returning to the subject that matters, see the edition of the answer, try to give details to confirm, I think it’s something silly, a typo probably.

  • All classes were created by me, I do not use third party lib, because the project is not so big. I will update the question with more details.

  • @Tutoxtutorials like I said, without looking at Composer.json and the folder structure I have no way nor have idea what you did friend, after all only you have access to your Composer.json and folders, if you inform these important details then yes I will be able to help you.

  • I was able to solve it this way: when defining autoload, Poser was like Src/Core/ and when requesting it was using strtolower. In the end it was just a typo of the paths. Thanks.

  • @Tutoxtutorials how good it worked, case-sensitive we have to take care ;)

Show 1 more comment

Browser other questions tagged

You are not signed in. Login or sign up in order to post.