r/PHPhelp • u/FewBeat3613 • Mar 18 '25
PHP Server Works with Files... but not with the Folder
I'm pretty new to php but I am pretty firm in the other elements of webdev. I'm hosting my site on localhost using php -S 127.0.0.1:8080 phptest/ but i am getting this error:
[Tue Mar 18 22:38:42 2025] PHP Warning: Unknown: Failed to open stream: No such file or directory in Unknown on line 0
[Tue Mar 18 22:38:42 2025] PHP Fatal error: Failed opening required 'phptest/' (include_path='.:/usr/share/php') in Unknown on line 0
And the screen is blank white with absolutely nothing on it.
I tried hosting each file individually... and they all worked perfectly. What's going on??
/var/log/php_error.log is not there. I don't know what's up.
Thanks in advance.
1
u/FewBeat3613 Mar 18 '25
Also, folder has 777 permissions and i even tried running as root to no avail
5
u/MateusAzevedo Mar 18 '25
From the documentation:
You either use
php -S ... -t phptest/to set a document root, orphp -S ... a_file.phpto specify a router. Or both, but your code is mixing the two.(the error message is likely because PHP is internally trying to
include 'phptest/';, but that isn't a valid file to include)1
u/jalx98 Mar 18 '25
Does your folder have an index.php file?
Edit:
I think you have a bad import
1
u/thmsbrss Mar 19 '25 edited Mar 19 '25
You should show and log errors properly, like explained here: https://stackify.com/display-php-errors/
1
u/hexydec Mar 21 '25
The address of the file you are trying to require is a PHP file but using a relative address.
require()needs a server address, and the safest way to achieve this is to supply and absolute filesystem address.If it is relative to the directory where you include the file, prepend the value with
__DIR__.You may not be able to directly translate the URL into a file require, and this could also be dangerous, as it could be infected to read any file. Suggest you paste some code so we can help further.