Solved

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

Posted on 2004-10-20
9
655 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
  • 5
  • 4
9 Comments
 
LVL 48

Expert Comment

by:hernst42
Comment Utility
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
Comment Utility
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
Comment Utility
Maybe your apache-config is not correct. I typical use php as handler and not as filter within apache2.
0
 

Author Comment

by:quilow
Comment Utility
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
Easy Project Management (No User Manual Required)

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 48

Expert Comment

by:hernst42
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
That solved the problem! Thank you so much for your help!
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduction Many web sites contain image galleries; a common design for these galleries includes a page with a collection of thumbnail images.  You can click on each of the thumbnail images to see the larger version of the image.  This is easily i…
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 …
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

763 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now