How can I enable process control extension (PCNTL) in PHP MAMP?
Asked Answered
T

6

30

I have MAMP and I need to enable -pcntl on my current MAMP installation.

How can I do so?

Timmerman answered 8/3, 2011 at 8:53 Comment(0)
W
59

There is a way of compiling PCNTL as an extension and linking it in to an existing PHP build, but it's a bit in-depth.

I'm doing the following on Mac OS X v10.6 (Snow Leopard) (64 bit), with MAMP and PHP version 5.3.6. Remember to change PHP version numbers in the following lines if yours is different!

Please note that make is required, which isn't installed by default on Mac OS X. You need to install this via Mac developer tools.

First, download a tar of the PHP source code that matches the version you are using in MAMP (e.g., mine is 5.3.6), which you can do at Unsupported Historical Releases. Untar and CD to php-[version]/ext/pcntl, e.g.:

wget http://museum.php.net/php5/php-5.3.6.tar.gz
tar xvf php-5.3.6.tar.gz
cd php-5.3.6/ext/pcntl

You then need to run phpize in the pcntl directory, which is a binary file that comes with MAMP:

cd php-5.3.6/ext/pcntl
/Applications/MAMP/bin/php/php5.3.6/bin/phpize

This creates a bunch of files that are needed for preparing a extension for compiling.

We now need to add some flags to tell it to compile the library with dual 32-bit and 64-bit architecture, as the MAMP PHP has been built this way. If you don't do this, the compiled shared objects won't work.

MACOSX_DEPLOYMENT_TARGET=10.6
CFLAGS="-arch i386 -arch x86_64 -g -Os -pipe -no-cpp-precomp"
CCFLAGS="-arch i386 -arch x86_64 -g -Os -pipe"
CXXFLAGS="-arch i386 -arch x86_64 -g -Os -pipe"
LDFLAGS="-arch i386 -arch x86_64 -bind_at_load"
export CFLAGS CXXFLAGS LDFLAGS CCFLAGS MACOSX_DEPLOYMENT_TARGET

We can then run ./configure and make to build our shared object:

./configure
make

This puts a file called pcntl.so in the modules directory. Copy this file to your MAMP's PHP extensions directory:

cp modules/pcntl.so /Applications/MAMP/bin/php/php5.3.6/lib/php/extensions/no-debug-non-zts-20090626/

Finally, edit the PHP INI file to include the extension:

echo "extension=pcntl.so" >> /Applications/MAMP/bin/php/php5.3.6/conf/php.ini

PCNTL should now be enabled. To check to see whether it has been added, just run:

/Applications/MAMP/bin/php/php5.3.6/bin/php --ri pcntl

Output:

pcntl

pcntl support => enabled

If you see that, it's worked! If anything has gone wrong you can just remove the pcntl.so file from the MAMP PHP extensions directory and remove the INI setting, and try again.

Weka answered 8/12, 2011 at 14:53 Comment(8)
This solution also works for standard PHP that comes with Snow Leopard ^_^Tympanitis
If you encounter error: ‘PHP_FE_END’ undeclared here (not in a function) after running make, replace all occurrences of PHP_FE_END in pcntl.c with {NULL,NULL,NULL}.Colorimeter
Any clue, I am getting Zend/zend_signal.h doe not exist. When I checked it does exists.Frustum
If you have multiple versions of php on your system (as is the case in Lion), you may need to specify the php-config location when on the ./configure step. That will look something like: ./configure --with-php-config=/Applications/MAMP/bin/php/php5.4.10/bin/php-configStormproof
@Stormproof thanks. your tip worked for me... Also if someone is getting compilation error in pcntl.c file, replace HASH_KEY_NON_EXISTENT with HASH_KEY_NON_EXISTANTYalu
Is it possible to make this available to PHP via the command line? I am calling php through the one MAMP installs but the module still doesn't exist after doing this. It made it available to the one that apache is using however.Oneill
@Oneill the MAMP PHP and CLI PHP use different INIs, so check that the extension is enabled in both.Weka
Works with php7.2.14 even in 2019 !Hyderabad
S
5

If you have Homebrew (executable brew) installed on your Mac then you should be able to do:

brew install php53-pcntl

I am no expert on MAMP though.

brew install php53-pcntl
brew info php53-pcntl

Output:

Warning: php53-pcntl-5.3.25 already installed

php53-pcntl: stable 5.3.25
http://php.net/manual/en/book.pcntl.php
/usr/local/Cellar/php53-pcntl/5.3.23 (3 files, 32K)
  Built from source
/usr/local/Cellar/php53-pcntl/5.3.25 (3 files, 32K) *
  Built from source
https://github.com/josegonzalez/homebrew-php/commits/master/Formula/php53-pcntl.rb
==> Dependencies
Build: autoconf
Required: php53
==> Options
--without-config-file
    Do not add ext-pcntl.ini to /usr/local/etc/php/5.3/conf.d
--without-homebrew-php
    Ignore homebrew PHP and use default instead
==> Caveats
To finish installing pcntl for PHP 5.3:
  * /usr/local/etc/php/5.3/conf.d/ext-pcntl.ini was created,
    do not forget to remove it upon extension removal.
  * Restart your webserver.
  * Write a PHP page that calls "phpinfo();"
  * Load it in a browser and look for the info on the pcntl module.
  * If you see it, you have been successful!
Shocking answered 10/5, 2013 at 13:6 Comment(5)
No such brew formula existsEsmond
Yes it does.. You need to do your research better before down voting.Shocking
this depends on the BREW version of PHP being installed - it does not appear to play well with MAMP - which was the original questionEsmond
It works fine with my MAMP version (with php 5.6.1) apart from php56-pcntl is kinda buggy right now and brew can't install it.Grackle
This works with MAMP. Just install phpXX-pcntl first, and than copy the pcntl.so to the correct folder (Check the output of brew for the correct path): cp /usr/local/Cellar/php71-pcntl/7.1.8_15/pcntl.so /Applications/MAMP/bin/php/php7.1.1/lib/php/extensions/no-debug-non-zts-20160303/Foyer
N
3

Just to make my life easier, I made a script from the other post. I used it to add extensions pcntl, sysvmsg, sysvshm, sysvsem and others to MAMP. To use it, cd to the extension directory or pass the directory as an argument to the script. Example: ./addExtension.sh php-5.3.6/ext/pcntl

#!/bin/bash
DIR=$1
MAMP_PHP=$2
if [ -z "$DIR" ]
then
  DIR=`pwd`
fi

if [ -z "$MAMP_PHP" ]
then
  MAMP_PHP='/Applications/MAMP/bin/php/php5.3.6'
fi

EXTENSION=${DIR##*/}

echo Extension: $EXTENSION

cd $DIR

eval "${MAMP_PHP}/bin/phpize"


MACOSX_DEPLOYMENT_TARGET=10.6
CFLAGS="-arch i386 -arch x86_64 -g -Os -pipe -no-cpp-precomp"
CCFLAGS="-arch i386 -arch x86_64 -g -Os -pipe"
CXXFLAGS="-arch i386 -arch x86_64 -g -Os -pipe"
LDFLAGS="-arch i386 -arch x86_64 -bind_at_load"
export CFLAGS CXXFLAGS LDFLAGS CCFLAGS MACOSX_DEPLOYMENT_TARGET

./configure
make

cp modules/${EXTENSION}.so "${MAMP_PHP}/lib/php/extensions/no-debug-non-zts-20090626/"

PHP_INI_PATH="${MAMP_PHP}/conf/php.ini"
sed -e "/extension=${EXTENSION}.so/ d" $PHP_INI_PATH > TMP
mv TMP $PHP_INI_PATH
echo "extension=${EXTENSION}.so" >> $PHP_INI_PATH

eval "${MAMP_PHP}/bin/php --ri ${EXTENSION}"
Neuropsychiatry answered 11/4, 2012 at 18:29 Comment(0)
R
2

I solved the problem by using MacPorts.

I ran the command:

sudo port install php5-pcntl
Ramirez answered 14/5, 2014 at 12:10 Comment(1)
Give more explanation to your answer.Seafaring
P
2

I found some slightly different instructions that worked for Mac OS X v10.10 (Yosemite) and MAMP using PHP 5.6.2.

Instructions were found here: How to get Artisan Tinker Working in OS X 10 MAMP

wget http://museum.php.net/php5/php-5.6.2.tar.gz
tar -xzvf php-5.6.2.tar.gz
mv php-5.6.2 php
mkdir -p /Applications/MAMP/bin/php/php5.6.2/include
mv php /Applications/MAMP/bin/php/php5.6.2/include

cd /Applications/MAMP/bin/php/php5.6.2/include/php
./configure

MACOSX_DEPLOYMENT_TARGET=10.10
CFLAGS="-arch i386 -arch x86_64 -g -Os -pipe -no-cpp-precomp"
CCFLAGS="-arch i386 -arch x86_64 -g -Os -pipe"
CXXFLAGS="-arch i386 -arch x86_64 -g -Os -pipe"
LDFLAGS="-arch i386 -arch x86_64 -bind_at_load"
export CFLAGS CXXFLAGS LDFLAGS CCFLAGS MACOSX_DEPLOYMENT_TARGET

cd ext/pcntl
phpize
./configure
make
cp modules/pcntl.so /Applications/MAMP/bin/php/php5.6.2/lib/php/extensions/no-debug-non-zts-20131226
Papilionaceous answered 24/4, 2015 at 16:58 Comment(0)
P
0
  1. Download a PHP implementation from Unsupported Historical Releases

  2. tar -xzvf php-7.3.8.tar.gz (we will name the outputted folder PhpSrcFolder)

  3. Make sure you've got the MAMP bin directory in your path → echo $PATH. You'll need the extra tools it has in order to do this. (Skip to step 5 if you already have mamp's bin in you $PATH.)

  4. you can add MAMP's bin to your path as follow, we first grep the version of PHP's used by MAMP from ~/.profile (PS: MAMP add alias to php in the latter), then we add the MAMP bin to PATH in accordance with the version used.

    export PHP_VERSION=`grep "alias php" ~/.profile | cut -d"/" -f6 | cut -c4-`
    \# point to your php.ini folder to use the same php setting
    export PHPRC="/Library/Application Support/appsolute/MAMP PRO/conf/"
    export PATH=/Applications/MAMP/bin/php/php$PHP_VERSION/bin:$PATH
    
    ### PS: close and reopen terminal
    
  5. Copy PhpSrcFolder/ext/pcntl to /Applications/MAMP/bin/php/php7.3.8/include/php/ext/pcntl

  6. Go into /Applications/MAMP/bin/php/php7.3.8/include/php/ext/pcntl and then run the phpize command. Note that you'll also need to have Xcode and related tools installed.

  7. You should then be able to run ./configure && make && make install. This will build the extension in /Applications/MAMP/bin/php/php7.3.8/include/php/ext/pcntl/modules/pcntl.so, copy it and paste it in /Applications/MAMP/bin/php/php7.3.8/lib/php/extensions/no-debug-non-zts-20180731/pcntl.so

  8. Now, edit the php.ini and enable the module like you would any of the other extensions. Get path of php.ini loaded by running which phpfor me its : /Library/Application Support/appsolute/MAMP PRO/conf/php7.3.8.ini and recheck that it has the pcntl extension:

    [pcntl]
    
    extension=pcntl.so
    
Premeditation answered 24/1, 2020 at 22:49 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.