安装
要安装 Zephir, 请按照下列步骤操作:
基础要求
要构建PHP扩展并使用Zephir,您需要满足以下要求:
- Zephir parser >= 1.1.0
A C编译器,例如 gcc
sudo apt-get update
sudo apt-get install git gcc make re2c php php-json php-dev libpcre3-dev build-essential
请注意,阅读本指南时特定版本的库和程序可能有所不同。
由于Zephir代码的编写是在PHP中进行的,所以需要安装最新版本的PHP,并且必须在您的控制台中可用:
php -v
PHP 7.2.17-0ubuntu0.19.04.1 (cli) (built: Apr 18 2019 18:01:25) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
with Zend OPcache v7.2.17-0ubuntu0.19.04.1, Copyright (c) 1999-2018, by Zend Technologies
with Xdebug v2.6.1, Copyright (c) 2002-2018, by Derick Rethans
此外, 请确保您在安装 php 的同时安装了 php 开发库:
phpize -v
Configuring for:
PHP Api Version: 20170718
Zend Module Api No: 20170718
Zend Extension Api No: 320170718
您不必确切看到的以上输出,但是这些命令对于开始使用Zephir进行开发非常重要。
## 安装 Zephir
首先, 确保安装并激活了 Zephir 解析器扩展。 你可以按照这个 [tutorial](https://github.com/phalcon/php-zephir-parser)。
### Release PHAR
The recommended, **officially supported**, and easiest-to-use way to install Zephir is to simply grab the latest release PHAR [from GitHub](https://github.com/phalcon/zephir/releases/latest), and download/move it to somewhere in your `$PATH`. (You'll probably also want to rename it to drop the `.phar` extension, so you can run it as `zephir` instead of `zephir.phar`.)
### Composer
The PHAR isn't available before 0.11.4, so if you need an older version, you can use Composer, in one of two ways:
#### Global Composer Application
```bash
composer global require phalcon/zephir
```
There are two approaches to running Zephir at this point. The first is to ensure that `${COMPOSER_HOME}/vendor/bin` is in your `$PATH`, then Zephir should be available as `zephir` on the command line. The second is to simply use `composer global exec zephir` instead.
#### Project Dependency
```bash
composer require phalcon/zephir
```
Use `composer exec zephir` within the project you installed Zephir in, above, to run it. (Alternately, you can still run `vendor/bin/zephir`.)
### Git Clone
Finally, you can also simply clone the latest tag from GitHub, install the dependencies, and run Zephir from there:
```bash
git clone --depth 1 -b $(git ls-remote https://github.com/phalcon/zephir 0.11.* | sort -t/ -k3 -Vr | head -n1 | awk -F/ '{ print $NF }') https://github.com/phalcon/zephir
composer install
```
You'll need to either use the path to `zephir/zephir`, or create a symlink in a directory in your `$PATH`, to run Zephir using this option.
## 测试安装
检查Zephir是否可以从任何目录执行:
```bash
zephir list
```