mac开发php扩展,Mac系统下的php扩展开发

本文详细阐述了如何在PHP开发中使用C语言编写扩展,包括下载、配置、编译及安装过程,适合开发者快速掌握C扩展的开发流程。

通常在开发PHP的时候,一些核心代码,比如加密函数或需要高效率执行的代码,此时可以用C语言写扩展。本文主要介绍了扩展的开发流程,具体的代码实现参考生成的文件说明。

当前PHP使用的是XAMPP 5.6.8,安装路径是:/Applications/XAMPP/。

1. 开始之前,从网站上下载php 5.6.8的扩展,下载地址:http://php.net/get/php-5.6.8.tar.bz2/from/a/mirror

2. 解压后进入ext目录,执行:./ext_skel --extname=test,会在ext目录下生成test目录,此目录下建立了扩展名称为test的开发框架

3. 进入test目录,编辑config.m4文件

将如下行的注释标签"dnl"去掉,修改后如下所示:

PHP_ARG_ENABLE(myfunctions, whether to enable myfunctions support,

Make sure that the comment is aligned:

[  --enable-myfunctions           Enable myfunctions support])

4. 使用phpize生成configure文件(phpize路径为:/Applications/XAMPP/xamppfiles/bin/phpize)

5. 执行命令:./configure --with-php-config=/Applications/XAMPP/xamppfiles/bin/php-config

6. 执行命令: make编译扩展

7. 执行命令:sudo make install 安装扩展

8. 修改php.ini文件(路径:/Applications/XAMPP/xamppfiles/etc/php.ini)

9. 重启apache,依次执行一下命令:

sudo /Applications/XAMPP/xamppfiles/apache2/scripts/ctl.sh stop

sudo /Applications/XAMPP/xamppfiles/apache2/scripts/ctl.sh start

原文:http://www.cnblogs.com/springwind2006/p/5876223.html

我安装laravel的一个扩展时,提示没有ZipArchive 我根据国外的一个网站的提示进行操作,任然不成功,后重新修改了这个包才成功 首先要执行下面操作 brew update brew install php@7.3 brew link php@7.3 然后执行 Step 1: Install PEAR/PECL support cd /tmp curl -s -O https://pear.php.net/install-pear-nozlib.phar sudo php install-pear-nozlib.phar -d /usr/local/lib/php -b /usr/local/bin (credit) Step 2: Download zip extension source I tried installing zip with pecl, but that failed because the PHP header files were missing. So I downloaded the source for the zip extension from pecl. Step 3:下载我提供的包文件 然后解压 Step 4: Copy/modify phpsize and php-config In order to make phpize and php-config find the PHP header files in the location that XCode places them rather than in /usr/include/php -- a read-only location now -- I followed some tips I found elsewhere and copied and modified phpize and php-config to change the include directory in each of them. cp /usr/bin/phpize /usr/local/bin/phpize cp /usr/bin/php-config /usr/local/bin/php-config Step 5: Build the zip PHP extension With all of those changes in place, I could now build the zip extension. cd zip-1.15.5 phpize ./configure -with-php-config=/usr/local/bin/php-config make Step 6: Install zip PHP extension make install fails to install the extension, again because of the read-only file system. So instead I created an extension directory under /usr/local/php. mkdir -p /usr/local/php/extensions cp modules/zip.so /usr/local/php/extensions/zip.so Step 7: Update your PHP.ini Finally we need to tell PHP to load this extension. sudo vim /etc/php.ini Add the following line: extension=/usr/local/php/extensions/zip.so Restart apache with sudo apachectl restart and you'll see the zip extension being loaded now.
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符  | 博主筛选后可见
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值