Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP Fatal error: Unknown: Failed opening required | public duplicate in index.php link

My project use Zend 3 framework and php7.2. When I build web on Ubuntu 17.04, this web isn’t working.

> php -S 0.0.0.0:8080 -t public public/index.php
[Thu Dec  7 23:25:59 2017] PHP Warning:  Unknown: failed to open stream: No such file or directory in Unknown on line 0
[Thu Dec  7 23:25:59 2017] PHP Fatal error:  Unknown: Failed opening required '/home/isling/workspace/sp/shopping/public/public/index.php' (include_path='.:/usr/share/php') in Unknown on line 0

'.../public/public/index.php' -> public is duplicated ???

like image 250
Long Nguyễn Avatar asked Nov 07 '25 09:11

Long Nguyễn


2 Answers

The -t argument specifies the document root, it is assumed that's where the indicated file is. So you just need this:

php -S 0.0.0.0:8080 -t public index.php

I usually put this in my composer.json:

"scripts": {
    "serve": "php -S 0.0.0.0:8080 -t public/ index.php"
}

Then I can just do composer serve to get a development server.

[EDIT 2018-04-27] This behavior has changed around version 7.2.3 or so. The filename parameter now appears to be relative to the current directory and not relative to the doc root directory specfied via -t, so you'd now use something like: php -S 0.0.0.0:8080 -t public/ public/index.php

like image 128
Alex Howansky Avatar answered Nov 10 '25 01:11

Alex Howansky


This error is generally thrown when -t or public is missing from the command. @Alex correctly explains the reason behind it. first, navigate to your project directory and then enter this from the command line.

php -S localhost:<your port number> -t public

check this link on how to run php built-in web server from command line

like image 44
Arpit J. Avatar answered Nov 10 '25 01:11

Arpit J.