Installation Instructions

Workerman is essentially a PHP code package. If your PHP environment is already set up, you only need to download the Workerman source code or demo to run it.

Installing via Composer:

composer require workerman/workerman

Note
Some Composer proxy mirrors are incomplete. Use the command composer config -g --unset repos.packagist to remove the proxy.

Windows Users (Must Read)

Starting from version 3.5.3, Workerman supports both Windows and Linux systems simultaneously. Windows users need to configure the PHP environment variables.

=== The content below this page applies only to the Linux environment of Workerman; Windows users please ignore ===

Linux System Environment Check

You can use the following script to test whether your local PHP environment meets the requirements to run Workerman.
curl -Ss https://www.workerman.net/check | php

If the script displays "ok" for all checks, it means that your environment meets Workerman's requirements, and you can directly download examples from the official website to run.

If not all checks show "ok," please refer to the documentation below to install the missing extensions.

(Note: The check script does not test for the event extension. If your business concurrent connection count exceeds 1024, you must install the event extension and optimize the Linux kernel. For installation methods, please refer to the description below.)

Install Missing Extensions in Existing PHP Environment

Installing pcntl and posix extensions:

CentOS System
If PHP was installed using yum, you can run the command yum install php-process to install the pcntl and posix extensions.

If the installation fails or if PHP was not installed using yum, please refer to the manual section Appendix - Installing Extensions, method 3 for source code compilation installation.

Debian/Ubuntu/macOS System
Please refer to the manual section Appendix - Installing Extensions, method 3 for source code compilation installation.

Installing the event extension:

To support a larger number of concurrent connections, it is necessary to install the event extension and optimize the Linux kernel. The installation method is as follows:

CentOS System

  1. Install the event extension dependency, libevent-devel package. Run the command:

    yum install libevent-devel -y
    # If installation fails, try the following command
    # yum install libevent2-devel -y
  2. Install the event extension. Run the command:
    (event extension requires PHP >= 5.4)

    pecl install event

    Note: When prompted Include libevent OpenSSL support [yes] :, enter no and hit Enter; for the rest, just hit Enter.

  3. Run php --ini to find and open the php.ini file, add the following configuration at the end:

    extension=event.so

Debian/Ubuntu System Installation

  1. Install the event extension dependency, libevent-dev package. Run the command:

    apt-get install libevent-dev -y
    # If installation fails, please try the following command
    # apt-get install libevent2-dev -y
  2. Install the event extension. Run the command:

    pecl install event

    Note: When prompted Include libevent OpenSSL support [yes] :, enter no and hit Enter; for the rest, just hit Enter.

  3. Run php --ini to find and open the php.ini file, add the following configuration at the end:

    extension=event.so

macOS System Installation Instructions

Typically, macOS is used as a development machine, and there is no need to install the event extension.

Fresh System Installation (Fresh Install of PHP + Extensions)

CentOS System Installation Instructions

  1. Run the command (this step includes installing the php-cli main program, as well as pcntl, posix, libevent library and git):

    yum install php-cli php-process git gcc php-devel php-pear libevent-devel -y
  2. Install the event extension. Run the command:
    (Note: event extension requires PHP >= 5.4)

    pecl install event

    Note: When prompted Include libevent OpenSSL support [yes] :, enter no and hit Enter; for the rest, just hit Enter.

  3. Run php --ini to find and open the php.ini file, add the following configuration at the end:

    extension=event.so
  4. Run the command (this step downloads the Workerman main program from GitHub):

    git clone https://github.com/walkor/Workerman
  5. Refer to Getting Started - Simple Development Example Section to write the entry file to run.
    Alternatively, you can download the packaged demo from the official website to run.

Debian/Ubuntu System Installation Instructions

  1. Run the command (this step includes installing the php-cli main program, libevent library, and git):

    apt-get install php-cli git gcc php-pear php-dev libevent-dev -y
  2. Install the event extension. Run the command:
    (Note: event extension requires PHP >= 5.4)

    pecl install event

    Note: When prompted Include libevent OpenSSL support [yes] :, enter no and hit Enter; for the rest, just hit Enter.

  3. Run php --ini to find and open the php.ini file, add the following configuration at the end:

    extension=event.so
  4. Run the command (this step downloads the Workerman main program from GitHub):

    git clone https://github.com/walkor/Workerman
  5. Refer to Getting Started - Simple Development Example Section to write the entry file to run.
    Alternatively, you can download the packaged demo from the official website to run.

macOS System Installation Instructions

Method 1: macOS comes with PHP CLI, but may lack the pcntl extension.

  1. Refer to the manual section Appendix - Installing Extensions, method 3 for source code compilation installation of the pcntl extension.

  2. Refer to the manual section Appendix - Installing Extensions, method 4 for using phpize to install the event extension (this can be omitted for development machines).

  3. Download the Workerman main program from https://www.workerman.net/download/workermanzip, or visit the official website to download examples to run.

Method 2: Install PHP and corresponding extensions using the brew command.

  1. Run the following command to install the brew tool (if you have already installed brew, you can skip this step):

    /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
  2. Run the following command to install php:

    brew install php
  3. Run the following command to install the event extension:

    brew install php-event    
  4. Visit the official website to download examples to run.

Event Extension Description

The Event extension is not mandatory. It is recommended to install the Event extension if your business needs to support over 1000 concurrent connections, as it can handle a massive number of concurrent connections. If your business has a relatively low number of concurrent connections, such as below 1000, you may not need to install it.

Common Issues

  1. If you encounter the error checking for include/event2/event.h... not found, please try removing the libevent-dev(el) library and then install libevent2-dev(el).
    CentOS system: yum remove libevent-devel && yum install libevent2-devel
    Debian/Ubuntu system: apt-get remove libevent-dev && apt-get install libevent2-dev

  2. If you encounter the error NOTICE: PHP message: PHP Warning: PHP Startup: Unable to load dynamic library '.../event.so' - ..../event.so: undefined symbol: php_sockets_le_socket in Unknown on line 0.
    Please change the loading order of event.so and socket.so, i.e., in php.ini, write extension=socket.so before extension=event.so, so that the socket extension loads first.