配置:错误:请安装 libyaml

配置:错误:请安装 libyaml

我正在关注安装PHP 中 YAML 解析的基础知识在 Fedora 20 中为 PHP 安装 YAML。

我经历了以下所有步骤:

wget http://pecl.php.net/get/yaml-1.1.0.tgz
tar -xvzf yaml-1.1.0.tgz
cd yaml-1.1.0
phpize
./configure && make && make install

但最后一个不起作用:

# ./configure && make && make install
checking for grep that handles long lines and -e... /bin/grep
checking for egrep... /bin/grep -E
.../...
checking for re2c... no
configure: WARNING: You will need re2c 0.13.4 or later if you want to regenerate PHP parsers.
checking for gawk... gawk
checking whether to enable LibYAML suppot... yes, shared
checking for yaml headers... not found
configure: error: Please install libyaml

当我收到“请安装 libyaml”时,我检查它是否已安装...并且已经安装!

# yum list installed | grep yaml
libyaml.x86_64                         0.1.6-1.fc20                    @updates 
yaml-cpp03.x86_64                      0.3.0-4.fc20                    @anaconda

当然,如果我创建一个 php 文件并调用yaml_parse_file(),我会收到错误:

Fatal error: Call to undefined function yaml_parse_file() in XXXfile on line YYY

什么可以缺失?

答案1

您应该安装 libyaml-dev,而不是 libyaml。在 CentOS 上,我使用 安装了它sudo yum install -y libyaml-devel.x86_64

[vagrant@localhost yaml-1.2.0]$ yum search libyaml
============================================
N/S Matched: libyaml
============================================
libyaml-devel.i686 : Development files for LibYAML applications
libyaml-devel.x86_64 : Development files for LibYAML applications
libyaml.i686 : YAML 1.1 parser and emitter written in C
libyaml.x86_64 : YAML 1.1 parser and emitter written in C

答案2

哦,事情本来不应该这样结束的,但我找到了解决办法如何使用 Pecl 安装Google Code 中的文档:

  • 使用您喜欢的方法安装 LibYAML。例如,在 Ubuntu 机器上安装sudo apt-get install libyaml-dev即可。
  • sudo pecl install yaml-beta
  • 编辑 php.ini 设置并添加extension=yaml.so
  • 看看是否有效php --re yaml

由于我使用的是 Fedora,因此我必须使用稍微不同的方法:

# yum search yaml | grep -i php
php-symfony-YAML.noarch : The Symfony YAML Component
php-pecl-yaml.x86_64 : PHP Bindings for yaml
php-symfony-yaml.noarch : Symfony Yaml Component
php-symfony2-Yaml.noarch : Symfony2 Yaml Component
php54-php-pecl-yaml.x86_64 : PHP Bindings for yaml
php56-php-pecl-yaml.x86_64 : PHP Bindings for yaml
syck.i686 : YAML for C, Python, and PHP
syck.x86_64 : YAML for C, Python, and PHP
syck-php.x86_64 : YAML module for php

所以我安装了php-pecl-yaml.x86_64

# yum install php-pecl-yaml.x86_64

我将这一行添加到我的php.ini文件中,重新启动了 apache 以防万一,现在我得到了一个很好的输出:

# php --re yaml
Extension [ <persistent> extension #16 yaml version 1.1.1 ] {

  - Dependencies {
    Dependency [ date (Optional) ]
  }

  - INI {
    Entry [ yaml.decode_binary <ALL> ]
      Current = '0'
    }
    Entry [ yaml.decode_timestamp <ALL> ]
      Current = '0'
    }
    Entry [ yaml.output_canonical <ALL> ]
      Current = '0'

    .../...

    Function [ <internal:yaml> function yaml_emit_file ] {

      - Parameters [5] {
        Parameter #0 [ <required> $filename ]
        Parameter #1 [ <required> $data ]
        Parameter #2 [ <optional> $encoding ]
        Parameter #3 [ <optional> $linebreak ]
        Parameter #4 [ <optional> array $callbacks ]
      }
    }
  }
}

相关内容