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 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?