How to Install and Set Up Zephir for High‑Performance PHP Extensions on Ubuntu

This guide introduces Zephir, outlines its key features and required dependencies, and provides step‑by‑step commands to install the Zephir parser, the php‑zephir‑parser extension, and Zephir itself on a Linux/Ubuntu system, finishing with PATH configuration.

Open Source Tech Hub
Open Source Tech Hub
Open Source Tech Hub
How to Install and Set Up Zephir for High‑Performance PHP Extensions on Ubuntu

Introduction

Zephir is an open‑source high‑level language designed to simplify the creation and maintenance of PHP extensions, emphasizing type safety and memory safety. It compiles to C code, which can be optimized by gcc, delivering strong performance while remaining easy to maintain.

Main Features

Type system: dynamic/static

Memory safety: no direct pointer or manual memory management

Compilation model: pre‑compilation

Memory model: task‑local garbage collection

Environment Dependencies

Zephir parser >= 1.3.0

re2c 0.13.6 or newer

automake 1.14 or newer

GNU make 3.81 or later

autoconf 2.31 or newer

Installation Steps

1. Basic System Packages

sudo apt-get update
sudo apt-get install git gcc make php php-json php-dev libpcre3-dev build-essential
If PHP is already compiled and installed, you can skip this step.

2. Install re2c

sudo apt install re2c

Verify the installed version:

$ re2c --version
re2c 1.0.1

3. Install php‑zephir‑parser

Clone, compile, and install the parser extension:

git clone https://github.com/zephir-lang/php-zephir-parser.git
cd php-zephir-parser
phpize
./configure --with-php-config=/usr/local/php-7.4/bin/php-config
make
sudo make install

Add the extension to php.ini:

sudo vim /usr/local/php-7.4/etc/php.ini
[Zephir Parser]
extension=zephir_parser.so

4. Install Zephir

Clone the latest Zephir source (selecting the newest 0.15.x tag) and install its PHP dependencies:

git clone --depth 1 -b $(git ls-remote https://github.com/zephir-lang/zephir 0.15.* | sort -t/ -k3 -Vr | head -n1 | awk -F/ '{print $NF}') https://github.com/zephir-lang/zephir
cd zephir
composer install
After installation, a binary named zephir is generated.

Check that the binary is reachable: zephir: command not found If not found, add its directory to the system PATH: sudo vim /etc/profile Append the following line: export PATH=$PATH:/home/www/build/zephir Apply the changes: source /etc/profile After configuration, the Zephir command should be executable from any location.

Congratulations, the installation is complete!

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

compilerzephirphp extensions
Open Source Tech Hub
Written by

Open Source Tech Hub

Sharing cutting-edge internet technologies and practical AI resources.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.