Question

I feel as though I've taken a step forward and two steps back since my last question about using chef to provision PHP 5.4 for an Ubuntu base box controlled by vagrant. I've given up on trying to use apt to pull the right version of PHP, and decided to try a source build instead.

My recipe

# 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]"
)

No obvious error messages when I vagrant up; and this time, when I ssh to the box and do php -v, I do at least get to see

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

That's one step forward.

First step back is the slew of messages that php -v shows first:

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

Second step back is when I point a browser at a phpinfo() file, it still shows PHP Version 5.3.10-1ubuntu3.7; so clearly the mod_php is still picking up the wrong version.

Using a provisioning tool like chef might be considered best practise, but when it's wasted 6 days of my time struggling to get nowhere for something I could have done manually in a couple of hours I find it pretty frustrating.

Google seems pretty useless for providing any answers: can anybody help point me in the right direction and prove to me that chef really is best practise and not simply a waste of time and effort.

Was it helpful?

Solution

Download latest Ubuntu server

Create a new virtualmachine with virtualbox i used the name 'devbox_ubuntu'

Boot your virtualmachine and install the needed packages for 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

fill in none for the URL

Add the vagrant user

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

Setup sudo for the admin group

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

Disable DNS for SSHD

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

SU to the vagrant user and setup the SSH key

$ 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

halt the VM and setup the VM with vagrant on the local machine

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

Wait a while ...

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

[default] Importing base box 'devbox_ubuntu'... .... lots of output

Do a test SSH login to see if it all works

$ vagrant ssh
$ exit
$ vagrant halt
$ vagrant destroy

Cool. So that's all there. Now setup some recipes (apache2 and 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

Setup the recipes in the 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

Boot the VM again and let chef do it's thing. Once done. Login and verify the PHP version

$ 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

I used a modified dotdeb cookbook by Yevgeniy Viktorov. And wrote a small article about it a while back. It might be helpful!

Adding additional PHP extensions i use the chef's standard PHP recipes from https://github.com/opscode-cookbooks/php. Apparently Ubuntu and dotdeb's PHP 5.4 have a dependency issue with libmysqlclient. Using mysqlnd instead of mysql should fix this

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top