Solved

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

Posted on 2004-10-20
9
667 Views
Last Modified: 2013-12-13
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.
0
Comment
Question by:quilow
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
9 Comments
 
LVL 48

Expert Comment

by:hernst42
ID: 12363366
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
 

Author Comment

by:quilow
ID: 12365708
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
 
LVL 48

Expert Comment

by:hernst42
ID: 12367340
Maybe your apache-config is not correct. I typical use php as handler and not as filter within apache2.
0
Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

 

Author Comment

by:quilow
ID: 12372735
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
 
LVL 48

Expert Comment

by:hernst42
ID: 12373177
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
 

Author Comment

by:quilow
ID: 12373740
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
 
LVL 48

Expert Comment

by:hernst42
ID: 12373888
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
 
LVL 48

Accepted Solution

by:
hernst42 earned 500 total points
ID: 12373923
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
 

Author Comment

by:quilow
ID: 12375608
That solved the problem! Thank you so much for your help!
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
i am unable to add data to mysql database 6 54
Increase counter and attr inside a while loop 15 37
curl parse data from site 20 44
MySQL-Design Help 12 44
Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question