PHP扩展编译

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 <curl-dir>/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_entry nova_functions[]加入以下内容

const zend_function_entry hello_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){

long int a,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

Installing shared extensions:        /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|grep  hello查看是否有 hello.so

<?php

echo hello_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/


转载于:https://my.oschina.net/linland/blog/286392

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值