laravel PHP 警告:第 0 行的 Unknown 中没有这样的文件或目录

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/28893474/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 11:04:44  来源:igfitidea点击:

PHP Warning: No such file or directory in Unknown on line 0

phpapache.htaccesslaravel

提问by FlowCastv

I'm using hosting in linux and configured subdomain in my website in Apache2 server. I'm using laravel but I didn't use apache2 service by default. I'm using laravel artisan commands.

我在 linux 中使用托管并在我的网站中的 Apache2 服务器中配置子域。我正在使用 laravel,但默认情况下我没有使用 apache2 服务。我正在使用 laravel 工匠命令。

php artisan serve --host 0.0.0.0

php artisan serve --host 0.0.0.0

It will listen to port 8000. So in order to access my website, I'm used http://myipaddress:8000to access it.

它将侦听端口 8000。所以为了访问我的网站,我使用http://myipaddress:8000来访问它。

I tried to "chmod 755 or 777 public folder" but still didn't work. My .htaccess in laravel/public folder

我试图“chmod 755 或 777 公共文件夹”,但仍然没有工作。我在 laravel/public 文件夹中的 .htaccess

.htaccess

.htaccess

<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
    Options -MultiViews
</IfModule>

RewriteEngine On

# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ / [L,R=301]

# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]

When I access my website with port 8000, below is my errors:

当我使用端口 8000 访问我的网站时,以下是我的错误:

PHP Warning:  Unknown: failed to open stream: No such file or directory in Unknown on line 0

PHP Fatal error:  Unknown: Failed opening required 'server.php' (include_path='.:/usr/share/php:/usr/share/php/PEAR') in Unknown on line 0

回答by Hugo S. Mendes

I know this is an old question, but I was having the same problem and I found a solution by adding a server.phpfile to the root directoryof the project with the following content:

我知道这是一个老问题,但我遇到了同样的问题,我找到了一个解决方案,将server.php文件添加到项目的根目录中,内容如下:

<?php
$uri = urldecode(
    parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH)
);

// This file allows us to emulate Apache's "mod_rewrite" functionality from the
// built-in PHP web server. This provides a convenient way to test a Laravel
// application without having installed a "real" web server software here.
if ($uri !== '/' && file_exists(__DIR__.'/public'.$uri))
{
    return false;
}

require_once __DIR__.'/public/index.php';

回答by Sasa Blagojevic

I had the same issue, the real cause of the problem is this, somewhere along the line, the last parameter for the php -Sbuilt in server was changed to a flag, so you have to call it like this:

我遇到了同样的问题,问题的真正原因是,沿着这条线的某个地方,php -S内置服务器的最后一个参数被更改为一个标志,所以你必须像这样调用它:

php -S 127.0.0.1:8000 -t public -f serve.php

php -S 127.0.0.1:8000 -t public -f serve.php

Before php 7.0.26 you could omit the -f.

在 php 7.0.26 之前,您可以省略-f.

This is what happens under the hood when you call php artisan serve.

这就是当您调用php artisan serve.

If you want to serve it with php artisan serveyou will have to override the ServeCommandand add -fbefore the serve.phpont the last line of the fire()method, like this:

如果你想和它一起提供服务,php artisan serve你必须在方法的最后一行之前覆盖ServeCommand和添加,像这样:-fserve.phpfire()

passthru('"'.PHP_BINARY.'"'." -S {$host}:{$port} -t \"{$public}\" -f server.php");

passthru('"'.PHP_BINARY.'"'." -S {$host}:{$port} -t \"{$public}\" -f server.php");

For more details look at this stackoverflow post.

有关更多详细信息,请查看此stackoverflow 帖子