一: 先编译php源码:
我的php源码解压后放在/home/vitas/php中
1:
./configure --prefix=/home/vitas/php/output/ --enable-fpm --enable-debug
2:
make && make install
安装时出现libiconv函数库未安装的问题,所以必须到
http://www.gnu.org/software/libiconv/下载安装最新版的libiconv的函数库。
./configure --prefix=/usr/local/iconv
make && make install
方法二:去除iconv模块也能正常编译php,如下:
編輯 Makefile 大約 77 行左右的地方:
EXTRA_LIBS = ..... -lcrypt
在最後加上 -liconv,例如:
EXTRA_LIBS = ..... -lcrypt -liconv
再检查php,指定 iconv的位置
./configure --prefix=/home/vitas/php --with-iconv=/usr/local/libiconv
再运行make&&make install 安装就可以了。
方法三
修改这个文件,添加一行,将路径改为正确的路径
vim ./ext/iconv/iconv.c
#ifdef HAVE_ICONV
#define PHP_ICONV_H_PATH </usr/local/include/iconv.h>
#ifdef PHP_ICONV_H_PATH
二:使用ext_skel生成helloworld扩展
进入/home/vitas/php/ext中,就能找到ext_skel
1: ./ext_skel --extname=helloworld
执行完成后ext文件夹下会出现一个helloworld文件夹
2:执行phpize
3:配置好php-config的路径
./configure -with-php-config=/home/vitas/php/output/bin/php-config
4:make &&make install
生成的扩展所在的路径:
/home/vitas/php/output/lib/php/extensions/debug-non-zts-20160303/helloworld.so
php生成php.ini文件
/home/vitas/php/output/bin/php --ini
生成
root@ubuntu:/home/vitas/php/output/bin# ./php --ini
Configuration File (php.ini) Path: /home/vitas/php/output/lib
Loaded Configuration File: /home/vitas/php/output/lib/php.ini
Scan for additional .ini files in: (none)
Additional .ini files parsed: (none)
在php.ini配置生成的helloworld.so文件
……………………
extension = /home/vitas/php/output/lib/php/extensions/debug-non-zts-20160303/helloworld.so
……………………
然后使用 /home/vitas/php/output/bin/php -m命令,可以看到当前php版本配置的扩展
root@ubuntu:/home/vitas/php/output/bin# /home/vitas/php/output/bin/php -m
[PHP Modules]
Core
ctype
date
dom
fileinfo
filter
hash
helloworld
……………………………………
我们看到helloworld扩展已经成功加载进来了。
三:测试
进入新增的扩展文件夹,
cd /home/vitas/php/ext/helloworld
找到helloworld.php文件,这是新建扩展的时候自动生成的测试文件。
运行 ../../output/bin/php helloworld.php,出现
root@ubuntu:/home/vitas/php/ext/helloworld# ../../output/bin/php helloworld.php
Functions available in the test extension:
helloworld
Congratulations! You have successfully modified ext/helloworld/config.m4. Module helloworld is now compiled into PHP.
则扩展安装成功。