Page tree

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

PHP pcntl extension (Process Control Extension) is required by MetaFox script. In some cases that the PHP pcntl extension isn't available on the default PHP build or is restricted to web server, you might

...

have to compile this PHP extension pcntl from the source manually. This guide will walk you through the process of compiling and installing the pcntl extension on an Ubuntu server using the command line.

Prerequisites

Before you begin, make sure you have the following:

  • An Ubuntu server with root or sudo privileges.
  • PHP and the necessary build tools installed on your server.

Step 1: Install Build Dependencies

To compile the pcntl extension, you'll need the necessary build tools and development packages. Open a terminal and run the following command to install them:

Code Block
sudo apt-get install php-dev build-essential

Step 2: Download PHP Source Code

To compile the extension, you'll need the PHP source code corresponding to the PHP version you're using. Follow these steps to download the source code:

  1. Check PHP Version: Determine your PHP version by running the following command:

    Code Block
    php -v

    Note down the PHP version for later use.

  2. Download PHP Source: Visit the PHP website's downloads page and download the source code for your PHP version. Alternatively, you can use the following command to download it directly:

    Code Block
    wget https://www.php.net/distributions/php-X.Y.Z.tar.gz

    Replace X.Y.Z with your PHP version (e.g., 8.1.22).

  3. Extract Source Code: Extract the downloaded archive:

    Code Block
    tar -xzf php-X.Y.Z.tar.gz

Step 3: Compile the pcntl Extension

  1. Navigate to Extension Directory: Change into the directory containing the PHP source code:

    Code Block
    cd php-X.Y.Z/ext/pcntl

  2. Compile the Extension: Use the following commands to compile the pcntl extension:
Code Block
phpize

./configure

make

Step 4: Install the Extension

After successfully compiling the extension, you can proceed to install it:

  1. Install Extension: Run the following command to install the compiled extension:

    Code Block
    sudo make install

Step 5: Enable the Extension

To enable the pcntl extension, follow these steps:

  1. Edit php.ini: Open the PHP configuration file in a text editor (e.g., nano):

    Code Block
    sudo nano /etc/php/X.Y/cli/php.ini

    Replace X.Y with your PHP version (e.g., 8.1)

...

  1. Add Extension: Add the following line to enable the pcntl extension. Add it under the "Dynamic Extensions" section:

    Code Block
    extension=pcntl.so

  2. Save and Exit: Save the file and exit the text editor.

Step 6: Restart services PHP-FPM and Web server (Apache)

Restart PHP-FPM

If you are using PHP-FPM, run following command to restart PHP-FPM service

...

Code Block
service phpX.Y-fpm restart


You have successfully compiled and installed the pcntl extension for PHP on your Ubuntu server.