PHP GD bundled extension without recompiling PHP - solution
Asked Answered
K

2

6

The bundled extension offer a lot of functionality. I have spent a lot of time how to compile extension for my version of PHP. So there are instructions.

Kingbolt answered 22/2, 2016 at 17:33 Comment(0)
K
16

0, Install PHP development package. Also You should have installed PHP with GD extension (but not bundled)

sudo apt-get install php5-dev

1, Download source code of used PHP (for me 5.6.18)

wget http://cz2.php.net/get/php-5.6.18.tar.gz/from/this/mirror -O php-5.6.18.tar.gz

2, Extract archive

tar -xzf php-5.6.18.tar.gz

3, Go to the source code of GD extension

cd php-5.6.18/ext/gd/

4, Prepare the extension (run phpize in that directory)

phpize

5, Now the configure command

5.1, The arguments depends on Your linux distribution. My was these:

--with-freetype-dir=shared,/usr --with-vpx-dir=shared,/usr --with-jpeg-dir=shared,/usr --with-xpm-dir=shared,/usr/X11R6

5.2, For getting paths for libraries You must run this command and search only the search arguments, which are specified above (5.1)

php-config --configure-options

5.3, Also add this arguments for configure (the second argument makes bundled version)

--with-php-config=/usr/bin/php-config --with-gd 

6, Final configure command

sudo ./configure --with-php-config=/usr/bin/php-config --with-gd --with-freetype-dir=YOUR_VALUE --with-vpx-dir=YOUR_VALUE --with-jpeg-dir=YOUR_VALUE --with-xpm-dir=YOUR_VALUE

7, Now run make

make

8, After compiling You should see something like this:

Libraries have been installed in:
   /home/jakub/php-5.6.18/ext/gd/modules

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'.

So in the directory modules You have compiled bundled extension gd.so. 9, Replace NOT bundled gd.so by Your new compiled bundled extension, for my version of PHP It was command:

sudo cp -f ./gd.so /usr/lib/php5/20131226/gd.so

10, Restart Apache

sudo service apache2 restart

Hope this helps! and will You spend less time than me.

Kingbolt answered 22/2, 2016 at 17:33 Comment(1)
Thank you @Kingbolt ! Worked like a charm on ubuntu 16.04 with libpng 12 and 16 both installed :)Monolith
H
0

Another way:

  1. Go to rpmfind.net and search php-gd-bundled for you php version.
  2. Extract rpm (rpm2cpio archive_name.rpm | cpio -idmv)
  3. Backup your gd.so and then copy gd.so from archive to you php lib directory.

Also I could compile a module with the following parameters:

#! /bin/sh
#
# Created by configure

'./configure' \
'--with-php-config=/usr/bin/php-config' \
'--with-gd=shared' \
'--with-freetype-dir=/usr' \
'--with-vpx-dir=/usr' \
'--with-jpeg-dir=/usr' \
'--with-xpm-dir=/usr' \
'--with-png-dir=/usr' \
'--with-t1lib=/usr' \
'--enable-gd-native-ttf' \
"$@"
Homebody answered 24/4, 2016 at 22:31 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.