Click to See Complete Forum and Search --> : Proper way to add support for GD, ImageMajik, cURL into php?


schwim
08-04-2006, 05:44 PM
Hi there guys,

If I leave out some important information, please just let me know. Being new to this leaves one fairly ignorant on exactly what is required.

I ordered a new server through my host. On moving the first of the domains over to the new server, I found that cURL and GD is not built into php. I'm not sure how to build support for these modules into php.

Server: Fedora Core 4
WebServer: Apache: 1.3.36
php ver: 4.4.2 (info.php (http://208.109.107.41/~rts/info.php))
GD Ver: 2 (already installed)
Server management console: WHM/cPanel: 10.8.2

Anything else you need, please just let me know.

With my server setup, how do I go about adding support for things like GD and cURL? I'm totally new to php installs, and this was already done for me when I took the keys over, so I don't have a single install under my belt.... be gentle :D

thanks,
json

tsinka
08-06-2006, 05:20 PM
The info on the phpinfo page makes me think that this is a custom build of apache and php. You may be able to compile the missing extensions yourself. Is this a dedicated server ?

Thomas

schwim
08-06-2006, 05:32 PM
Hi there Thomas,

First off, thank you for your reply. I figured weekend was the slow time, but I was starting to get concerned that I asked a moronic question :)

It is a dedicated server. I don't know a lot about the enviroment, but I do know this. The OS is Fedora Core 4, and the php being used is not the php supplied by Fedora. I'm thinking that when the host installed cPanel, php/apache/mysql got installed along with it, since it's a bundle.

When you say "compile the missing extensions", does that mean that it's something I can do without rebuilding php? Forgive my ignorance, but I'm not savvy with php installs.

thanks again,
json

tsinka
08-07-2006, 09:30 AM
Ok,

it's not too easy but possible. I don't know how the contract with your provider looks like but manually compiling stuff on your server might cause troubles regarding future provider support. Did you already ask your provider if they can add the missing extensions to the server ?

------------------------------

First of all make sure that neccessary packages are installed. Execute the following command

rpm --query <packagename>

for each of the following packages:

ImageMagick, gd, gd-devel, libpng, libpng-devel, libtiff, libtiff-devel, libjpeg, libjpeg-devel, freetype, freetype-devel, curl, curl-devel

If any of these packages are missing then download and install the most recent versions of that packages.

Install: rpm -Uvh <rpmfiles>

If rpm displays any unresolved dependencies then download and install those packages, too.

Is gcc installed on the system ? You can check that by executing the command:

gcc --version

If gcc is not installed then download and install the gcc package (and any dependencies).

If the packages are installed then the next step will be compiling the extensions you need.

Download and extract the source tarball of php 4.4.2.

Then do the following for each extension:

1. cd to <phpsource>/ext/<extension>
2. /usr/local/bin/phpize
3. ./configure --help (to see if phpize worked and which switches you need)
4. ./configure --with-php-config=/usr/local/bin/php-config <additional_switches>
where <additional_switches> differs from extension to extension (like e.g. --with-curl=/usr)
5. make
6. make install

./configure --help in step 3. displays all switches available for the given extension.

make install should display the location of the extension directory. You need to add that directory to the "extension_dir" line in php.ini. Additionally you need to enable each extension in php.ini by adding an extension=<sofile> line (like e.g. extension=curl.so).

Thomas

schwim
08-07-2006, 11:37 AM
Hi there Thomas,

My host has stated that it expects me to modify install to suit, or they will do it for a fee. As well, they will re-install the server software(again, for a fee) if I manage to break things completely.

Running rpm query provided the following:


ImageMagick-6.2.2.0-3.fc4.2
gd-2.0.33-2
gd-devel-2.0.33-2
libpng-1.2.8-2
libpng-devel-1.2.8-2
libtiff-3.7.1-6.fc4.3
libtiff-devel-3.7.1-6.fc4.3
libjpeg-6b-34
libjpeg-devel-6b-34
freetype-2.1.9-2
freetype-devel-2.1.9-2
curl-7.13.1-5.fc4
curl-devel-7.13.1-5.fc4


GCC version:

gcc (GCC) 4.0.2 20051125 (Red Hat 4.0.2-8)
Copyright (C) 2005 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.


Now I have to ask for a little more help before I continue:

1) I've downloaded/uploaded php 4.2.2. Does it matter where I extract it? Currently, I've got it sitting in one of the FTP users' home dir.

and concerning this part of the instructions:


1. cd to <phpsource>/ext/<extension>
2. /usr/local/bin/phpize
3. ./configure --help (to see if phpize worked and which switches you need)
4. ./configure --with-php-config=/usr/local/bin/php-config <additional_switches>
where <additional_switches> differs from extension to extension (like e.g. --with-curl=/usr)
5. make
6. make install


1) is phpsource the NEW location where I've got the tarball sitting(or where you tell me to put it), or is it where the existing php install is? If it's the existing php, how do I find out where that is? They're not using Fedora's php, but one that I think came with cpanel.

2) You tell me to cd to the extension directory, then in step 2, it looks like you're telling me to go to another directory. Am I misunderstanding that? Are you stating to go into the extension directory, then run the command "/usr/local/bin/phpize/configure --help" while in my extension directory?

I also don't understand the .so file comment. Is the .so file made already, and I just need to point it to it, or do I actually need to create the file?

I apologize for my ignorance in the matter, but really appreciate your help. If you get to the point where you think I'm a lost cause in this matter, just let me know :) Either way, I am very thankful for the help you've already provided.

thanks,
json

tsinka
08-07-2006, 01:01 PM
Hi,

regarding your questions:

It doesn't matter where you extract the tarball (in some home directory or somewhere under /usr/src).

I'll try to make things clearer:

1. you already downloaded the php-4.2.2.tar.gz tarball and have it in a directory. Since this is a ftp user directory move the file to another directory, maybe your own home directory on the server or let's say to /usr/src/compile

Let's say the base directory is /usr/src/compile, then execute the following commands to compile the curl extension:

1. mkdir /usr/src/compile
2. mv /dir/to/php-4.2.2.tar.gz /usr/src/compile
3. cd /usr/src/compile
4. tar xzf php-4.2.2.tar.gz
5. cd php-4.2.2/ext/curl
6. /usr/local/bin/phpize
7. ./configure --with-curl=/usr --with-php-config=/usr/local/bin/php-config
8. make
9. make install

Don't forget to set the extension dir and to enable the extension in php.ini.

The step 1. in my last post was a changedir, step 2. is the direct execution of a command (not a cd).

I just saw on the PHP site that php 4.4.3 has been released so it might be a good idea to recompile php completely. But as a first step just try to recompile the additional php 4.2.2 extensions.

schwim
08-07-2006, 05:32 PM
Hi there Thomas,

I've run configure, make and install, and I'm to the point where I'm editing the php.ini.

In it, I've got this for the extensions value:


extension_dir = "./";


This is what install provided me for a path:

/usr/local/lib/php/extensions/no-debug-non-zts-20020429/

Do I make the extensions value like this?


extension_dir = "./, /usr/local/lib/php/extensions/no-debug-non-zts-20020429/";


I didn't think I was supposed to get rid of the current dir, but I'm not sure how to add another directory to the value.

and you said:


Don't forget to set the extension dir and to enable the extension in php.ini.


this means that the section "Dynamic Extensions", I need to add "extension=curl.so", right? Currently, there is no extension listed there, so I'm going by the commented lines to come up with what to put there.

thank you very much for all of your help.

thanks,
json

tsinka
08-07-2006, 05:55 PM
Hi,

extension dir has to be:

extension_dir="/usr/local/lib/php/extensions/no-debug-non-zts-20020429"

and yes,

just put

extension=curl.so

to the extension block (or remove the semicolon in front of that line if it already exists).

Then restart apache.

Thomas

schwim
08-07-2006, 06:13 PM
Sir, I hold you in the highest esteem, right up there w/Mr. Torvalds. I did what you said, restarted, and I got the following in phpinfo:


CURL support enabled
CURL Information libcurl/7.13.1 OpenSSL/0.9.7f zlib/1.2.2.2 libidn/0.5.15


YAY!

Is enabling GD done the same way? When I searched google previously to try to find out how to do this, it seemed a lot harder than what I just did to enable curl support.

I apologize for ending our successful curl install with questions on installing GD, but I'm afraid I'll lose my magic mojo if I don't ask the question while my karma is in such good shape :)

thank you again for your time and assistance,
json

tsinka
08-07-2006, 06:51 PM
Compiling the gd extension is nearly the same besides the fact that the gd extension needs more configuration switches.

The steps that differ:

5. cd php-4.2.2/ext/gd
7. ./configure --with-php-config=/usr/local/bin/php-config --with-gd --with-jpeg-dir=/usr --with-png-dir=/usr --with-zlib-dir=/usr --with-freetype-dir=/usr --enable-gd-native-ttf

Then add extension=gd.so to php.ini and restart apache.

Thomas

schwim
08-07-2006, 09:07 PM
Hi there Thomas,

I was ripping along until I got to the configure portion of the script. I got this error:


./configure: line 2892: /usr/local/lib/php.ini: Permission denied
./configure: error: Cannot find php-config. Please use --with-php-config=PATH


this was my command:


sh ./configure --with-php-config=/usr/local/lib/php.ini --with-gd --with-jpeg-dir=/usr --with-png-dir=/usr --with-zlib-dir=/usr --with-freetype-dir=/usr --enable-gd-native-ttf


I viewed phpinfo to get the php.ini location, and I traversed to /usr/local/lib to make sure that it's still there. It's there along with the backup file I made before I made any changes for curl.

So, the file is there, and I don't think I'm typing anything wrong. Is there any other reason why it would tell me permission was denied? I'm working as root, and I've not made any changes to the enviroment since support for curl was enabled.

thanks,
json

tsinka
08-08-2006, 03:37 AM
No big problem, you accidently used the path to php.ini as value instead of the path to the php-config executable.

You have to use
--with-php-config=/usr/local/bin/php-config
and not
--with-php-config=/usr/local/lib/php.ini

Thomas

schwim
08-08-2006, 09:25 AM
Hi there Thomas,

I just wrapped up the GD install, and it's showing up under phpinfo. I can't thank you enough for your help.

I have a question though. I'm pretty sure that I used the value php.ini in the config line when I built curl, because I thought you were telling me to put my value in php-config. Is it possible that I messed up curl by doing this? I've run too many commands to view the history at the command line, so I can't see it for sure, but I'm almost positive that I've done this.

thanks,
json

tsinka
08-08-2006, 09:39 AM
Did you get the same error configuring the curl extension ? If not then everything should be fine. Just create a little php script to test curl. I think it should work since the extension seems to load without errors and shows up in the phpinfo output.

If you compile php without (or with the wrong) php-config binary then the extension most likely won't load at all.

Thomas

schwim
08-08-2006, 10:41 AM
Hi there Thomas,

I found a test script over at linuxformat.co.uk(actual page (http://linuxformat.co.uk/wiki/index.php/PHP_-_The_Curl_library)):


<?php
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, "http://www.linuxformat.co.uk");
curl_setopt($curl, CURLOPT_VERBOSE, 1);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_exec($curl);
curl_close ($curl);
?>


According to the instructions, I should have gotten something that looks like this in return to running it:


* About to connect() to www.linuxformat.co.uk port 80
* Connected to www.linuxformat.co.uk (212.113.202.71) port 80
> GET / HTTP/1.1
Host: www.linuxformat.co.uk
Pragma: no-cache
Accept: */*

< HTTP/1.1 200 OK
< Date: Wed, 13 Apr 2005 10:38:18 GMT
< Server: Apache/1.3.26 (Unix) Debian GNU/Linux PHP/4.1.2
< X-Powered-By: PHP/4.1.2
< Set-Cookie: POSTNUKESID=44fca78a116342c31c63befab03d6389; expires=Sat, 16-Apr-05 10:38:18 GMT; path=/
< Expires: Thu, 19 Nov 1981 08:52:00 GMT
< Cache-Control: cache
< Pragma: no-cache
< Transfer-Encoding: chunked
< Content-Type: text/html; charset=iso-8859-1
* Connection #0 left intact
* Closing connection #0


But if you view the script here (http://server.schwimsdns.com/~cck/curl.php), you'll see that I'm just getting a blank screen. Would that be curl, or something else(like a firewall) causing the problem? I don't even get an error printed to screen.

thanks,
json

tsinka
08-08-2006, 11:50 AM
You're not seeing an error because there is none (I guess). The script exactly follows the code.

The magic line is
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);

which makes cur_exec to return the data instead of just displaying it. So either remove that line or do something like:


<?php
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, "http://www.linuxformat.co.uk");
curl_setopt($curl, CURLOPT_VERBOSE, 1);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$res = curl_exec($curl);
curl_close ($curl);

print_r($res);
?>


Thomas

schwim
08-08-2006, 12:28 PM
:)

It pulled the page correctly Thomas, thank you!

I've installed ImageMagick, and it seems to be found just fine, I didn't do anything at all with php, just installed it and pointed the script to the directory. Is this ok?

I'm also trying to install gettext(for translation). I found this (http://us2.php.net/gettext) at php.net, and it seems like it gets installed the same as the other extensions with two exceptions:

1) at the php.net site, it states that I need to define a directory, and it says that it defaults to /usr/local. Do I want to change this to /usr? That's the dir that you've told me to use in the past instructions.

2) It also states on the php.net site that I don't need to do anything at all in php.ini. Is this correct? I don't need to add a .so listing under extensions?

Also, there's already a /gettext dir under /ext. Do I even need the downloaded file (http://www.gnu.org/software/gettext/manual/html_mono/gettext.html), or can I just use what's in the /usr/src/compile/php-4.4.2/ext/gettext directory?

Following your past instructions, would this be my method of installing gettext?

1. cd /usr/src/compile/php-4.2.2/ext/gettext
2. /usr/local/bin/phpize
3. ./configure --with-gettext=/usr --with-php-config=/usr/local/bin/php-config
4. make
5. make install

Then no editing of the php.ini(like it states at the php.net site)?

I know I might need to change the directory for --with-gettext.

thanks,
json

tsinka
08-08-2006, 12:53 PM
Ok,

you're almost right. You still need to enable the extension by adding the line extension=gettext.so to php.ini (but there are no additional configuration directives in php.ini related to the gettext extension). I think the /usr directory is correct but you need to make sure that the gettext library (including the devel package if available) is installed at all. The gettext extension depends on that library.

rpm --query gettext
rpm --query gettext-devel

both command should return some info. If one of those packages is missing then download and install them.

Besides that, your steps look good :)

Thomas

schwim
08-08-2006, 01:07 PM
Hi there Thomas,

I did it including the changes you stated, and it shows correctly in phpinfo now.

Do you mind if I keep this thread open(don't mark it resolved)? I've got a few more things that I'll try to install, but I'm currently stuck on netpbm, as I've installed it, but can't find it :) Once I've gotten that figured out, I may have a couple more questions to ask before I can call it done.

Thanks so very much for your help. I can't imagine the trouble I would have had trying to get my host to take care of this for me.

thanks,
json

tsinka
08-08-2006, 01:42 PM
The base installation path of netpbm should be /usr. Execute the commands

ll /usr/lib/libnetpbm.so*
and
ll /usr/include/pbm*.h

Additionally type pbm on the console and then press the tab key twice. You should get a list of pbm commands. Those commands are in /usr/bin.

If those command return anything then netpbm should be installed including the devel package and the pbm progs. You don't need the devel package if you just want to use pbm with e.g. the php-netpbm class.

Thomas

schwim
08-08-2006, 01:52 PM
Hi there Thomas,

I tried the commands you stated, and I'm getting some errors:

ll /usr/lib/libnetpbm.so*
nets
ll: command not found

pbm then tab twice doesn't do anything. If I simply hit the tab twice at a new prompt, it offers all 1500+ results, so that's working, but it's not finding netpbm.

I installed in via yum(since I'm on FC4), and when I run rpm --query netpbm, I get:

netpbm-10.33-1.FC4

If I type whereis netpbm, I get:

netpbm:

so, it shows that it's installed, but it won't tell me where.

Any suggestions would be appreciated.

thanks,
json

tsinka
08-08-2006, 01:57 PM
replace ll with ls -l

What does

rpm --query netpbm-progs

return ? You may need to install netbpm-progs, too.

There are the packages netpbm, netpbm-progs and netpbm-devel.


Thomas

schwim
08-08-2006, 02:08 PM
Hi there Thomas,

Installing -progs and -devel worked. Once I did that, the script found it just fine.

Again, thank you very much, and I'm positive that I'll be back shortly when I get stuck again.

thanks,
json