使用phpize建立php扩展 Cannot find config.m4

简介:

下面我来讲讲如何作一个php的扩展

  首先要有一个搭建好的php环境

  我把php的安装在了/usr/local/php当然也通过

  php的一个配置php.ini的路径但是要注意了

  用这种方法安装的php扩展不能实现

  我们在php安装以后的/usr/local/php/bin目录

  找到这个文件phpize稍后我们将用到他

  他就是个shell脚本你可以用vi phpize来查看他的内容

  但是你要注意了这个脚本不是在哪里都可以应用的

  [root@ns root]# phpize

  Cannot find config.m4.

  Make sure that you run /usr/local/bin/phpize in the top level source directory of the module

  [root@ns root]# phpize

  Cannot find config.m4.

  Make sure that you run /usr/local/bin/phpize in the top level source directory of the module

  你会看到这两种结果实际上你查看了这个脚本

  很轻松的就会发现是怎么来处理的

  你的模扩展的时候最好

  放在/usr/local/php/php-5.3.28/ext下

  来执行他你在这里也可以这样/usr/local/php/bin/phpize来执行也可以

  phpize来执行

  我们在/usr/local/php/php-5.3.28/ext下找到这个工具

  来建立一个php扩展的一个框架

  [root@ns ext]#cd /usr/local/php/php-5.3.28/ext/

  [root@ns ext]# ./ext_skel --extname=sdomain

  Creating directory sdomain

  Creating basic files: config.m4 .cvsignore sdomain.c php_sdomain.h CREDITS EXPERIMENTAL tests/001.phpt sdomain.php [done].

To use your new extension, you will have to execute the following steps:

  1. $ cd ..

  2. $ vi ext/sdomain/config.m4

  3. $ ./buildconf

  4. $ ./configure --[with|enable]-sdomain

  5. $ make

  6. $ ./php -f ext/sdomain/sdomain.php

  7. $ vi ext/sdomain/sdomain.c

  8. $ make

  Repeat steps 3-6 until you are satisfied with ext/sdomain/config.m4 and

  step 6 confirms that your module is compiled into PHP. Then, start writing

  code and repeat the last two steps as often as necessary.

    执行了这个步骤以后你会看到这样的结果


  这样以后我们会在这个目录下生成一个目录叫sdomain

  进入这里面我们看看

  [root@ns ext]# cd sdomain/

  [root@ns sdomain]# ls

  config.m4 EXPERIMENTAL     sdomain.php  tests

  CREDITS  sdomain.c php_sdomain.h

  然后我们要修改文件顺序是

  configue.m4

  sdomain.c

  php_sdomain.h

  使用文本编辑器打开config.m4文件,文件内容大致如下:

  dnl $Id$d

  dnl config.m4 for extension my_module

  dnl dont forget to call PHP_EXTENSION(my_module)

  dnl Comments in this file start with the string dnl.

  dnl Remove where necessary. This file will not work

  dnl without editing.

dnl If your extension references something external, use with:

  dnl PHP_ARG_WITH(my_module, for my_module support,

  dnl Make sure that the comment is aligned:

  dnl [ --with-my_module       Include my_module support])

  dnl Otherwise use enable:

  dnl PHP_ARG_ENABLE(my_module, whether to enable my_module support,

  dnl Make sure that the comment is aligned:

  dnl [ --enable-my_module      Enable my_module support])

  if test $PHP_MY_MODULE != no; then

  dnl If you will not be testing anything external, like existence of

  dnl headers, libraries or functions in them, just uncomment the

  dnl following line and you are ready to go.

  dnl Write more examples of tests here...

  PHP_EXTENSION(my_module, $ext_shared)

  Fi

  根据你自己的选择将

  dnl PHP_ARG_WITH(my_module, for my_module support,

  dnl Make sure that the comment is aligned:

  dnl [ --with-my_module       Include my_module support])

  修改成

  PHP_ARG_WITH(my_module, for my_module support,

  [ --with-my_module       Include my_module support])

  或者将

  dnl PHP_ARG_ENABLE(my_module, whether to enable my_module support,

  dnl Make sure that the comment is aligned:

  dnl [ --enable-my_module      Enable my_module support])

修改成

  PHP_ARG_ENABLE(my_module, whether to enable my_module support,

  [ --enable-my_module      Enable my_module support])

        (其实就是将这部分的dnl去掉,在这个文件里dnl就是注释的意思,相当于我们PHP里面的#或// 另外把他中间的一句描术也去掉)

  我这里用了后者

  然后保存退出

  然后在编辑

  Vi my_module.c

  将文件其中的下列代码进行修改

/* Every user visible function must have an entry in my_module_functions[].
*/
function_entry my_module_functions[] = {
PHP_FE(say_hello,    NULL) /* ?添加着一行代码 */
PHP_FE(confirm_my_module_compiled,   NULL) /* For testing, remove later. */
{NULL, NULL, NULL}   /* Must be the last line in my_module_functions[] */
};

  在文件的最后添加下列代码

PHP_FUNCTION(say_hello)
{
zend_printf("hello sdomain!");
}

再修改:php_sdomain.h

vi php_sdomain.h

在PHP_FUNCTION(confirm_my_module_compiled ); /* For testing, remove later. */ 这行的下面添加一行:

PHP_FUNCTION(say_hello); /* For testing, remove later. */

  保存文件退出

  然后我们就可以在这个目录下使用上面的命令了

  /usr/local/php/bin/phpize

  执行以后会看到下面的

  [root@ns sdomain]# /usr/local/php/bin/phpize

  Configuring for:

  PHP Api Version:     20020918

  Zend Module Api No:   20020429

  Zend Extension Api No:  20050606

  [root@ns sdomain]#

  然后执行./configure --with-php-config=/usr/local/php/bin/php-config

  然后执行make

     make install

        然后他会把对应的so文件生成放到PHP安装目录下面的一个文件夹,并提示在在什么地方,然后再把里面的SO文件拷到你存放SO文件的地方

  即你在php.ini里面的extension_dir所指定的位置

  最后一步是你在php.ini文件中打开这个扩展

  extension=sdomain.so

  然后

  重新起动apache

  用phpinfo来察看一下ok了

 

本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/sdomain/archive/2009/09/04/4520425.aspx

本文转自奔跑在路上博客51CTO博客,原文链接http://blog.51cto.com/qiangsh/1551038如需转载请自行联系原作者


qianghong000

相关文章
|
5月前
|
运维 Unix Linux
Linux系统 PHP安装expect扩展详解
Linux系统 PHP安装expect扩展详解
79 5
|
9天前
|
设计模式 算法 数据库连接
PHP中的设计模式:提高代码的可维护性与扩展性本文旨在探讨PHP中常见的设计模式及其应用,帮助开发者编写出更加灵活、可维护和易于扩展的代码。通过深入浅出的解释和实例演示,我们将了解如何使用设计模式解决实际开发中的问题,并提升代码质量。
在软件开发过程中,设计模式是一套经过验证的解决方案模板,用于处理常见的软件设计问题。PHP作为流行的服务器端脚本语言,也有其特定的设计模式应用。本文将重点介绍几种PHP中常用的设计模式,包括单例模式、工厂模式和策略模式,并通过实际代码示例展示它们的具体用法。同时,我们还将讨论如何在实际项目中合理选择和应用这些设计模式,以提升代码的可维护性和扩展性。
|
7天前
|
设计模式 存储 算法
PHP中的设计模式:策略模式的深入解析与应用在软件开发的浩瀚海洋中,PHP以其独特的魅力和强大的功能吸引了无数开发者。作为一门历史悠久且广泛应用的编程语言,PHP不仅拥有丰富的内置函数和扩展库,还支持面向对象编程(OOP),为开发者提供了灵活而强大的工具集。在PHP的众多特性中,设计模式的应用尤为引人注目,它们如同精雕细琢的宝石,镶嵌在代码的肌理之中,让程序更加优雅、高效且易于维护。今天,我们就来深入探讨PHP中使用频率颇高的一种设计模式——策略模式。
本文旨在深入探讨PHP中的策略模式,从定义到实现,再到应用场景,全面剖析其在PHP编程中的应用价值。策略模式作为一种行为型设计模式,允许在运行时根据不同情况选择不同的算法或行为,极大地提高了代码的灵活性和可维护性。通过实例分析,本文将展示如何在PHP项目中有效利用策略模式来解决实际问题,并提升代码质量。
|
2月前
|
安全 前端开发 PHP
PHP与现代Web开发:构建高效和可扩展的应用程序
【8月更文挑战第29天】在这篇文章中,我们将深入探讨PHP如何适应现代Web开发的需求。我们将通过实际案例分析,揭示PHP的核心优势,并展示如何利用这些优势来构建高性能、可扩展的Web应用。文章不仅提供理论知识,还包括具体的代码示例,旨在帮助开发者更好地理解和运用PHP解决实际问题。
|
2月前
|
SQL 关系型数据库 MySQL
PHP与数据库交互的艺术:深入探讨PDO扩展
【8月更文挑战第28天】在数字信息时代的海洋里,PHP作为一艘灵活的帆船,承载着无数网站和应用的梦想。而PDO扩展,则是这艘帆船上不可或缺的导航仪,指引着数据安全与效率的航向。本文将带你领略PHP与数据库交互的艺术,深入浅出地探索PDO的世界,从连接数据库到执行复杂的查询,每一步都清晰可见。我们将一起航行在这段奇妙的旅程上,解锁数据的奥秘,体验编程的乐趣。
15 1
|
2月前
|
PHP Windows
【Azure App Service for Windows】 PHP应用出现500 : The page cannot be displayed because an internal server error has occurred. 错误
【Azure App Service for Windows】 PHP应用出现500 : The page cannot be displayed because an internal server error has occurred. 错误
|
2月前
|
存储 安全 Linux
【Azure 应用服务】App Service For Linux 怎么安装Composer,怎么安装PHP扩展,怎么来修改站点根路径启动程序?
【Azure 应用服务】App Service For Linux 怎么安装Composer,怎么安装PHP扩展,怎么来修改站点根路径启动程序?
|
3月前
|
运维 Serverless API
函数计算产品使用问题之如何使用PHP Runtime非内置扩展
阿里云Serverless 应用引擎(SAE)提供了完整的微服务应用生命周期管理能力,包括应用部署、服务治理、开发运维、资源管理等功能,并通过扩展功能支持多环境管理、API Gateway、事件驱动等高级应用场景,帮助企业快速构建、部署、运维和扩展微服务架构,实现Serverless化的应用部署与运维模式。以下是对SAE产品使用合集的概述,包括应用管理、服务治理、开发运维、资源管理等方面。
|
4月前
|
Ubuntu 中间件 Linux
linux php添加扩展zip libzip ZipArchive功能
linux php添加扩展zip libzip ZipArchive功能
127 1
|
4月前
|
PHP
php 使用phpize报错Cannot find config.m4. Make sure that you run ‘/usr/bin/phpize‘ in the top l
php 使用phpize报错Cannot find config.m4. Make sure that you run ‘/usr/bin/phpize‘ in the top l
182 1
下一篇
无影云桌面