【问题标题】:Yii2 advanced index.php not working. In main domain, the code in index.php showsYii2 高级 index.php 不工作。在主域中,index.php 中的代码显示
【发布时间】:2021-03-27 06:08:07
【问题描述】:

它在我的 lohalhost 中运行良好,当我尝试放在服务器上时发生此错误。

在 index.php 中

<?php defined('YII_DEBUG') or define('YII_DEBUG', true); defined('YII_ENV') or define('YII_ENV', 'dev');

require(__DIR__ . '/_protected/vendor/autoload.php'); require(__DIR__ . '/_protected/vendor/yiisoft/yii2/Yii.php'); require(__DIR__ . '/_protected/common/config/bootstrap.php'); require(__DIR__ . '/_protected/frontend/config/bootstrap.php');

$config = yii\helpers\ArrayHelper::merge(
    require(__DIR__ . '/_protected/common/config/main.php'),
    require(__DIR__ . '/_protected/common/config/main-local.php'),
    require(__DIR__ . '/_protected/frontend/config/main.php'),
    require(__DIR__ . '/_protected/frontend/config/main-local.php') );

$application = new yii\web\Application($config); $application->run();

.htaccess

RewriteEngine on

# hide files and folders
RedirectMatch 404 /_protected
RedirectMatch 404 /\.git
RedirectMatch 404 /composer\.
RedirectMatch 404 /.bowerrc

# If a directory or a file exists, use the request directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Otherwise forward the request to index.php
RewriteRule . index.php

【问题讨论】:

  • 您使用的是 Apache 吗?你启用php了吗?运行 apache2ctl -M 并检查结果中是否有 php 行。
  • 这能回答你的问题吗? Apache shows PHP code instead of executing it
  • 什么错误?没有提供异常/错误字符串

标签: php ubuntu yii2 apache2 yii2-advanced-app


【解决方案1】:

如果你使用 apache 设置 DocumentRoot /var/www/frontend/web
并将 .htaccess 文件添加到 /var/www/frontend/web 的内容

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php

【讨论】:

  • 设置为 apache config* DocumentRoot /var/www/frontend/web
猜你喜欢
  • 2017-08-12
  • 1970-01-01
  • 1970-01-01
  • 2014-02-18
  • 2023-03-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多