【问题标题】:Symfony's app_dev.php shows "half" source codeSymfony app_dev.php 显示“一半”源代码
【发布时间】:2016-11-16 08:51:57
【问题描述】:

我用作曲家下载了它。尝试使用 PHPStorm 的内置服务器运行,但它不加载工具栏 (404)。

然后我尝试用 Apache 运行它,我将我的项目复制到/var/www/html,然后我在浏览器中转到http://localhost/symfony_app/web/app_dev.php

奇怪的是它部分显示了源代码(但没有换行):

loadClassCache(); $request = Request::createFromGlobals(); $response = $kernel->handle($request); $response->send(); $kernel->terminate($request, $response); 

这个文件(完整)有以下源代码:

<?php

use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Debug\Debug;

// If you don't want to setup permissions the proper way, just uncomment the following PHP line
// read http://symfony.com/doc/current/book/installation.html#checking-symfony-application-configuration-and-setup
// for more information
//umask(0000);

// This check prevents access to debug front controllers that are deployed by accident to production servers.
// Feel free to remove this, extend it, or make something more sophisticated.
if (isset($_SERVER['HTTP_CLIENT_IP'])
    || isset($_SERVER['HTTP_X_FORWARDED_FOR'])
    || !(in_array(@$_SERVER['REMOTE_ADDR'], ['127.0.0.1', 'fe80::1', '::1']) || php_sapi_name() === 'cli-server')
) {
    header('HTTP/1.0 403 Forbidden');
    exit('You are not allowed to access this file. Check '.basename(__FILE__).' for more information.');
}

/**
 * @var Composer\Autoload\ClassLoader $loader
 */
$loader = require __DIR__.'/../app/autoload.php';
Debug::enable();

$kernel = new AppKernel('dev', true);
$kernel->loadClassCache();
$request = Request::createFromGlobals();
$response = $kernel->handle($request);
$response->send();
$kernel->terminate($request, $response);

在 Apache 错误日志中什么都没有,只是重新启动。

该应用程序在 Symfony 的内置服务器上运行良好,在端口 8000

【问题讨论】:

  • 当您尝试访问 apache 下的页面时,究竟显示了什么?
  • 好像您没有在 Apache 中安装或配置 PHP 模块。
  • @cilefen 但我不会看到所有代码而是从loadClassCache() 看到的(甚至没有$kernel->loadClassCache())
  • @mmmm 一个没有格式的白页,就是我描述的那个

标签: php symfony apache2.4


【解决方案1】:

同样的事情发生在我做的一个新的 vagrant 设置上。我见过的最奇怪的事情。原来我已经安装了 php5,但没有完全安装。我需要在 Ubuntu 中专门安装 libapache2-mod-php5 包。在 Ubuntu 中运行它为我安装了它:

sudo apt-get install php5

我不知道你在什么系统上运行,但它可能是一个缺少这样的 php 包,这就是罪魁祸首。

【讨论】:

    【解决方案2】:

    如果您安装了 apache2 和 php 并启用此问题

    mod_rewrite
    

    你可以这样做:

    a2enmod rewrite
    

    在您的终端中并重新启动 apache

    【讨论】:

      猜你喜欢
      • 2016-07-29
      • 2013-06-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-11-04
      • 2016-08-26
      相关资源
      最近更新 更多