fralbo
fralbo

Reputation: 2664

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

Upvotes: 10

Views: 35415

Answers (3)

HANNAN Std
HANNAN Std

Reputation: 439

for ubuntu 18 and 20:

  1. php -v
    result for example: 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

Upvotes: 11

Meloman
Meloman

Reputation: 3712

According to your needs, the solution for me was to use the following tutorial from HowToForge.

Today, current release is 7.4.11, but you can change it.

cd /tmp
wget https://www.php.net/distributions/php-7.4.11.tar.gz
tar xfz php-7.4.11.tar.gz
cd php-7.4.11

On the next you will find --enable-pcntl what is the interesting thing.

./configure --prefix=/opt/php-7.4 --with-pdo-pgsql --with-zlib-dir --with-freetype --enable-mbstring --enable-soap --enable-calendar --with-curl --with-zlib --enable-gd --with-pgsql --disable-rpath --enable-inline-optimization --with-bz2 --with-zlib --enable-sockets --enable-sysvsem --enable-sysvshm --enable-pcntl --enable-mbregex --enable-exif --enable-bcmath --with-mhash --with-zip --with-pdo-mysql --with-mysqli --with-mysql-sock=/var/run/mysqld/mysqld.sock --with-jpeg --with-openssl --with-fpm-user=www-data --with-fpm-group=www-data --with-libdir=/lib/x86_64-linux-gnu --enable-ftp --with-imap --with-imap-ssl --with-kerberos --with-gettext --with-xmlrpc --with-xsl --enable-opcache --enable-intl --with-pear --enable-fpm

Please follow the entire tutorial for a complete working solution here : https://www.howtoforge.com/tutorial/how-to-compile-and-install-php-7.4-on-ubuntu-18-04/

Upvotes: 1

Alex Chiang
Alex Chiang

Reputation: 1840

You don't need apt-get install anything else.

pcntl module was included when you installed php by package manager, try to sudo apt update then sudo apt-get upgrade, it may be helpful. You can also use this to confirm if you have or don't have it.

php -i | grep pcntl
//pcntl suppport=>enable

Also list all my installed module by package manager.

sudo apt install php7.0 php7.0-cli php7.0-common php7.0-fpm php7.0-imap php7.0-json php7.0-mbstring php7.0-opcache php7.0-readline php7.0-xml

Upvotes: 12

Related Questions