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 ( 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

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

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

$ tar -xzvf
$ 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"

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

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 

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

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

Restart apache and verify the the PCNTL extension is loaded.



Joseph Fung said...

Clear post - thanks for sharing. For what it's worth, some PHP distros won't properly compile the PCNTL extension: make returns an error:

php-5.3.15/ext/pcntl/pcntl.c:175: error: ‘PHP_FE_END’ undeclared here (not in a function)

PHP_FE_END is supposed to be defined as the value {NULL,NULL,NULL} in the main php headers, but for some reason, the copy of these headers installed for some versions of PHP are sometimes missing these macros, though it exists in the headers in the source distribution.

The fix was to edit pcntl.c and on line 175 replace PHP_FE_END with {NULL,NULL,NULL}

Then, continuing with your instructions (make, sudo make install, etc...) worked well.

Sara said...

I am starting to learn php but now i am doing some apps y in c++ so i don't have enough time to learn both i hope in the future i can learn and share my knowledge to maybe you can teach me some of you tricks if you get a whatsapp download

lafif astahdziq said...

Great post,,
thanks,, saving my time

Jesus Alc said...

Or you could do a

brew install pcntl

It will give you flavors to choose from

==> Searching for similarly named formulae...
These similarly named formulae were found:
homebrew/php/php53-pcntl homebrew/php/php54-pcntl homebrew/php/php55-pcntl homebrew/php/php56-pcntl homebrew/php/php70-pcntl

Naviya Nair said...

I have read your blog its very attractive and impressive. I like it your blog.

PHP 7 Training in chennai | PHP 7 Training Course

PHP 7 Training in chennai | Online PHP 7 Course