Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to install swoole in windows machine?

I have installed Laravel 5 with php7 and which is working perfectly on my Windows machine. Recently I came to know that SWOOLE is a promising tool for PHP developers!

Unfortunately, I couldn't find any SWOOLE installers for windows.

Isn't it possible to install SWOOLE on a Windows machine, if so how?

Thanks in advance.

like image 991
Sumithran Avatar asked Jul 01 '18 11:07

Sumithran


4 Answers

Not directly, but with Docker and WSL (Windows Subsystem for Linux).

  1. Install Docker (https://www.docker.com/products/docker-desktop)
  2. Setup WSL

Open PowerShell as Administrator and run

Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux

Updating/Install the WSL 2 Linux kernel (https://learn.microsoft.com/en-us/windows/wsl/wsl2-kernel)

  1. Enable "Enable the experimental WSL 2 based engine" in Docker (General)
  2. Build the Docker container

IMPORTANT! Don't use a path with spacebars like:

  • C:\Users\ {FIRSTNAME}[SPACEBAR]{LASTNAME}\Desktop\docker)

Create a folder (D:\docker) and create with an Editor the Dockerfile (D:\docker\Dockerfile)

FROM php:7.4.2-cli

RUN apt-get update && apt-get install vim -y && \
    apt-get install openssl -y && \
    apt-get install libssl-dev -y && \
    apt-get install wget -y && \
    apt-get install git -y && \
    apt-get install procps -y && \
    apt-get install htop -y

RUN cd /tmp && git clone https://github.com/swoole/swoole-src.git && \
    cd swoole-src && \
    git checkout v4.4.15 && \
    phpize  && \
    ./configure  --enable-openssl && \
    make && make install

RUN touch /usr/local/etc/php/conf.d/swoole.ini && \
    echo 'extension=swoole.so' > /usr/local/etc/php/conf.d/swoole.ini

RUN wget -O /usr/local/bin/dumb-init https://github.com/Yelp/dumb-init/releases/download/v1.2.2/dumb-init_1.2.2_amd64
RUN chmod +x /usr/local/bin/dumb-init

RUN apt-get autoremove -y && rm -rf /var/lib/apt/lists/*

ENTRYPOINT ["/usr/local/bin/dumb-init", "--", "php"]

Open PowerShell navigate to your folder (D:\docker) to build the DockerImage

docker build -f ./Dockerfile -t swoole-php .
  1. Add your swoole source code

As an example (D:\docker\server.php)

<?php
$http = new Swoole\HTTP\Server("0.0.0.0", 9501);

$http->on('start', function ($server) {
    echo "Swoole http server is started at http://127.0.0.1:9501\n";
});

$http->on('request', function ($request, $response) {
    $response->header("Content-Type", "text/plain");
    $response->end("Hello World\n");
});

$http->start();
?>
  1. Start your swoole http server with the PowerShell
docker run --rm -p 9501:9501 -v D:/docker/:/app -w /app swoole-php server.php
like image 168
Kevin S. R. Schulz Avatar answered Oct 14 '22 03:10

Kevin S. R. Schulz


No.For now swoole is only supported for linux and Mac.

like image 22
Salman Zafar Avatar answered Oct 14 '22 02:10

Salman Zafar


I think you are looking for Cygwin and a tutorial how to use it with Swoole

UPDATE June 2020

you can also use Microsoft Windows Subsystem for Linux (WSL)

like image 38
Secret Keeper Avatar answered Oct 14 '22 04:10

Secret Keeper


For now, swool is only supported for Linux and Mac.but use Cygwin

follow this link

like image 39
kero Avatar answered Oct 14 '22 03:10

kero