将laravel 5上的网站构建部署到VPS服务器时遇到问题,但在本地计算机上运行正常.
我的页面是http://easyway.vn/当前页面显示空白,有错误
无法加载资源:服务器响应状态为500(内部服务器错误)
我跑的时候
php artisan serve --host = 0.0.0.0
我有一个错误
[ErrorException]
chdir():没有这样的文件或目录(错误2)
服务器信息
操作系统:Linux 2.6
服务器版本:Apache/2.2.29(Unix)
PHP 5.4.41(cli)(内置:2015年6月4日13:27:02)版权所有(c)1997-2014 PHP Group Zend Engine v2.4.0,版权所有(c)1998-2014 Zend Technologies
请帮帮我!
Sin*_*dem 13
重命名公用文件夹名称会导致此问题.
触摸供应商目录下的文件是您可能永远不会做的事情.
这是我在我的活动项目中测试和使用的一种可行的替代方法.
创建app/Console/Commands/Serve.php文件并将内容设置为:
<?php
namespace App\Console\Commands;
use Exception;
use Illuminate\Console\Command;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Process\PhpExecutableFinder;
use Symfony\Component\Process\ProcessUtils;
class Serve extends Command {
/**
* The console command name.
*
* @var string
*/
protected $name = 'serve';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Serve the application on the PHP development server';
/**
* Execute the console command.
*
* @return void
*
* @throws \Exception
*/
public function fire() {
chdir('/');
$host = $this->input->getOption('host');
$port = $this->input->getOption('port');
$base = ProcessUtils::escapeArgument($this->laravel->basePath());
$binary = ProcessUtils::escapeArgument((new PhpExecutableFinder)->find(false));
$this->info("Laravel development server started on http://{$host}:{$port}/");
if (defined('HHVM_VERSION')) {
if (version_compare(HHVM_VERSION, '3.8.0') >= 0) {
passthru("{$binary} -m server -v Server.Type=proxygen -v Server.SourceRoot={$base}/ -v Server.IP={$host} -v Server.Port={$port} -v Server.DefaultDocument=server.php -v Server.ErrorDocument404=server.php");
} else {
throw new Exception("HHVM's built-in server requires HHVM >= 3.8.0.");
}
} else {
passthru("{$binary} -S {$host}:{$port} {$base}/server.php");
}
}
/**
* Get the console command options.
*
* @return array
*/
protected function getOptions() {
return [
['host', null, InputOption::VALUE_OPTIONAL, 'The host address to serve the application on.', 'localhost'],
['port', null, InputOption::VALUE_OPTIONAL, 'The port to serve the application on.', 8000],
];
}
}
Run Code Online (Sandbox Code Playgroud)
使用以下内容更新app/Console/Kernel.php文件:
<?php
namespace App\Console;
use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
class Kernel extends ConsoleKernel {
/**
* The Artisan commands provided by your application.
*
* @var array
*/
protected $commands = [
// Commands\Inspire::class,
Commands\Serve::class,
];
/**
* Define the application's command schedule.
*
* @param \Illuminate\Console\Scheduling\Schedule $schedule
* @return void
*/
protected function schedule(Schedule $schedule) {
// $schedule->command('inspire')
// ->hourly();
}
}
Run Code Online (Sandbox Code Playgroud)
就这样!
现在运行您的服务命令:
$ php artisan serve
Run Code Online (Sandbox Code Playgroud)
服务器启动:
Laravel development server started on http://localhost:8000/
Run Code Online (Sandbox Code Playgroud)
sam*_*ben 12
这意味着您的Laravel应用程序无法找到公用文件夹.
我通过改变让它发挥作用
chdir($this->laravel->publicPath());
Run Code Online (Sandbox Code Playgroud)
在vendor/laravel/framework/src/Illuminate/Foundation/Console/ServeCommand.php中:
chdir('/');
Run Code Online (Sandbox Code Playgroud)
我知道你很久以前就问过这个问题,但对于那些寻求最简单有效的方法来解决这个问题的人来说:
这个错误说明laravel找不到public文件夹,必须在Providers/AppServiceProvider.php的注册方法中添加这段代码:
public function register()
{
$this->app->bind('path.public', function() {
return base_path('PATH TO PUBLIC FOLDER');
});
}
Run Code Online (Sandbox Code Playgroud)
public_html 示例
在您的情况下,公共 HTML 的路径将是:
public function register()
{
$this->app->bind('path.public', function() {
return base_path('public_html');
});
}
Run Code Online (Sandbox Code Playgroud)
这样 Laravel 就知道去哪里寻找公共文件夹路径。
改变
chdir(public_path());
到
chdir('/');
来自:供应商/laravel/framework/src/Illuminate/Foundation/Console/ServeCommand.php
| 归档时间: |
|
| 查看次数: |
23685 次 |
| 最近记录: |