2015-10-15 56 views
2

我能夠從Github回購庫成功將我的Yii2應用程序部署到Heroku。然而,當我嘗試訪問Heroku提供的域名時(https://portfolio-php.herokuapp.com),我收到一條錯誤消息:「禁止您無權訪問/在此服務器上。」我的構建日誌在下面提供。有人可以提供任何指導嗎?在成功部署後無法在Heroku上查看Yii應用程序

-----> 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; 
+0

您使用基本或高級模板?你在你的htaccess文件有哪些?和配置文件?求你了,發佈更多信息。 –

+0

非常感謝你的快速回復。我正在使用基本模板,我不相信有一個.htaccess文件。配置文件如下: –

+0

只是添加了更多信息到原始文章,包括配置文件內容 –

回答

0

如果你的應用程序被稱爲基本,這個網址應該工作:

https://portfolio-php.herokuapp.com/基本 /網絡

如何獲得在域中工作的基本應用程序/

1)將所有文件從/ web目錄移到public_html或wh atever

2)將文件的其餘部分中上等水平,讓您得到類似的東西:

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

3)變更的index.php你移動到/的public_html並更改路徑配置文件,供應商等

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

+0

我會做你說的爲了讓它工作在域中,但同時我在嘗試訪問https://portfolio-php.herokuapp.com/basic/web時得到一個空白頁面。任何可能的原因是什麼? –

+0

檢查文件權限還啓用調試索引.php: 'defined('YII_DEBUG')或define('YII_DEBUG',true); error_reporting(-1); ini_set('display_errors',true);' –

+0

當我運行'chmod'時,文件權限看起來不錯,正如您在下面的屏幕截圖中看到的,調試已啓用。 http://prntscr.com/8rrfa6 –

0

謝謝你的幫忙。它現在有效。答案是如下:。

「您的應用程序文件夾basic在這本身應該是倉庫你,而不是把父文件夾的basic版本控制之下,這意味着所有的Yii是錯了,因爲你的路徑某些時候試着動composer.json一級。

當您按照Yii的說明手冊,你需要cd basic/創建項目後。

您還需要從去除開發/調試的東西網絡/索引的頂部。php:

// defined('YII_DEBUG') or define('YII_DEBUG', true); 
// defined('YII_ENV') or define('YII_ENV', 'dev'); 

並將fxp/composer-asset-plugin添加到您項目的composer.json。

然後一切工作得很好」

相關問題