Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to enable PCNTL on Ubuntu server 16.04

I'm wondering how to enable pcntl extension in PHP7 running on Ubuntu server 16.04.
I saw this http://www.crimulus.com/2010/07/30/howto-enable-pcntl-in-ubuntu-php-installations/ but do we really have to recompile PHP7?

It surprises me as other extensions are usually simple to add with apt-get.

Thanks

like image 970
fralbo Avatar asked Nov 03 '16 17:11

fralbo


People also ask

How do I enable Pcntl?

You have to compile the CGI or CLI version of PHP with --enable-pcntl configuration option when compiling PHP to enable Process Control support.

How do I know if Pcntl is enabled?

Running php -i | grep pcntl will return the following if pcntl is enabled. Save this answer.


1 Answers

for ubuntu 18 and 20:

1- php -v
result for exapmle: PHP 7.4.10

2- sudo wget https://www.php.net/distributions/php-7.4.10.tar.gz
replace 7.4.10 with your php version.

3- sudo tar xfz php-7.4.10.tar.gz && sudo rm -rf php-7.4.10.tar.gz
replace 7.4.10 with your php version.

4- cd php-7.4.10/ext/pcntl/
replace 7.4.10 with your php version.

5- sudo phpize
if phpize is not installed you can install it with apt install php7.0-dev

6- sudo ./configure --with-php-config=/usr/bin/php-config

7- sudo make && sudo make install
the result must be like Installing shared extensions: /usr/lib/php/20190902/

8- cd ../../../ && sudo rm -rf php-7.4.10
replace 7.4.10 with your php version.

9- cd /etc/php/7.4
replace 7.4 with your php version.

10- sudo sh -c "echo 'extension=pcntl.so' > ./mods-available/pcntl.ini"

11- sudo nano ./cli/php.ini then add extension=pcntl.
repeat this job for sudo nano ./apache2/php.ini or sudo nano ./fpm/php.ini.

12- in all above php.ini there is disable_functions that include pcntl prefix. you must enable which one you want.

13- restart your apache2 or fpm with:
sudo service apache2 restart
sudo service php7.4-fpm restart
replace 7.4 with your php version.

14- you can check it with die(extension_loaded('pcntl')); in test.php

note: if you got error : PHP Warning: Module 'pcntl' already loaded in Unknown on line 0, remove extension=pcntl only in cli/php.ini

like image 66
HANNAN Std Avatar answered Sep 18 '22 16:09

HANNAN Std