zoukankan      html  css  js  c++  java
  • CentOs 自带 PHP 之坑

    在虚拟机上安装了CentOs6.5在上面安装了lnmp开发集成包(php7.1),对于之前没有任何开发经验的我来说,正常且安详滴在集成环境上开发着优雅的小bug.

    然而我今天在Composer拉取代码的时候,出现了问题:

    PHP Warning: PHP Startup: Unable to load dynamic library '/usr/local/php/lib/php/extensions/pdo/pdo_mysql.so' - /usr/local/php/lib/php/extensions/pdo/pdo_mysql.so: undefined symbol: pdo_parse_params in Unknown on line 0
    Using version ^3.4 for sonata-project/admin-bundle
    ./composer.json has been updated
    Loading composer repositories with package information
    Updating dependencies (including require-dev)
    Your requirements could not be resolved to an installable set of packages.
    
    Problem 1
    
    The requested package doctrine/orm (installed at v2.4.8, required as ^2.5) is satisfiable by doctrine/orm[v2.4.8] but these conflict with your requirements or minimum-stability.
    Problem 2
    
    doctrine/orm v2.5.4 requires ext-pdo * -> the requested PHP extension pdo is missing from your system.
    
    doctrine/orm v2.5.3 requires ext-pdo * -> the requested PHP extension pdo is missing from your system.
    
    doctrine/orm v2.5.2 requires ext-pdo * -> the requested PHP extension pdo is missing from your system.
    
    doctrine/orm v2.5.1 requires ext-pdo * -> the requested PHP extension pdo is missing from your system.
    
    doctrine/orm v2.5.0 requires ext-pdo * -> the requested PHP extension pdo is missing from your system.
    
    Installation request for doctrine/orm ^2.5 -> satisfiable by doctrine/orm[v2.5.0, v2.5.1, v2.5.2, v2.5.3, v2.5.4].
    
    To enable extensions, verify that they are enabled in those .ini files:
    
    /etc/php.ini
    
    /etc/php.d/curl.ini
    
    /etc/php.d/fileinfo.ini
    
    /etc/php.d/json.ini
    
    /etc/php.d/phar.ini
    
    /etc/php.d/zip.ini
    You can also run php --ini inside terminal to see which files are used by PHP in CLI mode.  

    这里的问题好像在告诉我,PHP 没有安装 PDO扩展,然而我 通过 phpinfo() 阅览了一下,PDO 是真实存在的,我很是懵逼。

    (关于扩展的小提示:通常在windows 上开发,通过 WAMP下直接在php.ini中启用PDO就行(去掉;extension=php_pdo.dll前面的分号“;”),而linux上添加扩展 是以 .so 结尾的扩展名参考如下:https://blog.csdn.net/leedaning/article/details/46314521 通过上面的小提示,我发现我执行不了 phpize , 然后发现我并没有openssl  我差点去执行了 php 的 openssl 源码安装 相关扩展,我这样的行为是愚蠢的,因为扩展是有的,而我现在发现我竟然也没有openssl 这个C源码扩展。原因是我不是编译安装的而是通过集成安装的环境;若真的这么做了我可能会发现新的问题,也甚者会越走越远....)

    于是 通过 php -m 我发现php的扩展并没有 pdo   mysqli ..., 而我执行 /usr/local/php/bin/php -m 发现竟然有PDO   MYSQLI 扩展,我很是懵逼!原来问题是这样的 CentOs 其实安装完成后 会自带了一个php5.3的版本,我一直没有发现。而我通过 Composer install 的时候其实走的是默认PHP版本,那默认PHP版本就是CentOs自带的 5.3的版本,我的天呐!!!

    通过如下命令才真正的使用了PHP7.1的版本,果然没有任何问题!

    /usr/local/php/bin/php composer install
    

    删掉默认CentOs 自带PHP5.3版本 

    通过如下命令:匹配php,移除php

    [root@localhost MerchantAdmin]# rpm -qa|grep php
    php-mbstring-5.3.3-49.el6.x86_64
    php-cli-5.3.3-49.el6.x86_64
    php-devel-5.3.3-49.el6.x86_64
    php-common-5.3.3-49.el6.x86_64
    php-5.3.3-49.el6.x86_64
    php-bcmath-5.3.3-49.el6.x86_64
    [root@localhost MerchantAdmin]# yum uninstall php-common
    Loaded plugins: fastestmirror, refresh-packagekit, security
    No such command: uninstall. Please use /usr/bin/yum --help
    [root@localhost MerchantAdmin]# yum remove php-common
    

    删除完之后执行了 php -v  

    [root@localhost MerchantAdmin]# php -v
    -bash: /usr/bin/php: No such file or director  

     由此可见 php 并没有全局使用的权限,继续修改添加全局目录 

    [root@localhost bin]# vim /etc/profile
    

     添加如下后两句即可 

    #set for nodejs
    export NODE_HOME=/usr/local/src/node-v8.9.4
    export PATH=$NODE_HOME/bin:$PATH
    export PHP_HOME=/usr/local/php
    export PATH=$PATH:$PHP_HOME/bin
    

     然后重启 profile

    source /etc/profile
    [root@localhost bin]# source /etc/profile
    [root@localhost bin]# 
    [root@localhost bin]# 
    [root@localhost bin]# php -v
    PHP 7.1.7 (cli) (built: Jan 23 2018 19:32:07) ( NTS )
    Copyright (c) 1997-2017 The PHP Group
    Zend Engine v3.1.0, Copyright (c) 1998-2017 Zend Technologies
    

     终于大功告成,坑太深! 

     

  • 相关阅读:
    XidianOJ 1099 A simple problem
    XidianOJ 1097 焊板子的xry111
    XidianOJ 1172 Hiking
    XidianOJ 1176 ship
    bzoj1912(树的直径)
    黑暗城堡(最短路径树)
    poj1639(k限制最小生成树)
    0-1分数规划
    tyvj1391(Kruskal)
    [Usaco2007 Nov]Cow Relays(矩阵乘法+floyd)
  • 原文地址:https://www.cnblogs.com/dump/p/8659827.html
Copyright © 2011-2022 走看看