使用Vagrant和puphpet为PHP启用pthreads


Enable pthreads for PHP with Vagrant and puphpet

我一直尝试在Vagrant中启用pthreads扩展。我已经通过puppet生成了Vagrantfile,并在PECL部分中选择了pthreads。当我运行时,它说一切正常,但是当我在虚拟机中运行php -m时,扩展丢失,类不可用。

如果我执行vagrant ssh并尝试手动安装pthreads,我得到以下错误:

$ sudo pecl install pthreads
downloading pthreads-2.0.7.tgz ...
Starting to download pthreads-2.0.7.tgz (77,570 bytes)
..................done: 77,570 bytes
34 source files, building
running: phpize
Configuring for:
PHP Api Version:         20121113
Zend Module Api No:      20121212
Zend Extension Api No:   220121212
building in /tmp/pear/temp/pear-build-rootS6s2Hq/pthreads-2.0.7
running: /tmp/pear/temp/pthreads/configure
checking for grep that handles long lines and -e... /bin/grep
checking for egrep... /bin/grep -E
checking for a sed that does not truncate output... /bin/sed
checking for cc... cc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether cc accepts -g... yes
checking for cc option to accept ISO C89... none needed
checking how to run the C preprocessor... cc -E
checking for icc... no
checking for suncc... no
checking whether cc understands -c and -o together... yes
checking for system library directory... lib
checking if compiler supports -R... no
checking if compiler supports -Wl,-rpath,... yes
checking build system type... x86_64-unknown-linux-gnu
checking host system type... x86_64-unknown-linux-gnu
checking target system type... x86_64-unknown-linux-gnu
checking for PHP prefix... /usr
checking for PHP includes... -I/usr/include/php5 -I/usr/include/php5/main -I/usr/include/php5/TSRM -I/usr/include/php5/Zend -I/usr/include/php5/ext -I/usr/include/php5/ext/date/lib
checking for PHP extension directory... /usr/lib/php5/20121212
checking for PHP installed headers prefix... /usr/include/php5
checking if debug is enabled... no
checking if zts is enabled... no
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... no
checking for nawk... nawk
checking if nawk is broken... no
checking whether to enable Threading API... yes, shared
checking whether to enable pedantic locking... no
checking checking for ZTS... configure: error: pthreads requires ZTS, please re-compile PHP with ZTS enabled
ERROR: `/tmp/pear/temp/pthreads/configure' failed

看来我需要在流浪环境中启用ZTS。有没有办法在配置中指定它?yaml文件?这是我目前拥有的:

---
vagrantfile-local:
    vm:
        box: debian-wheezy72-x64-vbox43
        box_url: 'http://box.puphpet.com/debian-wheezy72-x64-vbox43.box'
        hostname: null
        network:
            private_network: 192.168.56.101
            forwarded_port:
                RPfV8nB1v0E7:
                    host: '7885'
                    guest: '22'
        provider:
            virtualbox:
                modifyvm:
                    natdnshostresolver1: on
                    memory: '512'
                setextradata:
                    VBoxInternal2/SharedFoldersEnableSymlinksCreate/v-root: 1
        provision:
            puppet:
                manifests_path: puphpet/puppet
                manifest_file: manifest.pp
                options:
                    - '--verbose'
                    - '--hiera_config /vagrant/puphpet/puppet/hiera.yaml'
                    - '--parser future'
        synced_folder:
            Nko2ivpBaaBH:
                source: ./
                target: /var/www/php-mud-client
                nfs: 'false'
        usable_port_range: 2200..2250
    ssh:
        host: null
        port: null
        private_key_path: null
        username: vagrant
        guest_port: null
        keep_alive: true
        forward_agent: false
        forward_x11: false
        shell: 'bash -l'
    vagrant:
        host: detect
server:
    packages:
        - vim
    dot_files:
        -
            bash_aliases: null
    _prevent_empty: ''
mailcatcher:
    install: 0
    settings:
        smtp_ip: 0.0.0.0
        smtp_port: 1025
        http_ip: 0.0.0.0
        http_port: '1080'
        mailcatcher_path: /usr/local/bin
        log_path: /var/log/mailcatcher/mailcatcher.log
apache:
    install: 1
    settings:
        user: www-data
        group: www-data
        default_vhost: true
        manage_user: false
        manage_group: false
        sendfile: 0
    modules:
        - php
        - rewrite
    vhosts: {  }
    mod_pagespeed: 0
    mod_spdy: 0
php:
    install: '1'
    version: '55'
    composer: '1'
    modules:
        php:
            - cli
            - intl
            - mcrypt
        pear: {  }
        pecl:
            - pecl_http
            - pthreads
    ini:
        display_errors: On
        error_reporting: '-1'
        session.save_path: /var/lib/php/session
    timezone: Europe/Madrid
mysql:
    install: 0
    root_password: '123'
    phpmyadmin: 0
    adminer: 0
    databases: {  }
postgresql:
    install: 0
    settings:
        root_password: '123'
        user_group: postgres
        encoding: UTF8
        version: '9.3'
    databases: {  }
    adminer: 0
mariadb:
    install: 0
    root_password: '123'
    phpmyadmin: 0
    adminer: 0
    databases: {  }
mongodb:
    install: 0
    settings:
        auth: 1
        port: '27017'
    databases: {  }
redis:
    install: 0
    settings:
        conf_port: '6379'
beanstalkd:
    install: 0
    settings:
        listenaddress: 0.0.0.0
        listenport: '13000'
        maxjobsize: '65535'
        maxconnections: '1024'
        binlogdir: /var/lib/beanstalkd/binlog
        binlogfsync: null
        binlogsize: '10485760'
    beanstalk_console: 0
    binlogdir: /var/lib/beanstalkd/binlog
rabbitmq:
    install: 0
    settings:
        port: '5672'

我终于用shell脚本创建了一个流浪汉文件,该脚本编译PHP 5.5并启用了以下选项:

  • 启用调试
  • enable-maintainer-zts
  • enable-pthreads

流浪汉文件可以在Github上找到:https://github.com/carlescliment/configs/tree/master/vagrant/php-with-zts

因为我不需要一个非常复杂的环境,这似乎就足够了。