Selasa, 09 November 2021

Cara Menyiapkan PHP Swoole di Mac OS

This post will guide you to install the php swoole. I can't guarantee it will be a success, but we strive for it.

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/openssl@3/bin:$PATH"
export LDFLAGS="-L/opt/homebrew/opt/openssl@3/lib"
export CPPFLAGS="-I/opt/homebrew/opt/openssl@3/include"
export PKG_CONFIG_PATH="/opt/homebrew/opt/openssl@3/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/
/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.

Destinasi Utama Belajar Online dengan Format Tulisan yang Elegan
Kunjungi Sekarang