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 commandcomposer config -g --unset repos.packagistto 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
-
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 -
Install the event extension. Run the command:
(event extension requires PHP >= 5.4)pecl install eventNote: When prompted
Include libevent OpenSSL support [yes] :, enternoand hit Enter; for the rest, just hit Enter. -
Run
php --inito find and open the php.ini file, add the following configuration at the end:extension=event.so
Debian/Ubuntu System Installation
-
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 -
Install the event extension. Run the command:
pecl install eventNote: When prompted
Include libevent OpenSSL support [yes] :, enternoand hit Enter; for the rest, just hit Enter. -
Run
php --inito 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
-
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 -
Install the event extension. Run the command:
(Note: event extension requires PHP >= 5.4)pecl install eventNote: When prompted
Include libevent OpenSSL support [yes] :, enternoand hit Enter; for the rest, just hit Enter. -
Run
php --inito find and open the php.ini file, add the following configuration at the end:extension=event.so -
Run the command (this step downloads the Workerman main program from GitHub):
git clone https://github.com/walkor/Workerman -
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
-
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 -
Install the event extension. Run the command:
(Note: event extension requires PHP >= 5.4)pecl install eventNote: When prompted
Include libevent OpenSSL support [yes] :, enternoand hit Enter; for the rest, just hit Enter. -
Run
php --inito find and open the php.ini file, add the following configuration at the end:extension=event.so -
Run the command (this step downloads the Workerman main program from GitHub):
git clone https://github.com/walkor/Workerman -
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.
-
Refer to the manual section Appendix - Installing Extensions, method 3 for source code compilation installation of the
pcntlextension. -
Refer to the manual section Appendix - Installing Extensions, method 4 for using phpize to install the
eventextension (this can be omitted for development machines). -
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.
-
Run the following command to install the
brewtool (if you have already installedbrew, you can skip this step):/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" -
Run the following command to install
php:brew install php -
Run the following command to install the
eventextension:brew install php-event -
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
-
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 -
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, writeextension=socket.sobeforeextension=event.so, so that the socket extension loads first.