Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1475
  • Last Modified:

Adding cURL support on Linux box

Hello:

I have run in to a situation where I need to add cURL support to PHP on my RH 6.2 box. I have the rpms installed but I beleive I need to recompile PHP now.

1) Is this correct?

2) How do I do it?

3) How do I do it in such a way that I retain all previous settings that were in place?

4) Is there a way to back it up?

Thanks
Rob
0
RobMarreel
Asked:
RobMarreel
  • 8
  • 8
1 Solution
 
hernst42Commented:
Which php-version are you using (sorry, no RH 6.2 available). The following should work with php 4.3.x (maybe also on sooner version), but for further help your php-version might be improtant so I can have a look at the sources.

You don't need to recompile your php. You can also manage to create the curl as a loadable-module for you php.version.
To do that, install the php-sources of the php-version you are using and change into the unpacked sources. Then do:

cd ext/curl
phpize
./configure --with-curl=shared
make
make install

edit you php.ini to enable the new extension for php:
extension=curl.so

make sure you also have install curl-dev and mod_php4-dev or php-dev -rpms.
0
 
RobMarreelAuthor Commented:
Looks like I have PHP 4.1.2 installed. Where am I going to get the sources for that one? Seems like its kind of old.

Maybe it is already on this linux box. Is there a way to check ?

Thanks
Rob
0
 
hernst42Commented:
You can download php 4.1.2 from here:
http://www.php.net/releases.php

Search for a file called TODO-4.2.txt, which should be in the 4.1.2 -source directory
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
RobMarreelAuthor Commented:
OK. I did everything that you listed but it still can't find curl_init(). Do I need to include something or take another step? I even restarted httpd.

Thanks
Rob
0
 
hernst42Commented:
Yes, you need to enable the extension in your php.ini

extension=curl.so

and restart/reload your webserver

or use that code in your php-script:
if (!extension_loaded('curl')) {
    dl('curl.so');
}
0
 
RobMarreelAuthor Commented:
I took a closer look at the ouput and I am getting this:

*** Warning: This library needs some functionality provided by -lcurl.
*** I have the capability to make that library automatically link in when
*** you link to this library.  But I can only do this if you have a
*** shared version of the library, which you do not appear to have.

*** Warning: This library needs some functionality provided by -lcrypto.
*** I have the capability to make that library automatically link in when
*** you link to this library.  But I can only do this if you have a
*** shared version of the library, which you do not appear to have.

*** Warning: This library needs some functionality provided by -lssl.
*** I have the capability to make that library automatically link in when
*** you link to this library.  But I can only do this if you have a
*** shared version of the library, which you do not appear to have.

*** Warning: This library needs some functionality provided by -lcurl.
*** I have the capability to make that library automatically link in when
*** you link to this library.  But I can only do this if you have a
*** shared version of the library, which you do not appear to have.

*** Warning: libtool could not satisfy all declared inter-library
*** dependencies of module curl.  Therefore, libtool will create
*** a static module, that should work as long as the dlopening
*** application is linked with the -dlopen flag.


I beleive I have everything installed that you suggested. Come to find out only the curl.a and curl.la files are being built, not the so.

Rob
0
 
hernst42Commented:
The curl.so should be in the .libs-directory (hidden) ext/curl/.libs
0
 
RobMarreelAuthor Commented:
curl.so isn't there. It isn't anywhere on the HD actually I did a search. I would think it could still compile with the warnings above, but does that make a difference?

in that folder I have:

curl.a
curl.la (link to ../curl.la)
curl.lai

Thanks for the help.

Rob
0
 
hernst42Commented:
did the make run till the end without errors ?? If so the curl.so from the .libs directory may work.
0
 
RobMarreelAuthor Commented:
Here is the output for all of the commands you told me to run. Looks ok to me.



aclocal: macro `AC_ADD_LIBPATH' defined in acinclude.m4 but never used
aclocal: macro `AC_ADD_LIBRARY' defined in acinclude.m4 but never used
aclocal: macro `AC_ADD_LIBRARY_WITH_PATH' defined in acinclude.m4 but never used
aclocal: macro `AC_ADD_INCLUDE' defined in acinclude.m4 but never used



loading cache ./config.cache
checking for gcc... (cached) gcc
checking whether the C compiler (gcc  ) works... yes
checking whether the C compiler (gcc  ) is a cross-compiler... no
checking whether we are using GNU C... (cached) yes
checking whether gcc accepts -g... (cached) yes
checking whether gcc and cc understand -c and -o together... (cached) yes
checking for PHP prefix... /usr/local
checking for PHP includes... -I/usr/local/include/php -I/usr/local/include/php/main -I/usr/local/include/php/Zend -I/usr/local/include/php/TSRM
checking for PHP extension directory... /usr/local/lib/php/extensions/no-debug-non-zts-20010901
checking for CURL support... yes, shared
checking for CURL in default path... found in /usr
checking for cURL greater than 7.8.1... libcurl 7.9.8
checking for curl_easy_perform in -lcurl... (cached) yes
checking host system type... i686-pc-linux-gnu
checking build system type... i686-pc-linux-gnu
checking for ranlib... (cached) ranlib
checking for ld used by GCC... (cached) /usr/bin/ld
checking if the linker (/usr/bin/ld) is GNU ld... (cached) yes
checking for BSD-compatible nm... (cached) /usr/bin/nm -B
checking whether ln -s works... (cached) yes
checking for object suffix... o
checking for executable suffix... no
checking for gcc option to produce PIC... -fPIC
checking if gcc PIC flag -fPIC works... yes
checking if gcc supports -c -o file.o... yes
checking if gcc supports -c -o file.lo... yes
checking if gcc supports -fno-rtti -fno-exceptions ... yes
checking if gcc static flag -static works... -static
checking if the linker (/usr/bin/ld) is GNU ld... yes
checking whether the linker (/usr/bin/ld) supports shared libraries... yes
checking command to parse /usr/bin/nm -B output... ok
checking how to hardcode library paths into programs... immediate
checking for /usr/bin/ld option to reload object files... -r
checking dynamic linker characteristics... Linux ld.so
checking if libtool supports shared libraries... yes
checking whether to build shared libraries... yes
checking whether to build static libraries... no
checking for objdir... .libs
creating libtool
loading cache ./config.cache
checking for working mkdir -p... (cached) yes
creating config_vars.mk
creating Makefile
creating ./config.status
creating config.h
config.h is unchanged


make[1]: Entering directory `/usr/tmpdir/php-4.1.2/ext/curl'
make[1]: Nothing to be done for `all-p'.
make[1]: Leaving directory `/usr/tmpdir/php-4.1.2/ext/curl'
[root@marreel curl]# make clean
make[1]: Entering directory `/usr/tmpdir/php-4.1.2/ext/curl'
make[1]: Nothing to be done for `clean-p'.
make[1]: Leaving directory `/usr/tmpdir/php-4.1.2/ext/curl'
rm -f curl.la *.lo *.slo *.la *.o
rm -rf .libs
[root@marreel curl]# make
make[1]: Entering directory `/usr/tmpdir/php-4.1.2/ext/curl'
/bin/sh /usr/tmpdir/php-4.1.2/ext/curl/libtool --mode=compile gcc -I. -I/usr/tmpdir/php-4.1.2/ext/curl/ -I/usr/tmpdir/php-4.1.2/ext/curl/main -I/usr/tmpdir/php-4.1.2/ext/curl -I/usr/local/include/php -I/usr/local/include/php/main -I/usr/local/include/php/Zend -I/usr/local/include/php/TSRM  -DHAVE_CONFIG_H  -prefer-pic  -c curl.c && touch curl.slo
gcc -I. -I/usr/tmpdir/php-4.1.2/ext/curl/ -I/usr/tmpdir/php-4.1.2/ext/curl/main -I/usr/tmpdir/php-4.1.2/ext/curl -I/usr/local/include/php -I/usr/local/include/php/main -I/usr/local/include/php/Zend -I/usr/local/include/php/TSRM -DHAVE_CONFIG_H -prefer-pic -c curl.c  -fPIC -DPIC -o curl.lo
gcc: unrecognized option `-prefer-pic'
/bin/sh /usr/tmpdir/php-4.1.2/ext/curl/libtool --mode=link gcc  -I. -I/usr/tmpdir/php-4.1.2/ext/curl/ -I/usr/tmpdir/php-4.1.2/ext/curl/main -I/usr/tmpdir/php-4.1.2/ext/curl -I/usr/local/include/php -I/usr/local/include/php/main -I/usr/local/include/php/Zend -I/usr/local/include/php/TSRM  -DHAVE_CONFIG_H -g -O2   -o curl.la -avoid-version -module -rpath /usr/tmpdir/php-4.1.2/ext/curl/modules  curl.lo  -lcurl -ldl -lcrypto -lssl -lcurl
mkdir .libs

*** Warning: This library needs some functionality provided by -lcurl.
*** I have the capability to make that library automatically link in when
*** you link to this library.  But I can only do this if you have a
*** shared version of the library, which you do not appear to have.

*** Warning: This library needs some functionality provided by -lcrypto.
*** I have the capability to make that library automatically link in when
*** you link to this library.  But I can only do this if you have a
*** shared version of the library, which you do not appear to have.

*** Warning: This library needs some functionality provided by -lssl.
*** I have the capability to make that library automatically link in when
*** you link to this library.  But I can only do this if you have a
*** shared version of the library, which you do not appear to have.

*** Warning: This library needs some functionality provided by -lcurl.
*** I have the capability to make that library automatically link in when
*** you link to this library.  But I can only do this if you have a
*** shared version of the library, which you do not appear to have.

*** Warning: libtool could not satisfy all declared inter-library
*** dependencies of module curl.  Therefore, libtool will create
*** a static module, that should work as long as the dlopening
*** application is linked with the -dlopen flag.
ar cru .libs/curl.a curl.lo
ranlib .libs/curl.a
creating curl.la
(cd .libs && rm -f curl.la && ln -s ../curl.la curl.la)
/bin/sh /usr/tmpdir/php-4.1.2/ext/curl/libtool --mode=install cp curl.la /usr/tmpdir/php-4.1.2/ext/curl/modules
cp .libs/curl.lai /usr/tmpdir/php-4.1.2/ext/curl/modules/curl.la
cp .libs/curl.a /usr/tmpdir/php-4.1.2/ext/curl/modules/curl.a
ranlib /usr/tmpdir/php-4.1.2/ext/curl/modules/curl.a
chmod 644 /usr/tmpdir/php-4.1.2/ext/curl/modules/curl.a
PATH="$PATH:/sbin" ldconfig -n /usr/tmpdir/php-4.1.2/ext/curl/modules
----------------------------------------------------------------------
Libraries have been installed in:
   /usr/tmpdir/php-4.1.2/ext/curl/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 `-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.
----------------------------------------------------------------------
make[1]: Leaving directory `/usr/tmpdir/php-4.1.2/ext/curl'


make[1]: Entering directory `/usr/tmpdir/php-4.1.2/ext/curl'
installing shared modules into /usr/local/lib/php/extensions/no-debug-non-zts-20010901
make[1]: Leaving directory `/usr/tmpdir/php-4.1.2/ext/curl'

0
 
hernst42Commented:
Which file are located in /usr/local/lib/php/extensions/no-debug-non-zts-20010901 ?

try this short php-code:

<?php
dl('curl.la');
$c = curl_init('http://www.example.com');

to see if that lib loads instead of the curl.so
0
 
RobMarreelAuthor Commented:
The only file located in that dir is curl.a

So I tried your code but changed it to curl.a. I also tried moving curl.a up one folder to the extensions dir. Says it can't find the file curl.a when I run the php script.

You can look at my phpinfo here http://www.marreel.com/phpinfo.php

or look at the code snippet you sent me at http://www.marreel.com/curl.php

0
 
RobMarreelAuthor Commented:
Do I need to install the PHP source in to a specific location so the config will update the proper files? I have a feeling its not in the right localtion since phpinfo doesn't say anything about curl.
0
 
hernst42Commented:
It seems that those curl-packes do not come with a library to link against. This generates those warnings and it seems the compiler is not able to build a useable module.

The only thing would be to build libcurl, libcrypt and openssl by our own so all needed libs are available and linkable for the php-curl module. It seems that the RedHat 6.2 is too old to add the curl-support very easy :-(

When your are trying to compile those packages with current version you might also need to upgrade automake autoxconf and libtool and this can get a pain.
As I don't have a RedHat 6.2 (and was not able to setup one within my vmware from the iso-images) I can't do such a build on one of my system and give you the libs and curl.so :-(

Best thing is to upgrade that server to a current version which also include security fixes, which might also come with a finished PHP and curl-support.

Sorry but to solve this problem is not so easy a it looked :-(

The location seem to be right, but the needed libs for curl are not available
0
 
hernst42Commented:
It also seems that your extension_dir is not set properly in your php.ini
It should be  
extension_dir=/usr/local/lib/php/extensions/no-debug-non-zts-20010901

Have a look at that die if there is any file curl.* in  /usr/local/lib/php/extensions/no-debug-non-zts-20010901
0
 
RobMarreelAuthor Commented:
Well, although it wasn't the answer I was looking for. It pretty much looks like I need to update the OS. So you did answer my question. I will be upgrading everything and trying again.
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

  • 8
  • 8
Tackle projects and never again get stuck behind a technical roadblock.
Join Now