PHP require () giving error 500
I have a system recently developed 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 requiring classes, returning error 500 in the browser.
I run tail -f /var/log/apache2/error.log
and it 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 path, as well as relative, but none works.
Tests
When I run is_writable or is_readable it it also returns the error.
I created an index.php in root (/var/www/ html/) and included the index file.html inside the project and worked; so I discarded permissions, which are: folder (755) / files (644).
In the same index file.php checked whether the Router.class.php exists and it returns true. But if you do it in autoload it returns false.
I have always worked with Debian and this has never occurred problem.
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 answers
Error 500 is generic, i.e. no use looking specifically about it, you have to read the LOG error message. The error in
PHP Fatal error: require (): Failed opening required 'Src/Core/Router.class.php '
This means that the file does not exist, the possible reasons are:
Case-sensitive:
You are using a Linux or Mac OSX server, so:
The
./Src
Folder is actually in minuscule and should be./src
-
Or the file
Router.class.php
should berouter.class.php
in your autoload
On Windows systems you are case-insensitive, so it probably works, but if you do this on file name Foo.php
and require foo.php
on a Debian/Fedora/Mac/etc it won't work.
File name is wrong:
Can then be a typo, both in the file name and in the path (i.e. not in the folder), whether absolute or not.
The only way to be sure is if you inform if you inform the minimum as:
- is this (
Router.class.php
) a third-party framework installed via composer? - who created
Router.class.php
and added it manually? - have you configured as
composer.json
? (post it in the question)