将 Symfony-CMF 项目部署到 Heroku



>我目前正在按照CMF文档创建一个项目:https://symfony.com/doc/master/cmf/tutorial/introduction.html

当我继续教程时,我喜欢将项目推送到 heroku。但是当我需要数据库连接时,我遇到了一个问题。

比我找到这个来源:https://coderwall.com/p/qpitzq/deploing-symfony-project-using-mysql-to-heroku

这很有帮助,但我还需要配置"phpcr_backend"参数。我在控制台上设置了它们:

heroku config:set phpcr_backend=[type:doctrinedbal,connection:default]
or
heroku config:set phpcr_backend=(type:doctrinedbal,connection:default)
or 
heroku config:set phpcr_backend={type:doctrinedbal,connection:default}
or
heroku config:set phpcr_backend=type:doctrinedbal,connection:default
heroku config:set phpcr_workspace=default
heroku config:set phpcr_user=admin
heroku config:set phpcr_pass=admin

并更新parameters_production.php文件:

<?php
$db = parse_url(getenv('...'));
...
$container->setParameter('phpcr_backend', getenv('phpcr_backend'));
$container->setParameter('phpcr_workspace', getenv('phpcr_workspace'));
$container->setParameter('phpcr_user', getenv('phpcr_user'));
$container->setParameter('phpcr_pass', getenv('phpcr_pass'));

现在,当我部署项目时,我收到此错误:

           [SymfonyComponentConfigDefinitionExceptionInvalidTypeException]                                        
       Invalid type for path "doctrine_phpcr.session.sessions.default.backend". Expected array, but got boolean    

不确定,我是否以正确的语法设置这些参数。目前,这就是问题所在。

编辑:

我在config.yml文件中硬编码了doctrine_phpcr参数:

doctrine_phpcr:
   # configure the PHPCR session
   session:
       backend: { type: doctrinedbal, connection: default}
       workspace: default
       username: admin
       password: admin
    # enable the ODM layer
   odm:
       auto_mapping: true
       auto_generate_proxy_classes: "%kernel.debug%"

当前错误是

PHP Fatal error:  Cannot use 'String' as class name as it is reserved in /tmp/build_4d5c173733f27d9fb1cec775f9522884/ersah123-cmf-testing-118c5df/vendor/doctrine/phpcr-odm/lib/Doctrine/ODM/PHPCR/Mapping/Annotations/String.php on line 32   

编辑 2:

通过在 composer.json 中更改 php 版本,修复了最后一个问题。现在,当我部署项目时,生成成功。但是有另一个问题:

 heroku run php bin/console doctrine:database:create

 [DoctrineDBALExceptionConnectionException]                                                                                   
  An exception occured in driver: SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: Name or service not known 

您的帮助将不胜感激

盒的分步说明。

首先,克隆:

git clone https://github.com/symfony-cmf/cmf-sandbox.git
cd cmf-sandbox
composer install

然后根据需要声明可选扩展:

php -dmemory_limit=4G $(which composer) require "ext-gd:*" "ext-exif:*"
git add composer.json composer.lock
git commit -m "require gd and exif extensions"

数据库设置

在 composer.json 中映射(JAWSDB_|CLEARDB_)?DATABASE_URL

diff --git a/composer.json b/composer.json
index 0d880da..07a3ba8 100644
--- a/composer.json
+++ b/composer.json
@@ -91,7 +91,9 @@
         "incenteev-parameters": [
             {
                 "file": "app/config/parameters.yml",
-                "env-map": {}
+                "env-map": {
+                    "database_url": "DATABASE_URL"
+                }
             },
             {
                 "file": "app/config/phpcr.yml",

使用database_url详细信息更新config.ymlconfig_prod.yml

diff --git a/app/config/config.yml b/app/config/config.yml
index 3075825..0685fda 100644
--- a/app/config/config.yml
+++ b/app/config/config.yml
@@ -55,13 +55,6 @@ swiftmailer:
 # for jackalope-doctrine-dbal
 doctrine:
     dbal:
-        driver:   '%database_driver%'
-        host:     '%database_host%'
-        port:     '%database_port%'
-        dbname:   '%database_name%'
-        user:     '%database_user%'
-        password: '%database_password%'
-        path:     '%database_path%'
         charset:  UTF8
 # cmf configuration
diff --git a/app/config/config_prod.yml b/app/config/config_prod.yml
index aa51fbf..b704da2 100644
--- a/app/config/config_prod.yml
+++ b/app/config/config_prod.yml
@@ -17,3 +17,7 @@ monolog:
             type:  stream
             path:  '%kernel.logs_dir%/%kernel.environment%.log'
             level: debug
+
+doctrine:
+    dbal:
+        url: '%database_url%'

。并更新和提交:

php -dmemory_limit=4G $(which composer) update --lock
git add composer.json composer.lock app/config/config.yml app/config/config_prod.yml
git commit -m "map DATABASE_URL"

伐木

使用日志记录详细信息更新config_prod.yml

diff --git a/app/config/config_prod.yml b/app/config/config_prod.yml
index b704da2..755cff9 100644
--- a/app/config/config_prod.yml
+++ b/app/config/config_prod.yml
@@ -15,7 +15,7 @@ monolog:
             handler:      nested
         nested:
             type:  stream
-            path:  '%kernel.logs_dir%/%kernel.environment%.log'
+            path:  'php://stderr'
             level: debug
 doctrine:

。并提交:

git add app/config/config_prod.yml
git commit -m "log to stderr in prod"

PHPCR 配置需要在存储库中:

cp app/config/phpcr_doctrine_dbal.yml.dist app/config/phpcr.yml
sed -i '' '/phpcr.yml/d' .gitignore
git add app/config/phpcr.yml
git commit -m "PHPCR config"

创建一个Procfile

echo 'web: $(composer config bin-dir)/heroku-php-apache2 web/' > Procfile
git add Procfile
git commit -m "Heroku Procfile"

部署

heroku create
heroku config:set SYMFONY_ENV=prod
heroku addons:create heroku-postgresql
git push heroku master

初始化数据库

heroku run "php app/console doctrine:phpcr:init:dbal --force"
heroku run "php app/console doctrine:phpcr:workspace:create default"
heroku run "php app/console doctrine:phpcr:repository:init"
heroku run "php app/console -v -n doctrine:phpcr:fixtures:load"

做!

heroku open

最新更新