아파치랑 PHP는 거창한 config 없이 그냥 설치만 한다고 가정.



Apache 2.2.16
PHP 5.2.14


1. 다운로드






2. 아파치 설치

tar xvfz httpd-2.2.16.tar.gz
cd http-2.2.16
./configure --prefix=/usr/local/apache --with-mpm=worker --enable-modules=so --enable-so --with-included-apr --enable-mods-shared=all
make
make install




3. PHP 설치

cd ..
tar xvfz php-5.2.14.tar.gz
cd php-5.2.14
./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache/bin/apxs
make
make install
cp php.ini-dist /usr/local/lib/php.ini




4. httpd.conf 수정

vi /usr/local/apache/conf/httpd.conf

아래 2라인 추가

AddType application/x-httpd-php .php .inc .php3 .html
AddType application/x-httpd-php-source .phps




5. extension 제작

cd ext
./ext_skel --extname=myext
cd myext

config.m4를 아래처럼 수정

config.m4
-----------------------------------------------------------------------

PHP_ARG_ENABLE(myext, whether to enable myext support,
[ --enable-myext    Enable myext support])

if test "$PHP_MYEXT" = "yes"; then
    AC_DEFINE(HAVE_MYEXT, 1, [Whether you have myext])
    PHP_NEW_EXTENSION(myext, myext.c, $ext_shared)
fi
-----------------------------------------------------------------------



php_myext.h를 아래처럼 수정

php_myext.h
-----------------------------------------------------------------------
#ifndef PHP_MYEXT_H
#define PHP_MYEXT_H 1

#define PHP_MYEXT_VERSION "1.0"
#define PHP_MYEXT_EXTNAME "myext"


PHP_FUNCTION(myext_test);

extern zend_module_entry myext_module_entry;
#define phpext_myext_ptr &myext_module_entry

#endif
-----------------------------------------------------------------------



myext.c를 아래처럼 수정

myext.c
-----------------------------------------------------------------------

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#include "php.h"
#include "php_myext.h"

static function_entry myext_functions[] = {
    PHP_FE(myext_test, NULL)
    {NULL, NULL, NULL}
};

zend_module_entry myext_module_entry = {
#if ZEND_MODULE_API_NO >= 20010901
    STANDARD_MODULE_HEADER,
#endif
    PHP_MYEXT_EXTNAME,
    myext_functions,
    NULL,
    NULL,
    NULL,
    NULL,
    NULL,
#if ZEND_MODULE_API_NO >= 20010901
    PHP_MYEXT_VERSION,
#endif
    STANDARD_MODULE_PROPERTIES
};

#ifdef COMPILE_DL_MYEXT
ZEND_GET_MODULE(myext)
#endif

PHP_FUNCTION(myext_test)
{
    RETURN_STRING("Hello World", 1);
}
-----------------------------------------------------------------------



phpize
./configure --with-php-config=/usr/local/php/bin/php-config --enable-myext
make
mkdir /usr/local/php/extensions
cp modules/myext.so /usr/local/php/extensions





6. php.ini 수정

vi /usr/local/lib/php.ini

php.ini
-----------------------------------------------------------------------
extension_dir 수정
extension_dir=/usr/local/php/extensions

extension 추가
extension=myext.so
-----------------------------------------------------------------------





7. 확인

/usr/local/apache/bin/apachectl start

1. phpinfo() 함수로 Additional Modules에 myext가 있는지 확인
2. myext_test() 함수를 실행해서 잘 동작하는지 확인



Posted by bloodguy
,