成功部署后无法在Heroku上查看Yii应用程序

时间:2015-10-15 15:00:35

标签: heroku deployment yii2

我能够从我的Github回购中成功部署我的Yii2应用程序到Heroku。但是,当我尝试访问Heroku(https://portfolio-php.herokuapp.com)提供的域时,我收到错误消息“禁止您无权访问此服务器上的/。”我的构建日志如下所示。有人可以提供任何指导吗?

-----> PHP app detected
-----> Resolved 'composer.lock' requirement for PHP to version 5.6.14.
-----> Installing system packages...
   - PHP 5.6.14
   - Apache 2.4.17
   - Nginx 1.8.0
-----> Installing PHP extensions...
   - mbstring (composer.lock; bundled)
   - zend-opcache (automatic; bundled)
-----> Installing dependencies...
   NOTICE: Using '/composer.phar' to install dependencies.
   Composer version 1.0-dev (9e67bc761be98b45875855003eb8b2f23f4bf5a5) 2015-09-18 14:32:06
   Loading composer repositories with package information
   Installing dependencies from lock file
     - Installing yiisoft/yii2-composer (2.0.3)
       Loading from cache

     - Installing bower-asset/jquery (2.1.4)
       Loading from cache

     - Installing bower-asset/jquery.inputmask (3.1.63)
       Loading from cache

     - Installing bower-asset/punycode (v1.3.2)
       Loading from cache

     - Installing bower-asset/yii2-pjax (v2.0.4)
       Loading from cache

     - Installing cebe/markdown (1.1.0)
       Loading from cache

     - Installing ezyang/htmlpurifier (v4.6.0)
       Loading from cache

     - Installing yiisoft/yii2 (2.0.6)
       Loading from cache

     - Installing bower-asset/bootstrap (v3.3.5)
       Loading from cache

     - Installing yiisoft/yii2-bootstrap (2.0.4)
       Loading from cache

     - Installing swiftmailer/swiftmailer (v5.4.1)
       Loading from cache

     - Installing yiisoft/yii2-swiftmailer (2.0.4)
       Loading from cache

   Generating optimized autoload files
-----> Preparing runtime environment...
       NOTICE: No Procfile, using 'web: vendor/bin/heroku-php-apache2'.
-----> Discovering process types
       Procfile declares types -> web

-----> Compressing... done, 80.9MB
-----> Launching... done, v12
       https://portfolio-php.herokuapp.com/ deployed to Heroku

我使用的是基本的Yii2模板。没有htaccess文件,配置文件显示为:

<?php

$params = require(__DIR__ . '/params.php');

$config = [
    'id' => 'basic',
    'basePath' => dirname(__DIR__),
    'bootstrap' => ['log'],
    'components' => [
        'request' => [
            // !!! insert a secret key in the following (if it is empty) - this is required by cookie validation
            'cookieValidationKey' => 'gfWIx3XdsOCYeUve6VVm1KF4VayT0z7t',
        ],
        'cache' => [
            'class' => 'yii\caching\FileCache',
        ],
        'user' => [
            'identityClass' => 'app\models\User',
            'enableAutoLogin' => true,
        ],
        'errorHandler' => [
            'errorAction' => 'site/error',
        ],
        'mailer' => [
            'class' => 'yii\swiftmailer\Mailer',
            // send all mails to a file by default. You have to set
            // 'useFileTransport' to false and configure a transport
            // for the mailer to send real emails.
            'useFileTransport' => true,
        ],
        'log' => [
            'traceLevel' => YII_DEBUG ? 3 : 0,
            'targets' => [
                [
                    'class' => 'yii\log\FileTarget',
                    'levels' => ['error', 'warning'],
                ],
            ],
        ],
        'db' => require(__DIR__ . '/db.php'),
    ],
    'params' => $params,
];

if (YII_ENV_DEV) {
    // configuration adjustments for 'dev' environment
    $config['bootstrap'][] = 'debug';
    $config['modules']['debug'] = [
        'class' => 'yii\debug\Module',
    ];

    $config['bootstrap'][] = 'gii';
    $config['modules']['gii'] = [
        'class' => 'yii\gii\Module',
    ];
}

return $config;

2 个答案:

答案 0 :(得分:0)

如果您的应用名为 basic ,则此网址应该有效:

https://portfolio-php.herokuapp.com/ 基本 /网络

如何让基本应用在域中工作/

1)将所有文件从/ web目录移动到public_html或其他任何

2)将其余文件放在上层,这样就可以得到类似的东西:

[...]
commands
config
controllers
models
web (empty)
...
public_html
 - assets
 - index.php
 - css
 - [...]

3)更改您已移至/ public_html的index.php并更改配置文件,供应商等的路径。

4)使用以下命令在此目录中创建.htaccess:

Options +FollowSymLinks -Indexes
IndexIgnore */*

RewriteEngine on

# if a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

# otherwise forward it to index.php

====

<强>更新

检查https://portfolio-php.herokuapp.com/basic/requirements.php是否有效,如果没有,则应重新安装所有作曲家依赖项:

  • 备份您的供应商文件夹和composer.lock

  • 删除供应商文件夹

  • 中的所有文件
  • 执行composer install --prefer-dist

答案 1 :(得分:0)

感谢您的帮助。它现在有效。答案如下:

&#34;您的应用程序位于basic文件夹中。那本身应该是存储库。您改为将basic的父文件夹置于版本控制之下,这意味着Yii中的所有路径都是错误的,因为您在某个时候尝试将composer.json向上移动一级。

当您按照Yii手册中的说明操作时,您需要在创建项目后cd basic/

您还需要从web / index.php:

的顶部删除开发/调试内容
// defined('YII_DEBUG') or define('YII_DEBUG', true);
// defined('YII_ENV') or define('YII_ENV', 'dev');

并将fxp/composer-asset-plugin添加到您项目的composer.json。

然后一切正常&#34;