本文介绍了Laravel Homestead Mongo安装导致PHP错误未定义符号:第0行中的Unknown中的php_json_serializable_ce的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

安装MongoDB之后,无论何时从终端运行任何php命令,我都会收到此错误:

After installing MongoDB I'm now get this error whenever I run any php command from terminal:

php -v

我已经搜索了2天.我看过这些:

I have searched for 2 days now. I have seen these:

PHP无法加载动态库(mongo.so)

https://github.com/mongodb/mongo-php-library /issues/126

而且我很确定从Google出现此错误的其他任何解决方案.它们似乎都是php5的修复程序,对我不起作用.

and I'm pretty sure any other solution that comes up from google this error. They all seem to be fixes for php5 and ain't working for me.

我已将extension = mongodb.so添加到ini文件中.

I have added extension=mongodb.so to ini files.

我已破坏虚拟机并重新启动了100次.

I have destroyed VM and started fresh 100 times.

我正在跑步:流浪汉1.8.5Laravel安装程序版本1.3.3

I'm running:Vagrant 1.8.5Laravel Installer version 1.3.3

vagrant@homestead:~$ php -v 

PHP Warning:  PHP Startup: Unable to load dynamic library '/usr/lib/php/20151012/mongodb.so' - /usr/lib/php/20151012/mongodb.so: undefined symbol: php_json_serializable_ce in Unknown on line 0 PHP
7.0.13-1+deb.sury.org~xenial+1 (cli) ( NTS ) Copyright (c) 1997-2016 The PHP Group Zend Engine v3.0.0, Copyright (c) 1998-2016 Zend Technologies
    with Zend OPcache v7.0.13-1+deb.sury.org~xenial+1, Copyright (c) 1999-2016, by Zend Technologies
    with blackfire v1.14.1~linux-x64-non_zts70, https://blackfire.io, by Blackfireio Inc.

Mongo已安装并正常运行:

Mongo is installed and running fine:

vagrant@homestead:~$ mongo
MongoDB shell version v3.4.0
connecting to: mongodb://127.0.0.1:27017
MongoDB server version: 3.4.0
Server has startup warnings: 
2016-12-05T15:32:01.158+0000 I STORAGE  [initandlisten] 
2016-12-05T15:32:01.204+0000 I CONTROL  [initandlisten] 
2016-12-05T15:32:01.204+0000 I CONTROL  [initandlisten] ** WARNING: Access control is not enabled for the database.
2016-12-05T15:32:01.204+0000 I CONTROL  [initandlisten] **          Read and write access to data and configuration is unrestricted.
2016-12-05T15:32:01.204+0000 I CONTROL  [initandlisten] 
2016-12-05T15:32:01.204+0000 I CONTROL  [initandlisten] 
2016-12-05T15:32:01.204+0000 I CONTROL  [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/enabled is 'always'.
2016-12-05T15:32:01.204+0000 I CONTROL  [initandlisten] **        We suggest setting it to 'never'
2016-12-05T15:32:01.204+0000 I CONTROL  [initandlisten] 
2016-12-05T15:32:01.204+0000 I CONTROL  [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is 'always'.
2016-12-05T15:32:01.205+0000 I CONTROL  [initandlisten] **        We suggest setting it to 'never'
2016-12-05T15:32:01.205+0000 I CONTROL  [initandlisten] 
> 

但是我无法在世界上停止此php错误!

But I can't stop this php error for nothing in the world!!!

推荐答案

我认为问题出在这里,mongodb.so依赖于json.so.解决方案是在json.so之后加载mongodb.so.

I think the problem is here that mongodb.so depends on json.so. The solution is to load mongodb.so after json.so.

我想您正在为Homestead使用自定义Mongo脚本.该脚本在php.ini文件中输出mongodb.so模块,其结果是首先加载mongodb.so.您应该创建一个mongodb.ini文件,在该文件中装入mongodb.so.

I guess you are using the custom Mongo script for Homestead. The script outputs the mongodb.so module in php.ini file with the result that mongodb.so is loaded first.You should create a mongodb.ini file where mongodb.so is loaded.

创建.ini文件:/etc/php/7.0/mods-available/mongodb.ini,内容:

Create the .ini-file: /etc/php/7.0/mods-available/mongodb.ini with content:

; configuration for php mongo module
; priority=30
extension=mongodb.so

给它优先级30,因为json得到20(在我的设置中)以确保之后加载.

Give it priority 30, since json gets 20 (in my settings) to be sure it is loaded afterwards.

创建一个ini文件到/etc/php/7.0/fpm/conf.d的软链接,以使其可用于网络服务器.

Create a softlink of the ini-file to /etc/php/7.0/fpm/conf.d to make it available for the webserver.

ln -s /etc/php/7.0/mods-available/mongodb.ini 30-mongodb.ini

重新加载Web服务器和php-fpm.

Reload webserver and php-fpm.

sudo service [your webserver] restart && sudo service php7.0-fpm restart

您完成了!您可以用相同的方式配置cli-version

You are done! You can config the cli-version the same way

这篇关于Laravel Homestead Mongo安装导致PHP错误未定义符号:第0行中的Unknown中的php_json_serializable_ce的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-23 13:16