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

问题描述 投票:0回答:2

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

<?php

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

 * @package  Laravel
 * @author  
 Taylor Otwell <[email protected]>

*/

/*
|--------------------------------------------------------------------------
|
 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);
php laravel .htaccess
2个回答
3
投票

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


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 https://www.digitalocean.com/community/tutorials/how-to-install-linux-apache-mysql-php-lamp-stack-on-ubuntu-14-04上设置php app

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

© www.soinside.com 2019 - 2024. All rights reserved.