php 扩展编译c,PHP扩展编译 - Linland - OSCHINA - 中文开源技术交流社区

1.tar zxvf php-5.5.13.tar.gz

2.cd php-5.5.13

3.配置 编译选项

./configure --prefix=/usr/local/php \

--with-config-file-path=/etc \

--enable-opcache \

--enable-fpm \

--with-fpm-user=www \

--with-fpm-group=www \

--with-mysql=mysqlnd \

--with-mysqli=mysqlnd \

--with-pdo-mysql=mysqlnd \

--without-pdo-sqlite \

--without-sqlite3 \

--with-mysql-sock=/tmp/mysql.sock \

--with-curl \

--enable-mbstring \

--with-iconv \

--with-mhash \

--with-mcrypt \

--with-openssl \

--with-gd \

--enable-sockets \

--with-gettext \

--with-zlib \

--enable-zip \

--enable-soap \

--with-xmlrpc

www用户需要已存在

编译常见问题:

1.configure: error: xml2-config not found. Please check your libxml2 installation.

解决办法:安装libxml2-dev

2.configure: error: Please reinstall the BZip2 distribution

解决办法:安装bzip2-dev

3.configure: error: Please reinstall the libcurl distribution -easy.h should be in /include/curl/

解决办法:安装libcurl4-gnutls-dev

4.configure: error: jpeglib.h not found.

解决办法:安装libjpeg-dev

5.configure: error: png.h not found.

解决办法:安装libpng-dev

6.configure: error: libXpm.(a|so) not found.

解决办法:安装libxpm-dev

7.configure: error: freetype.h not found.

解决办法:安装libfreetype6-dev

8.configure: error: Your t1lib distribution is not installed correctly. Please reinstall it.

解决办法:安装libt1-dev

9.configure: error: mcrypt.h not found. Please reinstall libmcrypt.

解决办法:安装libmcrypt-dev

10.configure: error: Cannot find MySQL header files under yes.

Note that the MySQL client library is not bundled anymore!

解决办法:安装libmysql++-dev

11.configure: error: xslt-config not found. Please reinstall the libxslt >= 1.1.0 distribution

解决办法:安装libxslt1-dev

4.Make

5.make install

6.编译扩展模块

创建的模块为hello

1.cd /php5.5.13/ext/

2.执行./ext_skel --extname=hello,将在该目录生成 ~/php-5.5.13/ext/hello

3.编辑 config.m4文件,去掉第16行和第18行的注释(注释符号为dnl。)

16:  PHP_ARG_ENABLE(hello, whether to enable hello support,

17:  dnl Make sure that the comment is aligned:18:  [  --enable-hello           Enable hello support])

4.进入/hello目录,执行/usr/local/php/bin/phpize,生成configure文件

正常:

Configuring for: PHP Api Version:         20090626 Zend Module Api No:      20090626 Zend Extension Api No:   220090626

错误:

Configuring for: PHP Api Version:         20090626 Zend Module Api No:      20090626 Zend Extension Api No:   220090626 Cannot find autoconf. Please check your autoconf installation and the $PHP_AUTOCONF environment variable. Then, rerun this script.

解决办法:安装autoconf,再次执行phpize

5.修改php_hello.h,在 PHP_FUNCTION(confirm_hello_compiled); 之下加入函数声明

PHP_FUNCTION(nova_hello);

6.打开nova.c,在zend_function_entrynova_functions[]加入以下内容

constzend_function_entryhello_functions[]={

PHP_FE(confirm_hello_compiled, NULL)  /* For testing, remove later. */

PHP_FE(hello_hello, NULL)

PHP_FE_END /* Must be the last line in nova_functions[] */

};

然后在nova.c文件末尾添加nova_hello函数内容

PHP_FUNCTION(hello_hello){

longinta,b,c;

if(zend_parse_parameters(ZEND_NUM_ARGS()TSRMLS_CC,"ll",&a,&b)==FAILURE){

return;

}

c=a+b;

RETURN_LONG(c);

}

7.编译扩展模块,进入/php5.5.13/ext/hello/目录,执行

./configure --with-php-config=/usr/local/php/bin/php-config

Make

Make install

编译成功后,.so文件存放在

[root@localhost nova]# make install

Installingsharedextensions:   /usr/local/php/lib/php/extensions/no-debug-non-zts-20121212/

8.打开php.ini添加一行extension=hello.so

9.重启php-fpm,或者apache

10.检测是否成功加载

/usr/local/php/bin/php -m|grephello查看是否有hello.so

echohello_hello(1,2);

phpinfo();

?>

注意:

1.CLI模式下执行测试文件,最好加上php.ini文件

/usr/local/php/bin/php -c /etc/php.ini hello.php

2.PHP Warning:  PHP Startup: Unable to load dynamic library '/usr/local/lib/php/extensions/no-debug-non-zts-20121212/hello.so' - /usr/local/lib/php/extensions/no-debug-non-zts-20121212/hello.so: cannot open shared object file: No such file or directory in Unknown on line 0

解决办法:修改php.ini里extension_dir,添加/usr/local/lib/php/extensions/no-debug-non-zts-20121212/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值