【问题标题】:PHP fatal error: Interface 'JsonSerializable' not foundPHP 致命错误:未找到接口“JsonSerializable”
【发布时间】:2016-12-07 16:42:03
【问题描述】:

我今天已将我的 D8 站点从 Windows 移动并配置到 Ubuntu 14.04 PC。但是当我运行该站点时,出现以下错误:

致命错误:在第 32 行的 /var/www/eCartZone/core/lib/Drupal/Component/Render/MarkupInterface.php 中找不到接口“JsonSerializable”

我从终端检查了带有php -m 的已安装模块,并在列表中找到了它。

我使用 $ phpbrew install php-5.5.33 +default+json+mysql+curl 安装了 Php 5.5.33

版本信息:

Php: 5.5.33
Drupal: 8.2.3
Apache: 2.4.7
MySql: 14.14, Distrib 5.5.53

我不知道如何解决这个问题!有人请帮我解决问题。

更新
php -r "phpinfo();" | grep json的命令输出

PHP Warning:  phpinfo(): It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected the timezone 'UTC' for now, but please set date.timezone to select your timezone. in Command line code on line 1
Configure Command =>  './configure'  '--cache-file='''/home/subrara/.phpbrew/cache/config.cache'''' '--prefix=/home/subrara/.phpbrew/php/php-5.5.33' '--with-config-file-path=/home/subrara/.phpbrew/php/php-5.5.33/etc' '--with-config-file-scan-dir=/home/subrara/.phpbrew/php/php-5.5.33/var/db' '--disable-all' '--enable-session' '--enable-short-tags' '--with-zlib=/usr' '--with-libdir=lib/x86_64-linux-gnu' '--with-curl=/usr' '--enable-json' '--with-mysql=mysqlnd' '--with-mysqli=mysqlnd' '--with-pdo-mysql=mysqlnd' '--with-mysql-sock=/var/run/mysqld/mysqld.sock' '--enable-libxml' '--enable-simplexml' '--enable-xml' '--enable-xmlreader' '--enable-xmlwriter' '--with-xsl' '--with-libxml-dir=/usr' '--enable-bcmath' '--with-bz2=/usr' '--enable-calendar' '--enable-cli' '--enable-ctype' '--enable-dom' '--enable-fileinfo' '--enable-filter' '--enable-shmop' '--enable-sysvsem' '--enable-sysvshm' '--enable-sysvmsg' '--enable-mbregex' '--enable-mbstring' '--with-mhash=/usr' '--with-mcrypt=/usr' '--enable-pcntl' '--with-pcre-regex' '--with-pcre-dir=/usr' '--enable-pdo' '--enable-phar' '--enable-posix' '--with-readline=/usr' '--enable-sockets' '--enable-tokenizer' '--with-openssl=/usr' '--enable-zip' '--with-pear=/home/subrara/.phpbrew/php/php-5.5.33/lib/php' '--enable-zend-signals'
/home/subrara/.phpbrew/php/php-5.5.33/var/db/json.ini
json
json support => enabled
json version => 1.2.1

【问题讨论】:

  • php -r "phpinfo();" | grep json 显示什么?
  • 加载的模块也不同,具体取决于您使用的是内置 php 还是像 apache 这样的 Web 服务器。
  • 您在浏览器中运行的 PHP 版本是否与在控制台中运行的 PHP 版本相同?
  • 我用php -r "phpinfo();" | grep json 命令的输出更新了我的问题。浏览器和 CLI 工具都显示相同的 PHP 版本,即 5.5.33。 @JezEmery,如果您不介意,请再解释一下吗?
  • @SubrataSarkar 如果您在命令行中输入php -m,并在浏览器中运行phpinfo();,则可以安装完全不同的模块,因为可以有单独的php.ini 文件每次安装

标签: php json jsonserializer


【解决方案1】:

你需要在你的系统上安装 php-json。在基于 redhat 的操作系统上,您可以使用以下方式安装它:

sudo dnf install php-json

在基于 Debian 的操作系统上,执行以下操作:

sudo apt-get install php-json

【讨论】:

    【解决方案2】:

    经过更多研究,我终于找到了解决方案!希望这对其他人也有帮助。

    据说 Drupal 8 适用于 PHP 5.5.9+,而我的 php 版本是 5.5.33。

    我将我的 PHP 更新到 5.6.22 并且错误消失了!

    $ phpbrew install php-5.6.22 +default+curl+json+mysql+apxs2=/usr/bin/apxs2
    $ phpbrew switch php-5.6.22
    $ sudo service apache2 restart
    

    我的浏览器 (phpinfo();) 和 CLI 现在都将 5.6.22 显示为活动版本!

    感谢jimsmith :)

    【讨论】:

    • 也许你应该使用php7。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-08-15
    • 2018-07-06
    • 1970-01-01
    • 2014-07-21
    • 1970-01-01
    • 2016-08-19
    • 1970-01-01
    相关资源
    最近更新 更多