Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to enable pcntl in php ( while using a framework like Symfony2 )

Tags:

php

symfony

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 symfony2 environment..

I found a fix, by using the command:

$ php app/console server:run

But does someone know why server:start doesn't work on my desktop? Thanks in advance.

My goal is to:

Starting the Web Server

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
like image 487
Oussama Avatar asked Oct 09 '15 11:10

Oussama


3 Answers

On Windows

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

Note: This extension is not available on Windows platforms.

Try using Vagrant or a plain virtual machine with 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 https://stackoverflow.com/a/8432855/5157221!

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!


Helpful resources

For Windows:

  • How to install PCNTL extension in windows
  • https://www.drupal.org/node/771448

For UNIX operating systems:

  • http://www.crimulus.com/2010/07/30/howto-enable-pcntl-in-ubuntu-php-installations/

For Mac:

  • how to enable process control extension (PCNTL) in PHP MAMP?
  • https://serverfault.com/questions/158113/installing-pcntl-module-for-php-without-recompiling

Other informations:

  • https://github.com/symfony/symfony/issues/12153
like image 118
Suriyaa Avatar answered Sep 21 '22 07:09

Suriyaa


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

sudo apt-get install php-cli

Check doc for more info

like image 26
Tomasz Madeyski Avatar answered Sep 23 '22 07:09

Tomasz Madeyski


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

For example, for php version 7.3.9:

  1. Download pcntl.so from the repo here or directly here.
  2. Move pcntl.so file to extensions (Ex: /Applications/MAMP/bin/php/php7.3.9/lib/php/extensions/no-debug-non-zts-xxxxxxxx)
  3. Add extension=pcntl.so to your .ini
like image 44
Jeremy Avatar answered Sep 24 '22 07:09

Jeremy