php - How to install SWOOLE in a Dockerfile for Laravel8/PHP8 project?
Solution:
...so I don't know why exactly, but it works for now. Maybe there where something wrong with my Node.JS installation above Swoole?!
Here is the for me working solution:
ENV NODE_VERSION=16.5
ENV NVM_DIR=/root/.nvm
RUN curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh | bash
RUN . "$NVM_DIR/nvm.sh" \
&& nvm install ${NODE_VERSION}
RUN . "$NVM_DIR/nvm.sh" \
&& nvm use v${NODE_VERSION}
RUN . "$NVM_DIR/nvm.sh" \
&& nvm alias default v${NODE_VERSION}
ENV PATH="/root/.nvm/versions/node/v${NODE_VERSION}/bin/:${PATH}"
RUN apt-get update \
&& apt-get install -y --no-install-recommends \
npm
RUN npm install -g yarn
RUN pecl channel-update https://pecl.php.net/channel.xml \
&& pecl install swoole
Answer
Solution:
It is a sample Dockerfile that uses the official PHP 8.0 (Debian) image and installs the Swoole through the PECL:
FROM php:8.0.12-cli-bullseye
# ...
RUN pecl install swoole
RUN docker-php-ext-enable swoole
It's also my complete Dockerfile:
FROM php:8.0.12-cli-bullseye
# Install system dependencies
RUN apt-get update && apt-get install -y \
curl \
libicu-dev \
libpng-dev \
libonig-dev \
libxml2-dev \
git \
cron \
zip \
unzip
# Clear cache
RUN apt-get clean && rm -rf /var/lib/apt/lists/*
# Install PHP extensions
RUN pecl install redis swoole
RUN docker-php-ext-install pdo_mysql exif pcntl bcmath gd intl soap
RUN docker-php-ext-enable redis swoole
RUN docker-php-ext-configure intl
RUN sed -i -e "s/upload_max_filesize = .*/upload_max_filesize = 1G/g" \
-e "s/post_max_size = .*/post_max_size = 1G/g" \
-e "s/memory_limit = .*/memory_limit = 512M/g" \
/usr/local/etc/php/php.ini-production \
&& cp /usr/local/etc/php/php.ini-production /usr/local/etc/php/php.ini
# Set working directory
WORKDIR /app
# Get latest Composer and install
COPY --from=composer:2.1.9 /usr/bin/composer /usr/bin/composer
Source