25

Consider:

cd c:\xampp\htdocs\login
php app/console server:start

This command needs the pcntl extension to run.

This is the error I get when I try to start the web server in my Symfony 2 environment...

I found a fix, by using the command:

php app/console server:run

But why doesn't server:start work on my desktop?

My goal is to:

  1. Starting the Web server

  2. Running a Symfony application using PHP's built-in web server is as easy as executing the server:start command:

    php app/console server:start
    
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Oussama
  • 425
  • 1
  • 5
  • 7

6 Answers6

19

On Windows

You can't install the pcntl extension on Windows. According to the PHP documentation:

Note: This extension is not available on Windows platforms.

Try using Vagrant or a plain virtual machine with a Linux distributions like Ubuntu, Debian or Mint.


On Unix

First, type in your command line in your home directory:

mkdir php
cd php
apt-get source php5
cd php5-(WHATEVER_RELEASE)/ext/pcntl
phpize
./configure
make

Then do this:

cp modules/pcntl.so /usr/lib/php5/WHEVER_YOUR_SO_FILES_ARE/
echo "extension=pcntl.so" > /etc/php5/conf.d/pcntl.ini

Finished!


On Mac

Taken from an answer to How can I enable process control extension (PCNTL) in PHP MAMP?!

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) (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 OS X. 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 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:

/Applications/MAMP/bin/php/php5.3.6/bin/phpize

This creates a bunch of files that are needed for preparing an 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

pcntl

pcntl support => enabled

If you see that, it's worked!


Helpful resources

For Windows:

For Unix operating systems:

For Mac:

Other information:

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
  • 3
    Solid answer - but I think it would be helpful if you placed your sources closer to each excerpt and explicitly block quoted those excerpts. As written, I think someone could make a case that not using block quote formatting is dishonest. – HPierce Apr 01 '17 at 13:49
  • @HPierce: Re *"dishonest"* Yes, it is plagiarism. It needs to be quoted (at a minimum. That may not even be enough). Is wholesale copying of other answers OK, even if attributed and quoted? – Peter Mortensen Nov 29 '22 at 15:01
  • There must be a meta question somewhere. Starting points are *[Answers entirely copied though properly attributed](https://meta.stackoverflow.com/questions/321299/)* and *[How much can be quoted before it is considered plagiarism?](https://meta.stackoverflow.com/questions/343641/how-much-can-be-quoted-before-it-is-considered-plagiarism)*. – Peter Mortensen Nov 29 '22 at 15:04
  • A precedent: *[Why was my answer deleted for plagiarism, despite mentioning the source?](https://meta.stackoverflow.com/questions/421874/)* – Peter Mortensen Dec 07 '22 at 22:55
4

The php-extension-library at GitHub has several pcntl.so files which you can easily download for your version of PHP and add to your extensions and .ini files.

For example, for PHP version 7.3.9:

  1. Download pcntl.so from the repository here or directly here.
  2. Move pcntl.so file to extensions (Example: /Applications/MAMP/bin/php/php7.3.9/lib/php/extensions/no-debug-non-zts-xxxxxxxx)
  3. Add extension=pcntl.so to your .ini
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Jeremy
  • 3,620
  • 9
  • 43
  • 75
4

For Docker

You can use docker-php-extension-installer like this:

# Dockerfile
ADD https://github.com/mlocati/docker-php-extension-installer/releases/latest/download/install-php-extensions /usr/local/bin/

RUN chmod +x /usr/local/bin/install-php-extensions && \
    install-php-extensions pcntl

Then activate the extension in your php.ini file:

extension=pcntl.so
Lenny4
  • 1,215
  • 1
  • 14
  • 33
  • Why `uga+x`? Isn't `a+x` sufficient ([exactly the same](https://en.wikipedia.org/wiki/Chmod#Symbolic_modes))? The same as `ugo+x`. – Peter Mortensen Nov 29 '22 at 15:29
  • @PeterMortensen The documentation (https://github.com/mlocati/docker-php-extension-installer#usage) used to say to run `chmod uga+x` now it's only `chmod +x` – Lenny4 Nov 29 '22 at 18:30
3

You are missing the pcntl extension in your system. This is part of the php-cli package, so you just need to do:

sudo apt-get install php-cli

Check the documentation for more information.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Tomasz Madeyski
  • 10,742
  • 3
  • 50
  • 62
  • 1
    Thanks.., i am using Windows instead of iOs. So the command differs for my environment :) I hope i will find the right commando in the doc u linked! – Oussama Oct 09 '15 at 11:19
2

I wrote the following script to install the pcntl extension for Apache on our Ubuntu systems, which works at least on Ubuntu 16.04 (Xenial Xerus), and I anticipate will also work on Ubuntu 18.04 (Bionic Beaver), as well as other distributions with a similar PHP/Apache packaging/installation layout:

#! /bin/bash

php_ver=$(php -r 'print(join(".",array_slice(explode(".",phpversion()), 0, 2)));')
php_api_ver=$(php-config --phpapi)
pkg="php$php_ver"
mods_dir=/usr/lib/php/$php_api_ver/
php_conf_dir=/etc/php/$php_ver/apache2/conf.d
set -e
work_dir=/tmp/php-pcntl
rm -rf $work_dir
mkdir -p $work_dir
cd $work_dir
apt-get source $pkg
cd $pkg-$php_ver.*/ext/pcntl
phpize
./configure
make -j 8
sudo cp modules/pcntl.so $mods_dir
echo "extension=pcntl.so" | sudo tee $php_conf_dir/10-pcntl.ini > /dev/null
echo "pcntl extension installed, now restart Apache and make sure it really works"

You will possibly need to take care a few prerequisites in addition to the regular Apache/PHP install: apt-get install php-dev php-cli, then edit your /etc/apt/sources.list and make sure the appropriate deb-src line is not commented, and run apt-get update. Then you can just run the script and it should take care of the install. If everything is good, rm -rf /tmp/php-pcntl - I intentionally left that step out of the script in case something goes wrong and I need to debug the contents of that directory.

Note that you will need to make sure that your php.ini does not disable your functions of interest with disable_functions=. E.g., on Ubuntu 16.04 pcntl_signal() along with a few others are disabled with an explicit php.ini directive.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Sasha Pachev
  • 5,162
  • 3
  • 20
  • 20
2

Currently there is no options to enable pcntl in Windows machine. As per php official documentation about pcntl

See what php official documentation about pcntl

Brijesh
  • 21
  • 2