Manually enabling Swoole via php.ini
On most systems Swoole can be enabled by directly editing your
configuration file, you will want to add
to the end of the file and then Swoole should be enabled.
Enabling Swoole via phpenmod
Some Linux distributions like Debian or Ubuntu use the PHP
to load PHP extensions, in this case you can use
to enable Swoole.
一般系统 都可以通过添加扩展到php.ini的方式添加swoole支持,但我用的debian10+php7.4不支持,报如下错
PHP Warning: PHP Startup: Unable to load dynamic library 'swoole' (tried: /usr/lib/php/20190902/swoole (/usr/lib/php/20190902/swoole: cannot open shared object file: No such file or directory), /usr/lib/php/20190902/swoole.so (/usr/lib/php/20190902/swoole.so: undefined symbol: php_json_exception_ce)) in Unknown on line 0
只能通过
#!/bin/bash
# Create a Swoole extension PHP ini file, letting PHP know which modules to load
$ sudo bash -c "cat > /etc/php/<PHP_VERSION>/mods-available/swoole.ini << EOF
; Configuration for Swoole
; priority=25
extension=swoole
EOF"
# Enable the Swoole PHP extension only on CLI mode
$ sudo phpenmod -s cli swoole
# Optional: Enable Swoole for specific version of PHP CLI
$ sudo phpenmod -s cli -v 7.4 swoole
# Check if the Swoole extension has been enabled
$ php -m | grep swoole
You can also disable Swoole using
if you need to (this is not uninstalling, just turning Swoole off):
#!/bin/bash
# Turn off Swoole for CLI or a specific PHP install
sudo phpdismod -s cli swoole
sudo phpdismod -s cli -v 7.4 swoole