Install Curl on linux

After the Mashed Museum day yesterday, I finally got in gear to see what the OpenCalais service could do to enrich the tags upon our blog post archives and forthcoming posts. To do this I used two separate plugins that have already been written and tested out by others (i’ll write about this in a separate post). However, to get this to work, I had to get the Curl library working on our main server (backup already functions) and to do this required a clean install of curl. So first off, I’ll be techie and explain how to get curl working on your linux box post installation of apache and PHP. Most of the articles I found talked about doing this prior to installing PHP.

First off once you’ve used your SSH client to login to your server, check that you don’t have curl already. Do this by issuing:

CODE:

  1. curl –version

You then need to download the source files that are appropriate for your OS. To do this issue the following command:

CODE:

  1. wget http://curl.haxx.se/download/curl-X.XX.X.tar.gz

(Replace the X.XX.X with the version that you require, I used an older version – 7.15.2 – as the latest version was incompatible with my PHP.)

This then needs to be unpacked, so issue the following command:

CODE:

  1. tar -xzf curl-X.XX.X.tar.gz

Then after unpacking navigate to the created folder:

CODE:

  1. CD curl-X.XX.X

Then issue:

./configure and wait for this to finish. Once done issue a make command and wait for this to finish and then once done issue make install (again wait for this to finish.) Now you can check that curl is working, so in my case I issued this command:

CODE:

  1. curl –version
  2. curl http://www.finds.org.uk>test.txt

This then came back with the response:

% Total % Received % Xferd Average download Upload Speed Total Time Time Spent TimeLeft Current speed
100 20090 0 20090 0 0 5363 0 –:–:– 0:00:03 –:–:– 7329

To summarise, you will be issuing these commands in sequence:

  1. wget http://curl.haxx.se/download/curl-X.XX.X.tar.gz
  2. tar -xzf curl-X.XX.X.tar.gz
  3. ./configure
  4. make
  5. make install
  6. curl –version
  7. curl http://www.finds.org.uk >test.txt

Now you can proceed to recompile your version of PHP to include support for curl. First check your current configuration via your phpinfo file. Mine used to look like this:

CODE:

  1. ‘./configure’ ‘-with-MySQL=/usr/share/mysql/’ ‘–with-apxs2=/usr/sbin/apxs’ ‘–with-XSL ‘–with-gd’ ‘–with-jpeg-dir=/usr’ ‘–with-zlib-dir=/usr’ ‘–with-PNG-dir=/usr’ ‘–with-freetype-dir=/usr’ ‘–with-tidy’ ‘–enable-SOAP ‘–with-magickwand=/usr/local/’ ‘–with-openssl’ ‘–enable-exif’

I want it to look like this:

CODE:

  1. ‘./configure’ ‘-with-MySQL=/usr/share/mysql/’ ‘–with-apxs2=/usr/sbin/apxs’ ‘–with-XSL ‘–with-gd’ ‘–with-jpeg-dir=/usr’ ‘–with-zlib-dir=/usr’ ‘–with-PNG-dir=/usr’ ‘–with-freetype-dir=/usr’ ‘–with-tidy’ ‘–enable-SOAP ‘–with-magickwand=/usr/local/’ ‘–with-openssl’ ‘–enable-exif’ ‘–with-curl=usr/local’

Now using your SSH client, navigate to the folder with your current version of PHP installed eg. 5.04. Then issue the following command:

CODE:

  1. ./configure –with-MySQL=/usr/share/mysql/ –with-apxs2=/usr/sbin/apxs –with-XSL –with-gd  –with-jpeg-dir=/usr –with-zlib-dir=/usr –with-PNG-dir=/usr –with-freetype-dir=/usr –with-tidy –enable-SOAP –with-magickwand=/usr/local/ –with-openssl –enable-exif –with-curl=/usr/local/

Once finished, run the make command and then after this has run through, you will need to run make install to finish off the recompiled software. To summarise:

  1. ./configure –with-MySQL=/usr/share/mysql/ –with-apxs2=/usr/sbin/apxs –with-XSL –with-gd –with-jpeg-dir=/usr –with-zlib-dir=/usr –with-PNG-dir=/usr –with-freetype-dir=/usr –with-tidy –enable-SOAP –with-magickwand=/usr/local/ –with-openssl –enable-exif –with-curl=/usr/local/
  2. make
  3. make install

To make this take effect, you’ll need to restart your webserver and then recheck your phpinfo. The desired addition of with-curl should be implemented. You can then proceed to check that your PHP and curl play like lovely children in a playpen. This can be done by running the following PHP file:

PHP:

  1. $curl = curl_init();
  2. curl_setopt ($curl, CURLOPT_URL, “http://www.britishmuseum.org”);
  3. curl_exec ($curl);
  4. curl_close ($curl);

The above script starts off by intitialising curl, the tells it to capture the URL mentioned and then print it out. So in this instance you’ll get the BM‘s homepage from that script on your domain.
Simple hey. You can then start to get more dangerous by writing screen scrapers to leverage you Google Analytics content for instance…..

OpenCalais helped to tag this with:

Possibly related posts: Gallery upgradedMashed MuseumDatabase upgrade work to commence

Leave a comment