Wednesday, June 6, 2012

Installing PCNTL for PHP on OSX Lion

Today I needed to install the PCNTL extension for PHP for a tutorial session at the Dutch PHP Conference. And since I am working on OSX Lion, this of course gave some problems due to the rather odd installation of Apache and PHP on OSX.

Several sites on the web gave quick guides for this, but still, as always there are a few things you need to keep in mind for it all to work. I will try to walk through the process as detailed as possible:

First start by installing Xcode. You can get the latest version from the App Store. NOTE that the App Store only have the latest version of Xcode, so if you need a version for Snow Leopard or older, you need to dig deep on the web (https://connect.apple.com is a good place to start).

Next you need to install the Command Line Tools from Xcode. You do this by opening Xcode, go to Preferences (CMD + ,) -> Downloads -> Components and hit install on the Command Line Tools. You can get the Command Line Tools without installing Xcode via https://connect.apple.com

Now you need to find out what version of PHP is installed on OSX

$ php -v
PHP 5.3.10 with Suhosin-Patch (cli) (built: Feb 20 2012 22:55:53) Copyright (c) 1997-2012 The PHP Group Zend Engine v2.3.0, Copyright (c) 1998-2012 Zend Technologies

and then get the source code for that version

$ curl -O http://us.php.net/distributions/php-5.3.10.tar.gz

When the download have finished, you should unpack, find the PCNTL extension, phpize, configure, make and then make install

$ tar -xzvf php-5.3.10.tar.gf
$ cd php-5.3.10/ext/pcntl
$ phpize
$ ./configure
$ make
$ sudo make install

If phpize is complaining, you are probably missing autoconf. The easiest way to install autoconf is via Homebrew. You install Homebrew by doing

$ /usr/bin/ruby -e "$(/usr/bin/curl -fsSL https://raw.github.com/mxcl/homebrew/master/Library/Contributions/install_homebrew.rb)"

The first thing you need to do afterwards is to run

$ brew doctor

to find out if any dependencies are missing. Homebrew will telle you what to do, if any is missing.

Lastly you need to enable the PCNTL extension. Do this by adding the following to your php.ini

extension=pcntl.so

if you do not know where your php.ini file are, you probably need to create on, by doing

sudo cp /private/etc/php.ini.default /private/etc/php.ini

Restart Apache and verify that the PCNTL extension are loaded correctly

$ sudo apachectl restart 
$ php -m | grep pcntl 
pcntl

If the PCNTL extension for some reason is not loaded, try and copy the pcntl.so from the compiled source code to the extensions directory

$ sudo cp php-5.3.10/ext/pcntl/modules/pcntl.so /usr/lib/php/extensions/no-debug-non-zts-10090626/

Restart apache and verify the the PCNTL extension is loaded.

Resources:

Tuesday, January 17, 2012

An odd error with VirtualBox on OSX 10.6

I recently updated my version of VirtualBox on my OSX 10.6 box to version 4.1.8 and it suddenly stopped working. When I tried to start on of the virtual I was given the following error message:

Failed to load VMMR0.r0 (VERR_SUPLIB_WORLD_WRITABLE).


After searching the Internet a bit I found a highly unusually solution. Remove write permission for Other!!

$ chmod o-w Applications

Why this work, I do not know but it does. If you know why, please leave a comment.

Wednesday, December 14, 2011

Installing Gearman on Ubuntu 10.04

This is a quick guide on how to install Gearman on Ubuntu 10.04 LTS.

I found numerous guides online, but none of them seems to do the complete trick for me. I know most installations are different from each other, so that is probably the reason why non of them worked on my setup. So here is my addition to the list of Gearman install guides.

  1. The first thing you need to do is to find a PPA repository with an updated version of Gearman. The one bundled in Ubuntu by default is very old. The only reasonable up to date repository I could find is

    https://launchpad.net/~gearman-developers/+archive/ppa

  2. If you do not have the add-apt-repository command installed, you have to install it

    $ sudo apt-get install python-software-properties

  3. Now you can add the repository by issuing the following command

    $ sudo add-apt-repository ppa:gearman-developers/ppa

  4. After adding the repository, you should update the package list

    $ sudo apt-get update

  5. Now you can install the latest version of Gearman

    $ sudo apt-get install gearman gearman-job-server gearman-tools libgearman4 libgearman-dev

    Please note that as of December 2011 the latest update to the repository was in May 2011 with Gearman version 0.14.
  6. You are now free to install Gearman extension to whatever language  you like. Most requirements should be covered by the above mentioned packages.
    You can start the Gearman job server by the following comand

    $ gearman -d
References

Wednesday, September 7, 2011

Sticky session on Linux

Today i stumbled upon the slides from a talk given at Confoo 2011 by Sean Coates called "Fifty Tips, Tricks and Tools ...in one talk". Most of the stuff was not new to me, but still informative. But slide 56 gave a very usefull snippet "Sticky shell start", which allows you to login and be placed where the last shell operated.

You should place the following snippit in your ~/.bashrc or ~/.profile

cd () { builtin cd "$@" ; pwd > ~/.pwd ; }
cd "`cat ~/.pwd`"  

To me this is very usefull since i often jump between different servers and often need to go to the same place every time. so this saves me a lot of typing.

Tuesday, August 16, 2011

Quick tip: Save without permissions in VIM

Like many others I use VIM for my daily work. And like many others I often forget to open files with the right permissions (i.e. sudo vim ...).

To save a file that you need special permissions for, do the following:

:w !sudo tee %

this will allow you to save the file even though you do not have the right permissions (You need to have sudo rights of course).

More tips can be found here.