【问题标题】:PHP files are downloaded by browser instead of processed by Laravel projectPHP 文件由浏览器下载而不是由 Laravel 项目处理
【发布时间】:2018-06-07 19:19:29
【问题描述】:

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

<?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);

【问题讨论】:

  • 我认为缺少一些扩展laravel.com/docs/5.5/installation
  • 我认为您的系统中缺少 php env,您是否安装了 php?
  • 尊敬的先生,我的许多 Laravel 项目已经在我的系统上运行。我下载了我的项目并尝试在我的本地主机和新的托管服务器上运行它,所以当我点击 URL 时它下载了一个文件。使用以下我最常用的代码
  • 我的项目中有 env 文件
  • 项目的url输入错误会报错吗?

标签: php laravel .htaccess


【解决方案1】:

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

【讨论】:

  • 兄弟,我的许多 Laravel 项目已经在我的系统上运行。我下载了我的项目并尝试在我的本地主机和新的托管服务器上运行它,所以当我点击 URL 时它下载了一个文件..
【解决方案2】:

阿帕奇

需要在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 应用程序 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

【讨论】:

    猜你喜欢
    • 2011-01-19
    • 2015-01-02
    • 2020-06-28
    • 2013-09-23
    • 1970-01-01
    • 2021-01-03
    • 1970-01-01
    • 2021-11-07
    • 1970-01-01
    相关资源
    最近更新 更多