Using GD causes Apache Segmentation fault w/ PHP 4.3.9, Apache 2, RedHat AS

I have installed PHP 4.3.9 on RedHat AS with Apache 2. Any script that accesses gd related functions causes the httpd process to die with this error: [notice] child pid 30391 exit signal Segmentation fault (11). I have gd-1.8.4 and gd-devel-1.8.4 on the system but my understanding is that PHP comes bundled with its own version which it uses unless otherwise instructed during the build. The exact same config below works fine on our box running php-4.3.2, RedHat 7 with Apache 1.

Here is the config:
./configure
--with-apxs2=/usr/sbin/apxs
--with-mysql=/usr
--with-gd=/usr/
--with-jpeg-dir=/usr
--with-png-dir=/usr
--with-zlib-dir=/usr
--with-ttf
--with-pdflib=/usr/local
--with-mcrypt=/usr
--with-curl --with-openssl

Here is a sample script I used:
<?
header ("Content-type: image/png");
$im = @ImageCreate (50, 100)
    or die ("Cannot Initialize new GD image stream");
$background_color = ImageColorAllocate ($im, 255, 255, 255);
$text_color = ImageColorAllocate ($im, 233, 14, 91);
ImageString ($im, 1, 5, 5,  "A Simple Text String", $text_color);
ImagePng ($im);
?>

I tried building GD 2 from source and forcing PHP to compile against those headers under /usr/local/ but php make died with some errors related to undefined gd* functions. If it matters, I installed libjpeg-devel-6b-30 and libpng-devel-1.2.2 RPMs before building php. I'm at a loss and this issue is delaying our launch window for an important new product that uses jpgraph (thus gd) so any help will be greatly appreciated! Thanks.
quilowAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

hernst42Commented:
The switch --with-gd=/usr/  instructs php not to use the bundled gd, instead use the system gd. Does it work if you use only --with-gd ?
0
quilowAuthor Commented:
Well I had tried rebuilding using just "--with-gd" before and nothing changed. Then it occured to me to remove the gd-devel-1.8.4 rpm and try it again. This time, it looks like it did install the bundled version of gd because the phpinfo page is showing "bundled (2.0.28)" now instead of "1.6 or higher". Alas, the problem still happens though. I'm wondering if I need to do something with Apache? I'm also getting a lot of these errors in the apache log: "[error] an unknown filter was not added: PHP", but I don't think that's related.
0
hernst42Commented:
Maybe your apache-config is not correct. I typical use php as handler and not as filter within apache2.
0
Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

quilowAuthor Commented:
Well there was an issue with the apache config but that turned out to be a red herring. The main httpd.conf file was correct but it was also including an additional php.conf file that was using php as a filter. So I cleaned that up and now I don't get any filter errors in the apache log, but unfortunately, gd is still crashing apache.
0
hernst42Commented:
As this bug is reproducable you might do the following to track down where the error comes from:

get a list of all httpd running by
ps axfu | grep httpd
then pick one of that pids (except the top most one)
the do a
gdb -p <pid>
o the gdb starts and is watching the process. now enter:
cont
so the process is use able. Then keep on executing your php-script which causes a segfault, till you see it in the debugger.
Then type where to get a backtrace of that process. So you might get a clue where the segfault comes from. Post that output here so I can give you an advice whats going on. This backtrace will also be usefull if you open a bug for php.

At them moment I see no other chance how to track down that error.
0
quilowAuthor Commented:
Okay, I think this is what you are looking for. I followed your instructions until I got the segfault and then typed bt. Below is a copy of what I saw. Is this right or do I need to add some paramater to my bt command?

(gdb) cont
Continuing.

Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread -1223509856 (LWP 15417)]
0x0001eb09 in ?? ()
(gdb) bt
#0  0x0001eb09 in ?? ()
#1  0xb6dc2a7a in png_malloc () from /usr/lib/libpng12.so.0
#2  0xb6dba8b1 in png_create_write_struct_2 () from /usr/lib/libpng12.so.0
#3  0xb6dba6ec in png_create_write_struct () from /usr/lib/libpng12.so.0
#4  0xb6ebe0d3 in gdImagePngCtxEx (im=0x823ebf4, outfile=0x823629c, level=-1)
    at /home/sfanning/php-4.3.9/ext/gd/libgd/gd_png.c:448
#5  0xb6ebe051 in gdImagePngCtx (im=0x823ebf4, outfile=0x823629c)
    at /home/sfanning/php-4.3.9/ext/gd/libgd/gd_png.c:424
#6  0xb6ea393a in _php_image_output_ctx (ht=1, return_value=0x82369a4, this_ptr=0x0,
    return_value_used=0, image_type=2, tn=0xb6fe07b7 "PNG", func_p=0xb6ebe02e <gdImagePngCtx>)
    at gd_ctx.c:120
#7  0xb6ea88c6 in zif_imagepng (ht=1, return_value=0x82369a4, this_ptr=0x0, return_value_used=0)
    at /home/sfanning/php-4.3.9/ext/gd/gd.c:1746
#8  0xb6fd4be4 in execute (op_array=0x823610c) at /home/sfanning/php-4.3.9/Zend/zend_execute.c:1640
#9  0xb6fc34df in zend_execute_scripts (type=8, retval=0x0, file_count=3)
    at /home/sfanning/php-4.3.9/Zend/zend.c:891
#10 0xb6f8c725 in php_execute_script (primary_file=0xbfffbe60)
    at /home/sfanning/php-4.3.9/main/main.c:1735
#11 0xb6fdadf6 in php_handler (r=0x823cc18)
    at /home/sfanning/php-4.3.9/sapi/apache2handler/sapi_apache2.c:540
#12 0x080685d5 in ap_run_handler ()
#13 0x08068bef in ap_invoke_handler ()
#14 0x08065276 in ap_process_request ()
#15 0x080608ac in _start ()
#16 0x0823cc18 in ?? ()
#17 0x00000004 in ?? ()
#18 0x0823cc18 in ?? ()
#19 0xb6c772f7 in modperl_process_connection_handler () from /etc/httpd/modules/mod_perl.so
#20 0x080720c5 in ap_run_process_connection ()
#21 0x08066af1 in ap_graceful_stop_signalled ()
#22 0x08066c44 in ap_graceful_stop_signalled ()
#23 0x08066d66 in ap_graceful_stop_signalled ()
#24 0x0806758d in ap_mpm_run ()
#25 0x0806da3f in main ()
0
hernst42Commented:
Its very interesting:
#1  0xb6dc2a7a in png_malloc () from /usr/lib/libpng12.so.0
#2  0xb6dba8b1 in png_create_write_struct_2 () from /usr/lib/libpng12.so.0
#3  0xb6dba6ec in png_create_write_struct () from /usr/lib/libpng12.so.0
the backtrace shows that gd does not seem to be the problem. It looks like there is a problem with the used png-library.
This bug looks the same as yours http://bugs.php.net/bug.php?id=18303
Or compile first a custom libpng and then use this compiled version to be used for PHP ?

0
hernst42Commented:
Forget the compiling of libpng, the problem seems to be the used libpdf See
http://bugs.php.net/bug.php?id=18303#c42343

So using a new/other version of libpdf should solve your problem.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
quilowAuthor Commented:
That solved the problem! Thank you so much for your help!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.