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

如何在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>

图片转代码服务由CSDN问答提供 功能建议

目前我正在云代工厂部署php(symfony)/ MySQL应用程序。 部署之后,当我在SSH中连接以启动命令doctrines以创建数据库的模式时,我遇到了这个问题

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

 致命错误:在第172行的/home/vcap/app/vendor/doctrine/dbal/lib/Doctrine/DBAL/DriverManager.php中找不到类'PDO'
 
 [  Symfony \ Component \ Debug \ Exception \ ClassNotFoundException]尝试从全局命名空间加载类“PDO”。你忘了“使用”语句吗?
 
 doctrine:schema:create [--dump-sq  l] [--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] [ -  ]&lt; command&gt; 
 
   
 
  
 
  
 
 
 
 

  vcap @ 5nkjb8jdl87:〜/ app $。/ php / bin / php -m 
 
 [PHP Modules] 
 
  
 \ bcmath 
 
 calendar 
 
核心
 
ctype 
 
日期
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 \过滤
 
 
 
 
 \对
 
 
 iconv 
 
  
 intl 
 
 json 
 
 \ tlibxml 
 
 
 
 
 
 
 \ m 
 
 
 
 
 
 
 
 
 
 
 
ep 
 
 
 
 \ p \ p \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \  
 SimpleXML 
 
 SPL 
 
 \ sqlite3 
 
标准
 
 tokenizer 
 
 xml 
 
 \ xmlreader 
 
 xmlwriter 
 
 
 
 [Zend Modules]  
 
 
 
 vcap @ 5nkjb8jdl87:〜/ app $   
 
  
 
  
 
 
 
 

如何在ClI中激活php PDO模块? 谢谢你的帮助 cdt

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

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!

    已采纳该答案
    评论
    解决 无用
    打赏 举报
  • dougudu3564 2017-01-24 10:54

    you need to install php-mysql

    apt-get install php-mysql
    

    if you are using php7

    apt-get install php7.0-mysql
    

    find your php.ini file and search for pdo_mysql

    ;extension=php_pdo_mysql.so
    

    remove ;

    extension=pdo_mysql.so
    

    Save the file and restart service and verify.

    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题