how to enable process control extension (PCNTL) in PHP MAMP?

痞子三分冷 提交于 2019-11-27 05:06:03

问题



I have MAMP and I need to enable -pcntl on my current MAMP installation. How can I do so?

Thanks for your help.


回答1:


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 OSX Snow Leopard (64bit), 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 OSX. You need to install this via Mac developer tools, http://developer.apple.com/unix/

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 http://www.php.net/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:

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 32bit and 64bit architecture, as the MAMP PHP has been built this way. If you don't do this, the compiled shared objects won't work.

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

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

pcntl$ ./configure
pcntl$ make

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

pcntl$ 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

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.




回答2:


If you have 'brew' installed on your MAC then you should be able to do:

brew install php53-pcntl

I am no expert on MAMP though.

==== EDIT ==== (In response to being down voted)

Ian-Lewiss-MacBook-Pro:~ ianlewis$ brew install php53-pcntl
Warning: php53-pcntl-5.3.25 already installed

Ian-Lewiss-MacBook-Pro:~ ianlewis$ brew info php53-pcntl
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!



回答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 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}"



回答4:


I solved the problem by using MacPorts.

Ran the command:

sudo port install php5-pcntl



回答5:


I found some slightly different instructions that worked for Yosemite and Mamp using php 5.6.2. Instructions were found here: https://www.flynsarmy.com/2015/01/get-artisan-tinker-working-osx-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


来源:https://stackoverflow.com/questions/5230255/how-to-enable-process-control-extension-pcntl-in-php-mamp

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!