Install Swoole on Ubuntu 16.04

Ref: https://github.com/swoole/swoole-docs/blob/master/get-started/installation.md
Install from pecl

Then include the extension “extension=swoole.so” in php.ini file. For php-fpm, the php.ini file in “/etc/php/7.2/fpm/php.ini”

then add this new line:

Save then restart php7.2-fpm service

look it up phpinfo() result. It should show like this:Pls do the same thing for php cli. the php.ini file for php cli in “/etc/php/7.2/cli/php.ini”. So edit the file and add a new line for the extension “extension=swoole.so”. Check the extension is loaded on the terminal:

Note: I tried to do this via terminal

But it didn’t work. The extension is not loaded so I put it manually in the php.ini for cli.
NOTE: IT NEED TO DISABLE ‘xdebug’ EXTENSION. CHECK IF xdebug IS ACTIVE/ENABLED:

IF IT IS ENABLED, THEN MODIFY ‘/etc/php/7.2/cli/conf.d/20-xdebug.ini’ FILE TO DISABLE xdebug BY ADDING ‘;’ IN FRONT OF THE LINE LIKE THIS:

IF xdebug IS ENABLED WHEN THE SERVER IS RUNNING, IT’D SPIT THIS WARNING:

TEST SWOOLE
ref: https://github.com/swoole/swoole-docs/blob/master/get-started/examples/tcp_server.md
Create a new file server.php

Run the php in a terminal

then open another terminal and type ‘telnet 127.0.0.1 9501’

The first terminal would print ‘Client : Connect’

You can connect with another new terminal.
To close the connection in the second terminal, press Ctrl + ] then type close in telnet>

The first terminal would give response like this:

Create web server
ref: https://github.com/swoole/swoole-docs/blob/master/get-started/examples/http_server.md
create a new file ‘http_server.php’

then run the server via terminal

Open it via web browser: http://127.0.0.1:9503/
It should show this message:

 

Leave a Reply

Your email address will not be published. Required fields are marked *