Tag Archives: php5.6.30

[Solved] Php5.6.30 environment error call to undefined function imagecreate() compile and install GD Library

php5.6.30 environment reports error Call to undefined function ImageCreate() compile and install gd library


Found that php5.6.30 does not load the gd library

[root@cn_vs_web04:/usr/local/php]# php -i |grep configure
Configure Command =>  './configure'  '--prefix=/usr/local/php-5.6.30_fpm' '--with-openssl=/usr/local/lab/openssl' '--with-libxml-dir=/usr' '--with-zlib-dir=/usr/local/lab/zlib-1.2.8' '--with-bz2' '--enable-calendar' '--with-curl=/usr/local/lab/curl-7.36.0' '--enable-dba' '--enable-exif' '--enable-ftp' '--with-jpeg-dir=/usr/local/lab/libjpeg-6b' '--with-png-dir=/usr/local/lab/libpng-1.6.10' '--with-freetype-dir=/usr/local/lab/freetype-2.5.4' '--with-gettext' '--enable-mbstring' '--with-ldap=/usr/local/openldap-2.4.23' '--with-mcrypt=/usr/local/lab/libmcrypt-2.5.8' '--with-mhash=/usr/local/lab/mhash-0.9.9.9' '--with-mysql=mysqlnd' '--with-mysqli=mysqlnd' '--with-pdo-mysql=mysqlnd' '--with-unixODBC=/usr/local/lab/unixODBC-2.3.2' '--with-pdo-dblib=/usr/local/lab/freetds-0.92' '--enable-zip' '--with-iconv-dir=/usr/local/lab/libiconv-1.14' '--with-fpm-user=apache' '--with-fpm-group=users' '--enable-fpm' '--with-xmlrpc' '--enable-soap' '--enable-mbregex' '--enable-opcache' '--enable-inline-optimization' '--enable-xml' '--enable-sockets' '--disable-debug

Solution:

The gd library was not compiled in during compilation, so it needs to be added again. Fortunately, the gd library is an extension library, so there is no need to recompile the whole php program.

1. Download php5.6.30 source code


Get the source code and decompress it
# wget https://www.php.net/distributions/php-5.6.30.tar.gz
# tar -zxf php-5.6.30.tar.gz
# cd php-5.6.30/ext/gd

Execute phpize in the source code directory
# /usr/local/php/bin/phpize

# Recompile
# ./configure --with-php-config=/usr/local/php/bin/php-config --with-gd
# make && make install

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

Installing shared extensions:     /usr/local/php-5.6.30_fpm/lib/php/extensions/no-debug-non-zts-20131226/
Installing header files:           /usr/local/php-5.6.30_fpm/include/php/

# Add the extensions library to the extensions folder

cp /usr/local/php-5.6.30_fpm/lib/php/extensions/no-debug-non-zts-20131226/ /usr/local/php/lib/php/extensions

Edit php.ini to add the gd.so extension library

# vim /usr/local/php/php.ini
extension_dir=/usr/local/php/lib/php/extensions
extension=gd.so

# restart php
/etc/init.d/php-fpm restart

# Validation
[root@cn_vs_web04:/usr/local/lab]# php -m|grep gd
gd


[root@cn_vs_web04:/usr/local/lab]# cat /etc/init.d/php-fpm 
#! /bin/sh

### BEGIN INIT INFO
# Provides:          php-fpm
# Required-Start:    $remote_fs $network
# Required-Stop:     $remote_fs $network
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: starts php-fpm
# Description:       starts the PHP FastCGI Process Manager daemon
### END INIT INFO

prefix=/usr/local/php
exec_prefix=${prefix}

php_fpm_BIN=${exec_prefix}/sbin/php-fpm
php_fpm_CONF=${prefix}/etc/php-fpm.conf
php_fpm_PID=${prefix}/var/run/php-fpm.pid


php_opts="--fpm-config $php_fpm_CONF --pid $php_fpm_PID"


wait_for_pid () {
    try=0

    while test $try -lt 35 ; do

        case "$1" in
            'created')
            if [ -f "$2" ] ; then
                try=''
                break
            fi
            ;;

            'removed')
            if [ ! -f "$2" ] ; then
                try=''
                break
            fi
            ;;
        esac

        echo -n .
        try=`expr $try + 1`
        sleep 1

    done

}

case "$1" in
    start)
        echo -n "Starting php-fpm "

        $php_fpm_BIN --daemonize $php_opts

        if [ "$?" != 0 ] ; then
            echo " failed"
            exit 1
        fi

        wait_for_pid created $php_fpm_PID

        if [ -n "$try" ] ; then
            echo " failed"
            exit 1
        else
            echo " done"
        fi
    ;;

    stop)
        echo -n "Gracefully shutting down php-fpm "

        if [ ! -r $php_fpm_PID ] ; then
            echo "warning, no pid file found - php-fpm is not running ?"
            exit 1
        fi

        kill -QUIT `cat $php_fpm_PID`

        wait_for_pid removed $php_fpm_PID

        if [ -n "$try" ] ; then
            echo " failed. Use force-quit"
            exit 1
        else
            echo " done"
        fi
    ;;

    force-quit)
        echo -n "Terminating php-fpm "

        if [ ! -r $php_fpm_PID ] ; then
            echo "warning, no pid file found - php-fpm is not running ?"
            exit 1
        fi

        kill -TERM `cat $php_fpm_PID`

        wait_for_pid removed $php_fpm_PID

        if [ -n "$try" ] ; then
            echo " failed"
            exit 1
        else
            echo " done"
        fi
    ;;

    restart)
        $0 stop
        $0 start
    ;;

    reload)

        echo -n "Reload service php-fpm "

        if [ ! -r $php_fpm_PID ] ; then
            echo "warning, no pid file found - php-fpm is not running ?"
            exit 1
        fi

        kill -USR2 `cat $php_fpm_PID`

        echo " done"
    ;;

    *)
        echo "Usage: $0 {start|stop|force-quit|restart|reload}"
        exit 1
    ;;

esac