PHP文件由浏览器下载,而不是由Laravel项目处理

时间:2017-12-27 06:11:59

标签: php laravel .htaccess

当我尝试运行我的项目时,它下载一个包含以下代码的文件。我不知道这背后的原因是什么。请指导我这个问题

<?php

/**
 * Laravel - A PHP Framework For Web Artisans
 *

 * @package  Laravel
 * @author  
 Taylor Otwell <taylor@laravel.com>

*/

/*
|--------------------------------------------------------------------------
|
 Register The Auto Loader
|--------------------------------------------------------------------------
|
| 
Composer provides a convenient, automatically generated class loader for
| our application.
 We just need to utilize it! We'll simply require it
| into the script here so that we don't 
have to worry about manual
| loading any of our classes later on.
 It feels nice to relax.
|
*/

require __DIR__.'/../bootstrap/autoload.php';

/*
|--------------------------------------------------------------------------
| 
Turn On The Lights
|--------------------------------------------------------------------------
|
| 
We need to illuminate PHP development, so let us turn on the lights.
| This bootstraps the framework and g
ets it ready for use, then it
| will load up this application so that we can run it and send
| 
the responses back to the browser and delight
 our users.
|
*/

$app = require_once __DIR__.'/../bootstrap/app.php';

/*
|--------------------------------------------------------------------------
| 
Run The Application
|--------------------------------------------------------------------------
|
| 
Once we have the application, we can handle the incoming request
| through the kernel, and 
send the associated response back to
| the client's browser allowing them to enjoy the 
creative
| and wonderful application we have prepared 
for them.
|
*/

$kernel = $app->make(Illuminate\Contracts\Http\Kernel::class);

$response = $kernel->handle(

$request = Illuminate\Http\Request::capture()
);

$response->send();

$kernel->terminate($request, $response);

2 个答案:

答案 0 :(得分:3)

您的服务器配置未设置为将.php文件作为php脚本执行,而只是将内容显示为纯文本。检查服务器的配置。

答案 1 :(得分:0)

的Apache

您需要在dir.conf中添加index.php

cat  /etc/apache2/mods-enabled/dir.conf

设置

<IfModule mod_dir.c>
   DirectoryIndex index.html index.cgi index.pl index.php index.xhtml index.htm
</IfModule>

最后,重启apache

sudo service apache2 restart

参考:如何在Ubuntu 14.0或Ubuntu 16.0上设置php app https://www.digitalocean.com/community/tutorials/how-to-install-linux-apache-mysql-php-lamp-stack-on-ubuntu-14-04

https://www.digitalocean.com/community/tutorials/how-to-install-linux-apache-mysql-php-lamp-stack-on-ubuntu-16-04