我在linux中使用主机,并在Apache2服务器中配置了我的网站子域。我使用的是laravel,但默认情况下我没有使用apache2服务。我使用的是laravel artisan命令。
php artisan serve--主机0.0.0.0
它将监听8000端口。所以为了访问我的网站,我习惯了http://myipaddress:8000以访问它。
我尝试"chmod 755或777公用文件夹",但仍然没有成功。laravel/公用文件夹中的My.htaccess
.htaccess
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
当我使用端口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
我知道这是一个老问题,但我遇到了同样的问题,我通过向项目的根目录添加一个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';
我也遇到了同样的问题,问题的真正原因是,在这个过程中,php -S
内置服务器的最后一个参数被更改为标志,所以你必须这样调用它:
php -S 127.0.0.1:8000 -t public -f serve.php
在php 7.0.26之前,您可以省略-f
。
这就是当您调用php artisan serve
时在引擎盖下发生的情况。
如果你想用php artisan serve
提供它,你必须覆盖ServeCommand
,并在fire()
方法的最后一行的serve.php
之前添加-f
,如下所示:
passthru('"'.PHP_BINARY.'"'." -S {$host}:{$port} -t '"{$public}'" -f server.php");
有关更多详细信息,请查看这篇stackoverflow帖子。