PHP7 学习笔记(七)如何使用zephir编译一个扩展记录-阿里云开发者社区

开发者社区> 开发与运维> 正文

PHP7 学习笔记(七)如何使用zephir编译一个扩展记录

简介: 一、zephir 编译遇到的错误 安装 git clone https://github.com/phalcon/zephir $ cd zephir $ ./install-json $ ./install -c 编译 www@ubuntu4:~$ zephir build ────...

 一、zephir 编译遇到的错误

安装

git clone https://github.com/phalcon/zephir
$ cd zephir
$ ./install-json
$ ./install -c

编译

www@ubuntu4:~$ zephir build

────────────────────────────────────────────────────────────
  The Zephir Parser extension is not loaded.
  Note: Zephir no longer distributed with internal parser.
  
  To install latest stable Zephir Parser please refer to:
  https://github.com/phalcon/php-zephir-parser
────────────────────────────────────────────────────────────

二、php-zephir-parser 安装

git clone git://github.com/phalcon/php-zephir-parser.git

php7.0-dev 安装报错

www@ubuntu4:~$ sudo apt-get install php7.0-dev gcc make re2c autoconf
Reading package lists... Done
Building dependency tree       
Reading state information... Done
E: Unable to locate package php7.0-dev
E: Couldn't find any package by regex 'php7.0-dev'

如何让解决

1、php7的存储库的问题,添加php7 ppa

sudo add-apt-repository ppa:ondrej/php

2、更新库

sudo apt-get update

3、现在做一个搜索来确认php7是有的

sudo apt search php7

重新安装,则不会报错

www@ubuntu4:~$ sudo apt-get install php7.0-dev gcc make re2c autoconf
Reading package lists... Done
Building dependency tree       
Reading state information... Done
gcc is already the newest version.
gcc set to manually installed.
make is already the newest version.
re2c is already the newest version.
The following extra packages will be installed:
  automake autotools-dev debhelper dh-apparmor dh-php gettext intltool-debian
  libasprintf-dev libgettextpo-dev libgettextpo0 liblist-moreutils-perl
  libltdl-dev libmail-sendmail-perl libssl1.1 libsys-hostname-long-perl
  libtool libunistring0 m4 php-common php-pear php-xml php7.0-cli
  php7.0-common php7.0-json php7.0-opcache php7.0-readline php7.1-common
  php7.1-xml pkg-php-tools po-debconf shtool xml2

开始编译

www@ubuntu4:~/ffmpeg_videos/php-zephir-parser$ sudo ./install
Generating parser...
Parser statistics: 132 terminals, 99 nonterminals, 470 rules
                   982 states, 0 parser table entries, 0 conflicts
Configuring for:
PHP Api Version:         20151012
Zend Module Api No:      20151012
Zend Extension Api No:   320151012
libtool: compile:  gcc -I. -I/home/www/ffmpeg_videos/php-zephir-parser -DPHP_ATOM_INC -I/home/www/ffmpeg_videos/php-zephir-parser/include
-I/home/www/ffmpeg_videos/php-zephir-parser/main -I/home/www/ffmpeg_videos/php-zephir-parser -I/usr/include/php/20151012

-I/usr/include/php/20151012/main -I/usr/include/php/20151012/TSRM -I/usr/include/php/20151012/Zend -I/usr/include/php/20151012/ext

-I/usr/include/php/20151012/ext/date/lib -DHAVE_CONFIG_H -march=native -mtune=native -O2 -fomit-frame-pointer -fvisibility=hidden -flto
-c /home/www/ffmpeg_videos/php-zephir-parser/zephir_parser.c -fPIC -DPIC -o .libs/zephir_parser.o

或者指定编译配置文件

$./install --phpize /usr/local/php-7.1.11/bin/phpize --php-config /usr/local/php-7.1.11/bin/php-config

....

  

See any operating system documentation about shared libraries for
more information, such as the ld(1) and ld.so(8) manual pages.
----------------------------------------------------------------------

Build complete.
Don't forget to run 'make test'.

Installing shared extensions: /usr/local/php-7.1.11/lib/php/extensions/no-debug-non-zts-20160303/
Cleaning..

Thanks for compiling Zephir Parser!
Build succeed: Please restart your web server to complete the installation

编译完成

查找.so 文件路径

www@ubuntu4:~ sudo find / -name zephir_parser.so
/usr/lib/php/20151012/zephir_parser.so

配置php.ini 文件

sudo vim /opt/php-7.1.9/etc/php.ini

添加一下内容:

[Zephir Parser]
extension=/usr/lib/php/20151012/zephir_parser.so

安装完毕

三、重新编译,出现同样的错误:

www@ubuntu4:~/ffmpeg_videos/zephir-framework/lib$ zephir build

────────────────────────────────────────────────────────────
  The Zephir Parser extension is not loaded.
  Note: Zephir no longer distributed with internal parser.
  
  To install latest stable Zephir Parser please refer to:
  https://github.com/phalcon/php-zephir-parser
────────────────────────────────────────────────────────────

好纠结啊,如何解决:

直接系统自动默认安装的

rm /usr/bin/php

做个软连接

sudo ln -s /opt/php-7.0.9/bin/php /usr/bin/php

继续,Ok 了:

www@ubuntu4:~/ffmpeg_videos/zephir-framework/zephirlib$ zephir build
Compiling...
Installing...
Extension installed!
Add extension=zephirlib.so to your php.ini

 

编译PHP7 如何使用 Cli 命令而不是软连接

 

  • root用户,sudo vim /etc/profile

  • 添加PHP7编译的路径:export PATH=$PATH:/usr/local/php-7.1.8/bin,执行source profile使生效

 

版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。

分享:
开发与运维
使用钉钉扫一扫加入圈子
+ 订阅

集结各类场景实战经验,助你开发运维畅行无忧

其他文章