无法让厨师在Ubuntu虚拟机上配置PHP 5.4.x.

时间:2013-07-18 18:11:19

标签: php chef provisioning vagrant

我觉得好像我向前迈出了一步,自我last question以后又向前迈了两步,使用厨师为流浪汉控制的Ubuntu基本盒配置PHP 5.4。我已经放弃尝试使用apt来提取正确版本的PHP,并决定尝试使用源代码构建。

我的食谱

# Name of the role should match the name of the file
name "webserver"

default_attributes(
    "build_essential" => {
        "compiletime" => true
    }
)

override_attributes(
    "mysql" => {
        "server_root_password" => 'reverse',
        "server_repl_password" => 'reverse',
        "server_debian_password" => 'reverse'
    },
    "php" => {
        "install_method" => "source",
        "php54" => true
    }

)

# Run list function we mentioned earlier
run_list(
    "recipe[apt]",
    "recipe[build-essential]",
    "recipe[xml]",
    "recipe[chef-php54]",
    "recipe[openssl]",
    "recipe[apache2]",
    "recipe[apache2::vhosts]",
    "recipe[apache2::mod_rewrite]",
    "recipe[apache2::mod_ssl]",
    "recipe[mysql]",
    "recipe[mysql::server]",
    "recipe[php]",
    "recipe[php::module_gd]",
    "recipe[php::module_curl]",
    "recipe[php::module_mysql]",
    "recipe[php::module_apc]",
    "recipe[chef-php-extra::default]",
    "recipe[chef-php-extra::development]",
    "recipe[apache2::mod_php5]",
    "recipe[database::mysql]",
    "recipe[database::import]",
    "recipe[memcached]",
    "recipe[varnish]"
)

vagrant up时没有明显的错误消息;而这一次,当我sh到盒子并做php -v时,我至少可以看到

PHP 5.4.15 (cli) (built: Jul 18 2013 17:42:34)
Copyright (c) 1997-2013 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2013 Zend Technologies

这是向前迈出的一步。

第一步是php -v首先显示的大量消息:

Failed loading /usr/lib/php5/20090626/xdebug.so:  /usr/lib/php5/20090626/xdebug.so: undefined symbol: output_globals
PHP Warning:  PHP Startup: Unable to load dynamic library '/usr/local/lib/php/extensions/no-debug-non-zts-20100525/apc.so' - /usr/local/lib/php/extensions/no-debug-non-zts-20100525/apc.so: cannot open shared object file: No such file or directory in Unknown on line 0
PHP Warning:  PHP Startup: Unable to load dynamic library '/usr/local/lib/php/extensions/no-debug-non-zts-20100525/gd.so' - /usr/local/lib/php/extensions/no-debug-non-zts-20100525/gd.so: cannot open shared object file: No such file or directory in Unknown on line 0
PHP Warning:  PHP Startup: Unable to load dynamic library '/usr/local/lib/php/extensions/no-debug-non-zts-20100525/mcrypt.so' - /usr/local/lib/php/extensions/no-debug-non-zts-20100525/mcrypt.so: cannot open shared object file: No such file or directory in Unknown on line 0
PHP Warning:  PHP Startup: Unable to load dynamic library '/usr/local/lib/php/extensions/no-debug-non-zts-20100525/mysql.so' - /usr/local/lib/php/extensions/no-debug-non-zts-20100525/mysql.so: cannot open shared object file: No such file or directory in Unknown on line 0
PHP Warning:  PHP Startup: Unable to load dynamic library '/usr/local/lib/php/extensions/no-debug-non-zts-20100525/mysqli.so' - /usr/local/lib/php/extensions/no-debug-non-zts-20100525/mysqli.so: cannot open shared object file: No such file or directory in Unknown on line 0
PHP Warning:  PHP Startup: Unable to load dynamic library '/usr/local/lib/php/extensions/no-debug-non-zts-20100525/pdo.so' - /usr/local/lib/php/extensions/no-debug-non-zts-20100525/pdo.so: cannot open shared object file: No such file or directory in Unknown on line 0
PHP Warning:  PHP Startup: Unable to load dynamic library '/usr/local/lib/php/extensions/no-debug-non-zts-20100525/pdo_mysql.so' - /usr/local/lib/php/extensions/no-debug-non-zts-20100525/pdo_mysql.so: cannot open shared object file: No such file or directory in Unknown on line 0

第二步是当我将浏览器指向phpinfo()文件时,它仍显示PHP Version 5.3.10-1ubuntu3.7;很明显mod_php仍然是错误的版本。

使用像厨师这样的配置工具可能被认为是最佳做法,但是如果浪费了6天的时间,我就无法在几个小时内手动完成任务,我发现它非常令人沮丧。

谷歌提供任何答案似乎毫无用处:任何人都可以帮助我指出正确的方向并向我证明厨师确实是最佳做法而不仅仅是浪费时间和精力。

1 个答案:

答案 0 :(得分:5)

下载最新的Ubuntu服务器

使用virtualbox创建一个新的虚拟机我使用名称'devbox_ubuntu'

启动虚拟机并安装chef / vagrant所需的软件包

$ sudo bash
$ apt-get install sudo ruby ruby-dev libopenssl-ruby rdoc ri irb build-essential ssl-cert curl rubygems puppet


$ echo “deb http://apt.opscode.com/ `lsb_release -cs`-0.10 main”    tee /etc/apt/sources.list.d/opscode.list
$ gpg --keyserver keys.gnupg.net --recv-keys 83EF826A
$ gpg --export packages@opscode.com | tee /etc/apt/trusted.gpg.d/opscode-keyring.gpg > /dev/null

$ apt-get update
$ apt-get install opscode-keyring chef

为网址填写无

添加流浪者用户

$ adduser vagrant
passwrd : vagrant
$ groupadd admin
$ usermod -a -G admin vagrant

为管理员组设置sudo

$ visudo
%admin ALL=(ALL) NOPASSWD: ALL

为SSHD禁用DNS

$ vi /etc/etc/ssh/sshd_config
UseDNS no

SU到流浪者用户并设置SSH密钥

$ su vagrant
$ mkdir -p ~/.ssh
$ chmod 0700 ~/.ssh
$ curl -o ~/.ssh/authorized_keys https://raw.github.com/mitchellh/vagrant/master/keys/vagrant.pub
$ chmod 0600 ~/.ssh/authorized_keys

暂停虚拟机并在本地计算机上设置虚拟机

$ vagrant package --base devbox_ubuntu
$ mv package.box devbox_ubuntu.box

等一会儿......

$ vagrant box add devbox_ubuntu devbox_ubuntu.box
$ mkdir devbox_ubuntu && cd devbox_ubuntu
$ vagrant init devbox_ubuntu
$ vagrant up

[默认]导入基本框'devbox_ubuntu'... ....大量输出

进行测试SSH登录以查看是否一切正常

$ vagrant ssh
$ exit
$ vagrant halt
$ vagrant destroy

冷却。这就是全部。现在设置一些食谱(apache2和dotdeb php 5.4)

$ mkdir cookbooks
$ cd cookbooks

$ git clone https://github.com/opscode-cookbooks/apache2
$ git clone https://github.com/tlenss/misc.git
$ mv misc/chef/cookbooks/dotdeb .
$ rm -rf misc

在Vagrantfile中设置配方

$ cd ..
$ vi Vagrantfile

config.vm.provision :chef_solo do |chef|
     chef.cookbooks_path = "cookbooks"
     chef.add_recipe("dotdeb")
     chef.add_recipe("dotdeb::php54")
     chef.add_recipe("apache2");
     chef.add_recipe("apache2::mod_php5");
end

再次启动VM,让厨师做到这一点。一旦完成。登录并验证PHP版本

$ vagrant up
$ vagrant ssh
$ php -v

PHP 5.4.17-1~dotdeb.0 (cli) (built: Jul  6 2013 17:53:27) 
Copyright (c) 1997-2013 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2013 Zend Technologies

我使用了Yevgeniy Viktorov修改过的dotdeb食谱。一段时间后写了一篇关于它的小article。它可能会有所帮助!

添加额外的PHP扩展我使用来自https://github.com/opscode-cookbooks/php的厨师标准PHP配方。显然Ubuntu和dotdeb的PHP 5.4与libmysqlclient存在依赖性问题。使用mysqlnd而不是mysql应该解决这个问题