douhe3313 2017-01-24 10:42
浏览 119
已采纳

如何在CLI中配置PHP以添加pdo模块

Currently I'm working on deploying a php (symfony)/MySQL application on cloud foundry. After deployment, when I connect in SSHto launch commands doctrines for the creation of the schema of the database I have this problem

    vcap@5nkjb8jdl87:~/app$ ./php/bin/php app/console doctrine:schema:create --env=prod
   

 Fatal error: Class 'PDO' not found in /home/vcap/app/vendor/doctrine/dbal/lib/Doctrine/DBAL/DriverManager.php on line 172
    [Symfony\Component\Debug\Exception\ClassNotFoundException] Attempted to load class "PDO" from the global namespace.Did you forget a "use" statement?
    doctrine:schema:create [--dump-sql] [--em [EM]] [-h|--help] [-q|--quiet] [-v|vv|vvv|--verbose] [-V|--version] [--ansi] [--no-ansi] [-n|--no-interactio
    -shell] [--process-isolation] [-e|--env ENV] [--no-debug] [--] <command>
  

  vcap@5nkjb8jdl87:~/app$ ./php/bin/php -m
    [PHP Modules]
    bcmath
    calendar
    Core
    ctype
    date
    dom
    ereg
    filter
    hash
    iconv
    intl
    json
    libxml
    mhash
    mysqlnd
    pcre
    Phar
    posix
    Reflection
    session
    SimpleXML
    SPL
    sqlite3
    standard
    tokenizer
    xml
    xmlreader
    xmlwriter
    
    [Zend Modules]
    
    vcap@5nkjb8jdl87:~/app$

How to activate the php PDO module in ClI ? Thank you for your help cdt

</div>
  • 写回答

2条回答 默认 最新

  • dsbtwy1329 2017-01-24 20:33
    关注

    When you SSH into an application using cf ssh the system unfortunately does not automatically configure the environment for you. This causes things like PHP to function in different ways (often by failing) because environment variables that affect how PHP functions and where it looks for configuration are not set.

    What you need to do to make things the same as when your application runs is to source the environment configuration first. The process for doing this is documented here.

    However before doing that please keep in mind that executing the .profile.d and .profile scripts can have side-effects. This is because both of these can be extended by your application. This is typically done as a way to run commands prior to your application starting. Make sure that these scripts are safe to run prior to executing the following commands! If parts are not safe, then do not run them. Just execute the commands that are safe.

    For reference here, the process boils down to running these commands:

    export HOME=/home/vcap/app
    export TMPDIR=/home/vcap/tmp
    cd /home/vcap/app
    source /home/vcap/app/.profile.d/*.sh
    source /home/vcap/app/.profile
    

    This sources the .profile.d & .profile scripts which initialize the environment.

    UPDATE:

    A slightly easier way to do this is to run cf ssh myapp -t -c "/tmp/lifecycle/launcher /home/vcap/app bash ''". This will open a bash shell and it lets the lifecycle launcher handle sourcing & setting up the environment.

    Hope that helps!

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 wpf界面一直接收PLC给过来的信号,导致UI界面操作起来会卡顿
  • ¥15 init i2c:2 freq:100000[MAIXPY]: find ov2640[MAIXPY]: find ov sensor是main文件哪里有问题吗
  • ¥15 运动想象脑电信号数据集.vhdr
  • ¥15 三因素重复测量数据R语句编写,不存在交互作用
  • ¥15 微信会员卡等级和折扣规则
  • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒