Prerequisites

General Requirements

  1. Linux, FreeBSD or MacOS (OS X), Cygwin, WSL
  2. Linux kernel version >= 2.3.32
  3. For Windows there is Docker and WSL (Windows Subsystem for Linux)
  4. PHP version >= 7.3.0
  5. GCC version >= 4.8

Recommend Linux version: Ubuntu 16, CentOS 7 or greater


PHP Version Dependency

  1. Swoole only supports PHP version >= 7.3.0, PHP 8.0+ is recommended
  2. Swoole doesn't depend on the PHP extensions like stream, sockets, pcntl, posix, sysvmsg, etc. You simply need to install the basic extensions for core PHP
  3. Swoole always aims to support the latest version of PHP, it is best to always make sure you have a supported version of PHP installed, check PHP Supported Versions to find out

Swoole supports PHP 8.0 and PHP JIT


Update your System

Before we start it is best to make sure your system has the latest updates and packages.

For Ubuntu/Debian this is easy, run the following commands:

#!/bin/bash
sudo apt-get update && sudo apt-get upgrade

For CentOS and RedHat systems etc. check online guides on how to update your OS.


Linux Systems Requirements

On Linux if you are installing Swoole via PECL or the PHP PPA Repository (Deb.Sury) or compiling, you will need the following requirements/packages below.

PHP Language Core

You should have PHP installed first, refer to the PHP manual for this; in general though PHP can be installed by compiling PHP directly or via your Unix like package installation system, for example on Ubuntu/Debian:

PHP via Default Package on System

#!/bin/bash

# Update your server
$ sudo apt-get update && sudo apt-get upgrade

# Install default PHP package
$ sudo apt-get install php

# Check installed version and info
$ php -v

PHP via Deb.Sury

#!/bin/bash

# Install the Deb.Sury PHP Ubuntu PPA source
sudo apt install software-properties-common
sudo add-apt-repository ppa:ondrej/php
sudo apt-get update

# Install a specific version of PHP
sudo apt install php7.4

PHP Installation Complete

When we check our PHP install with $ php -v you will see something like:

PHP 7.4.3 (cli) (built: Oct  6 2020 15:47:56) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
    with Zend OPcache v7.4.3, Copyright (c), by Zend Technologies

PECL & Compiling From Source

When using PHP PECL or cloning the Swoole source to compile manually, you will need to meet the following requirements on Linux:

#!/bin/bash

# Install the GCC Compiler
sudo apt install gcc

# Required for PECL installation and manual Swoole compilation
$ sudo apt install php-dev

# Main requirements for Swoole and useful packages
$ sudo apt install openssl
$ sudo apt install libssl-dev
$ sudo apt install curl
$ sudo apt install libcurl4-openssl-dev
$ sudo apt install libpcre3-dev
$ sudo apt install build-essential

PHP Extensions

If you plan on using CURL or MySQL with Swoole, you need to have the compatible PHP extensions installed as well, check the example below for which extensions you may need.

You should change the PHP version to what you have installed.

#!/bin/bash

# Recommended PHP Extensions
sudo apt install php7.4-curl \
                 php7.4-json \
                 php7.4-mysql \
                 php7.4-common

# Useful PHP Extensions
sudo apt install php7.4-bcmath \
                 php7.4-gd \
                 php7.4-intl \
                 php7.4-mbstring \
                 php7.4-opcache \
                 php7.4-xml \
                 php7.4-zip

Swoole from Deb.Sury Packages

When installing Swoole using the ondrej/php PPA, you can follow the main Linux Requirements. But make sure you install PHP first.

Then you can follow the installation documentation for using the Deb.Sury PPA to install Swoole.

MacOs

For MacOS you can use brew to install PHP and then follow along with the Linux Requirements.

Once you have all the general and linux dependencies you can then install Swoole on OS X systems.

After you have completed the prerequisites guide you can move onto installing Swoole