Skip to content

Installation

To install Zephir, please follow these steps:

Prerequisites

Before building a PHP extension with Zephir, ensure you have the following requirements:

  • Zephir parser >= 1.3.0
  • A C compiler such as gcc >= 4.4 or an alternative such as clang >= 3.0, Visual C++ >= 11 or Intel C++. It is recommended to use gcc 4.4 or later
  • re2c 0.13.6 or later
  • PHP development headers and tools

For Linux based systems you'll need also: * GNU make 3.81 or later * autoconf 2.31 or later * automake 1.14 or later * libpcre3 * The build-essential package when using gcc on Ubuntu (and likely in other distributions as well)

On Ubuntu, you can install the required packages with:

sudo apt-get update
sudo apt-get install git gcc make re2c php php-json php-dev libpcre3-dev build-essential

Ensure you have a recent version of PHP installed and available in your console:

php -v
PHP 8.0.30 (cli) (built: Nov 21 2023 16:16:21) ( NTS )
Copyright (c) The PHP Group
Zend Engine v4.0.30, Copyright (c) Zend Technologies
    with Xdebug v3.3.1, Copyright (c) 2002-2023, by Derick Rethans

Additionally, check that the PHP development libraries are installed:

phpize -v
Configuring for:
PHP Api Version:         20200930
Zend Module Api No:      20200930
Zend Extension Api No:   420200930

You don't have to necessarily see the exact above output, but it's important that these commands are available to start developing with Zephir.

Installing Zephir

First make sure that the Zephir parser extension is installed and activated. You can find installation instructions in the Zephir Parser repository.

Composer

The recommended installation method is using composer:

composer require phalcon/zephir

Make sure that ${COMPOSER_HOME}/vendor/bin is in your $PATH, to have Zephir should be available as zephir on the command line.

Project

Use composer exec zephir within the project you installed Zephir in, above, to run it. (Alternately, you can still run vendor/bin/zephir.)

Global

For a global installation, you can use:

composer global require phalcon/zephir

Release PHAR

You can also download the latest release PHAR from GitHub. Place it in your $PATH and consider renaming it to zephir for convenience.

Git Clone

Clone the latest tag from GitHub, install dependencies, and run Zephir from there:

git clone --depth 1 -b $(git ls-remote https://github.com/zephir-lang/zephir 0.17.* | sort -t/ -k3 -Vr | head -n1 | awk -F/ '{ print $NF }') https://github.com/zephir-lang/zephir
composer install

Either use the path to zephir/zephir or create a symlink in a directory in your $PATH to run Zephir using this option.

Testing the Installation

Check if Zephir is available from any directory by executing:

zephir help