Go back
7 months ago

Setup PHP Swoole In Your Mac OS

I will assume you have the brew installed in your machine, so that I can continue all of this with brew initials command.

brew install openssl

Do not forget to put the config below in your .bashprofile, mine is .zshrc, so I will open it and paste code below.

export PATH="/opt/homebrew/opt/[email protected]/bin:$PATH"
export LDFLAGS="-L/opt/homebrew/opt/[email protected]/lib"
export CPPFLAGS="-I/opt/homebrew/opt/[email protected]/include"
export PKG_CONFIG_PATH="/opt/homebrew/opt/[email protected]/lib/pkgconfig"

After that, you can start to install pcre2, and you still can do this with brew.

brew install pcre2

When it's done, you can restart your php like so.

brew services restart php

But if you get an error like this

Stopping `php`... (might take a while)
==> Successfully stopped `php` (label: homebrew.mxcl.php)
Error: Formula `php` has not implemented #plist, #service or installed a locatable service file

Don't worry, you can solve that by installing php.

brew install php

And after that, you can start your php in background with brew services like so.

brew services start php

Now start to install the swoole with pecl.

yes | pecl install swoole

And some of you may have an error like this.

In file included from /private/tmp/pear/temp/swoole/ext-src/php_swoole.cc:21:
/opt/homebrew/Cellar/php/8.0.12/include/php/ext/pcre/php_pcre.h:23:10: fatal error: 'pcre2.h' file not found
#include "pcre2.h"
         ^~~~~~~~~
1 error generated.
make: *** [ext-src/php_swoole.lo] Error 1
ERROR: `make' failed

Again, do not worry. We can fix that by making symlink like this.

sudo ln -s /opt/homebrew/include/pcre2.h /usr/local/include/

Now you can start the command again like this

yes | pecl install swoole

When the all success, you will get message in the last line that said Extension swoole enabled in php.ini.