Minggu, 28 Oktober 2018

How to compile and install php extension from source centos 6

  Tidak ada komentar
Enter to your php source directory
[root@cloud sites-enabled]# cd ~/php-5.5.17
[root@cloud php-5.5.17]# ls
acinclude.m4      footer              Makefile.gcov        README.GIT-RULES                  run-tests.php
aclocal.m4        generated_lists     Makefile.global      README.input_filter               sapi
build             genfiles            Makefile.objects     README.MAILINGLIST_RULES          scripts
buildconf         header              makerpm              README.md                         server-tests-config.php
buildconf.bat     include             missing              README.namespaces                 server-tests.php
buildmk.stamp     INSTALL             mkinstalldirs        README.NEW-OUTPUT-API             snapshot
CODING_STANDARDS  install-sh          modules              README.PARAMETER_PARSING_API      stamp-h.in
config.guess      libphp5.la          netware              README.PHP4-TO-PHP5-THIN-CHANGES  stub.c
config.log        libs                NEWS                 README.REDIST.BINS                svnclean.bat
config.nice       libtool             pear                 README.RELEASE_PROCESS            tests
config.status     LICENSE             php5.spec            README.SELF-CONTAINED-EXTENSIONS  travis
config.sub        ltmain.sh           php5.spec.in         README.STREAMS                    TSRM
configure         main                php.gif              README.SUBMITTING_PATCH           UPGRADING
configure.in      makedist            php.ini-development  README.TESTING                    UPGRADING.INTERNALS
CREDITS           Makefile            php.ini-production   README.TESTING2                   vcsclean
ext               Makefile.frag       README.EXTENSIONS    README.UNIX-BUILD-SYSTEM          win32
EXTENSIONS        Makefile.fragments  README.EXT_SKEL      README.WIN32-BUILD-SYSTEM         Zend
[root@cloud php-5.5.17]#

Enter to extension directory
[root@cloud php-5.5.17]# cd ext/
[root@cloud ext]# ls
bcmath      dom                 ftp        intl      mysqli   pdo           pgsql       shmop      standard   xml
bz2         enchant             gd         json      mysqlnd  pdo_dblib     phar        simplexml  sybase_ct  xmlreader
calendar    ereg                gettext    ldap      oci8     pdo_firebird  posix       skeleton   sysvmsg    xmlrpc
com_dotnet  exif                gmp        libxml    odbc     pdo_mysql     pspell      snmp       sysvsem    xmlwriter
ctype       ext_skel            hash       mbstring  opcache  pdo_oci       readline    soap       sysvshm    xsl
curl        ext_skel_win32.php  iconv      mcrypt    openssl  pdo_odbc      recode      sockets    tidy       zip
date        fileinfo            imap       mssql     pcntl    pdo_pgsql     reflection  spl        tokenizer  zlib
dba         filter              interbase  mysql     pcre     pdo_sqlite    session     sqlite3    wddx
[root@cloud ext]# 

Enter to extension directory that you want to install 
[root@cloud ext]# cd mcrypt/
[root@cloud mcrypt]# ls
config.m4   CREDITS   mcrypt.dsp       mcrypt_filter.lo  php_mcrypt_filter.h  tests
config.w32  mcrypt.c  mcrypt_filter.c  mcrypt.lo         php_mcrypt.h         TODO
[root@cloud mcrypt]#

Execute phpize
[root@cloud mcrypt]# phpize
Configuring for:
PHP Api Version:         20121113
Zend Module Api No:      20121212
Zend Extension Api No:   220121212
[root@cloud mcrypt]# ls
acinclude.m4    config.guess  configure     install-sh       mcrypt.dsp        missing              run-tests.php
aclocal.m4      config.h.in   configure.in  ltmain.sh        mcrypt_filter.c   mkinstalldirs        tests
autom4te.cache  config.m4     config.w32    Makefile.global  mcrypt_filter.lo  php_mcrypt_filter.h  TODO
build           config.sub    CREDITS       mcrypt.c         mcrypt.lo         php_mcrypt.h
[root@cloud mcrypt]#

Running configure on chosen extension directory
[root@cloud mcrypt]# ./configure
checking for grep that handles long lines and -e... /bin/grep
checking for egrep... /bin/grep -E
checking for a sed that does not truncate output... /bin/sed
checking for cc... cc
checking for C compiler default output file name... a.out
checking whether the C compiler works... yes
checking whether we are cross compiling... no
checking for suffix of executables...
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether cc accepts -g... yes
checking for cc option to accept ISO C89... none needed
checking how to run the C preprocessor... cc -E
checking for icc... no
checking for suncc... no
checking whether cc understands -c and -o together... yes
checking for system library directory... lib
checking if compiler supports -R... no
checking if compiler supports -Wl,-rpath,... yes
checking build system type... x86_64-unknown-linux-gnu
checking host system type... x86_64-unknown-linux-gnu
checking target system type... x86_64-unknown-linux-gnu
checking for PHP prefix... /usr/local/php5
checking for PHP includes... -I/usr/local/php5/include/php -I/usr/local/php5/include/php/main -I/usr/local/php5/include/php/TSRM -I/usr/local/php5/include/php/Zend -I/usr/local/php5/include/php/ext -I/usr/local/php5/include/php/ext/date/lib
checking for PHP extension directory... /usr/local/php5/lib/php/extensions/no-debug-non-zts-20121212
checking for PHP installed headers prefix... /usr/local/php5/include/php
checking if debug is enabled... no
checking if zts is enabled... no
checking for re2c... re2c
checking for re2c version... 0.13.5 (ok)
checking for gawk... gawk
checking for mcrypt support... yes, shared
checking for libmcrypt version... >= 2.5.6
checking for mcrypt_module_open in -lmcrypt... no
checking for mcrypt_module_open in -lmcrypt... yes
checking for ld used by cc... /usr/bin/ld
checking if the linker (/usr/bin/ld) is GNU ld... yes
checking for /usr/bin/ld option to reload object files... -r
checking for BSD-compatible nm... /usr/bin/nm -B
checking whether ln -s works... yes
checking how to recognize dependent libraries... pass_all
checking for ANSI C header files... yes
checking for sys/types.h... yes
checking for sys/stat.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for memory.h... yes
checking for strings.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for unistd.h... yes
checking dlfcn.h usability... yes
checking dlfcn.h presence... yes
checking for dlfcn.h... yes
checking the maximum length of command line arguments... 1966080
checking command to parse /usr/bin/nm -B output from cc object... ok
checking for objdir... .libs
checking for ar... ar
checking for ranlib... ranlib
checking for strip... strip
checking if cc supports -fno-rtti -fno-exceptions... no
checking for cc option to produce PIC... -fPIC
checking if cc PIC flag -fPIC works... yes
checking if cc static flag -static works... no
checking if cc supports -c -o file.o... yes
checking whether the cc linker (/usr/bin/ld -m elf_x86_64) supports shared libraries... yes
checking whether -lc should be explicitly linked in... no
checking dynamic linker characteristics... GNU/Linux ld.so
checking how to hardcode library paths into programs... immediate
checking whether stripping libraries is possible... yes
checking if libtool supports shared libraries... yes
checking whether to build shared libraries... yes
checking whether to build static libraries... no

creating libtool
appending configuration tag "CXX" to libtool
configure: creating ./config.status
config.status: creating config.h
[root@cloud mcrypt]#
Compile the extension
[root@cloud mcrypt]# make
/bin/sh /root/php-5.5.17/ext/mcrypt/libtool --mode=link cc -DPHP_ATOM_INC -I/root/php-5.5.17/ext/mcrypt/include -I/root/php-5.5.17/ext/mcrypt/main -I/root/php-5.5.17/ext/mcrypt -I/usr/local/php5/include/php -I/usr/local/php5/include/php/main -I/usr/local/php5/include/php/TSRM -I/usr/local/php5/include/php/Zend -I/usr/local/php5/include/php/ext -I/usr/local/php5/include/php/ext/date/lib  -DHAVE_CONFIG_H  -g -O2   -o mcrypt.la -export-dynamic -avoid-version -prefer-pic -module -rpath /root/php-5.5.17/ext/mcrypt/modules  mcrypt.lo mcrypt_filter.lo -lmcrypt
cc -shared  .libs/mcrypt.o .libs/mcrypt_filter.o  -lmcrypt  -Wl,-soname -Wl,mcrypt.so -o .libs/mcrypt.so
creating mcrypt.la
(cd .libs && rm -f mcrypt.la && ln -s ../mcrypt.la mcrypt.la)
/bin/sh /root/php-5.5.17/ext/mcrypt/libtool --mode=install cp ./mcrypt.la /root/php-5.5.17/ext/mcrypt/modules
cp ./.libs/mcrypt.so /root/php-5.5.17/ext/mcrypt/modules/mcrypt.so
cp ./.libs/mcrypt.lai /root/php-5.5.17/ext/mcrypt/modules/mcrypt.la
PATH="$PATH:/sbin" ldconfig -n /root/php-5.5.17/ext/mcrypt/modules
Libraries have been installed in:

If you ever happen to want to link against installed libraries
in a given directory, LIBDIR, you must either use libtool, and
specify the full pathname of the library, or use the `-LLIBDIR'
flag during linking and do at least one of the following:
   - add LIBDIR to the `LD_LIBRARY_PATH' environment variable
     during execution
   - add LIBDIR to the `LD_RUN_PATH' environment variable
     during linking
   - use the `-Wl,--rpath -Wl,LIBDIR' linker flag
   - have your system administrator add LIBDIR to `/etc/ld.so.conf'

See any operating system documentation about shared libraries for
more information, such as the ld(1) and ld.so(8) manual pages.

Build complete.
Don't forget to run 'make test'.

[root@cloud mcrypt]#
Install the extension and check the extension.so created successfully or not
[root@cloud mcrypt]# make install
Installing shared extensions:     /usr/local/php5/lib/php/extensions/no-debug-non-zts-20121212/
[root@cloud mcrypt]#
[root@cloud mcrypt]# ls /usr/local/php5/lib/php/extensions/no-debug-non-zts-20121212/
mcrypt.so  opcache.a  opcache.so  pdo.so
[root@cloud mcrypt]#

Edit your PHP.INI

The extension is ready to be included -- now we need to change the php.ini file to load that particular extension. First, find out which php.ini your system is using (note: the CLI may load a different config than the php-fpm or the Apache module one, a phpinfo() in your application would tell you for certain).
[root@cloud ~]# php -i | grep 'Configuration File'
Configuration File (php.ini) Path => /usr/local/php5/etc
Loaded Configuration File => /usr/local/php5/etc/php.ini
In the example above, we use /etc/php.ini as our base php.ini file.
[root@cloud ~]# vi /usr/local/php5/etc/php.ini
Add the module you want to load. I usually add these at the very bottom, where my changes are. This is relative to the extension_dir directive you found above.

Restart your php

In case of Apache
$ /etc/init.d/httpd restart
$ /etc/init.d/apache2 restart
or php-fpm:
$ /etc/init.d/php-fpm restart
And it's as easy as that!

Tidak ada komentar :

Posting Komentar