在虛擬機上安裝了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
終於大功告成,坑太深!