Compile and install Swoole with OpenSSL support enabled on Mac and php7.4.6. A recompile installation of Swoole already installed will also work. Create swoole.so and then override the previous swoole.so.

First, install OpenSSL. If openSSL is not available, run the following command to install OpenSSL

Yanzhongxin:consul admin$ which openssl
/usr/bin/openssl
Copy the code

2. Compile and install Swoole

Initially my Swoole version was 4.6.3, and repeated recompilations and installations failed.

So I re-downloaded Swoole4.6.4: pecl.php.net/package/swo…

Decompress the package and go to the directory

Yanzhongxin: swoole - 4.6.4 admin $/ Applications/MxSrvs/bin/PHP/bin/phpize you for: PHP Api Version: 20190902 Zend Module Api No: 20190902 Zend Extension Api No: 320190902 Yanzhongxin:swoole-4.6.4 admin$./configure --enable-openssl --with-openssl-dir=/usr/local/opt/openssl - enable - http2 - with - PHP - config = / Applications/MxSrvs/bin/PHP/bin/PHP - config... Yanzhongxin: swoole - 4.6.4 admin $make... Yanzhongxin:swoole-4.6.4 admin$make install Installing shared extensions: /Applications/MxSrvs/bin/php/lib/php/extensions/no-debug-non-zts-20190902/ Installing header files: /Applications/MxSrvs/bin/php/include/php/Copy the code

Note above:

1. The openSSL path is /usr/bin/openssl

The command was found and could not be found

Yanzhongxin:consul admin$ cd /usr/bin/openssl
bash: cd: /usr/bin/openssl: Not a directory
Yanzhongxin:consul admin$ cd /usr/local/opt/openssl
Yanzhongxin:openssl admin$ ls
AUTHORS                 INSTALL_RECEIPT.json    NEWS                    bin                     lib
CHANGES                 LICENSE                 README                  include                 share
Copy the code

./configure –enable-openssl –with-openssl-dir=/usr/local/opt/openssl –enable-http2 –with-php-config=/Applications/MxSrvs/bin/php/bin/php-config

Note the openssl-dir path

2. The storage location of Swoole.so after compilation is:

Installing shared extensions: /Applications/MxSrvs/bin/php/lib/php/extensions/no-debug-non-zts-20190902

3. Make sure extension=swoole.so is added to the php.ini configuration

You can perform the following configuration directly

extension=/Applications/MxSrvs/bin/php/lib/php/extensions/no-debug-non-zts-20190902/swoole.so
swoole.use_shortname = 'Off'
Copy the code

Swoole.so can also be copied to the ext/ directory in PHP

The php.ini configuration is extension=swoole.so

3. Check whether openSSL is enabled

Yanzhongxin:swoole-4.6.4 admin$PHP --ri swoole swoole swoole => enabled Author => swoole Team <[email protected]> Version 4.6.4 Built => Mar 28 2021 18:09:50 Coroutine => Enabled with boost asm context kqueue => Enabled rwlock => Enabled Openssl => openssl 1.1.5g 21 Apr 2020 DTLS => Enabled pcRE => Enabled zlib => 1.2.11 brotli => E16777225/D16777225 async_redis => enabled Directive => Local Value => Master Value swoole.enable_coroutine => On => On swoole.enable_library => On => On swoole.enable_preemptive_scheduler => Off => Off swoole.display_errors => On => On swoole.use_shortname => Off => Off swoole.unixsock_buffer_size => 262144 => 262144Copy the code