Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I'm trying to compile pHash 0.9.5 on Centos 6.3 x86_64 Here is the detail of the steps I've followed:

$ yum install unzip
$ wget https://downloads.sourceforge.net/project/cimg/CImg-1.5.4.zip
$ unzip CImg-1.5.4.zip
$ wget http://phash.org/releases/pHash-0.9.5.tar.gz
$ tar xvf pHash-0.9.5.tar.gz
$ cp CImg-1.5.4/CImg.h pHash-0.9.5/src/
$ cd pHash-0.9.5
$ ./configure --enable-video-hash=no --enable-audio-hash=no
$ make
$ make install

Then once pHash is installed I've tried to install the php extension like this:

$ cd bindings/php
$ phpize
$ ./configure 
checking for grep that handles long lines and -e... /bin/grep
checking for egrep... /bin/grep -E
checking for a sed that does not truncate output... /bin/sed
checking for cc... cc
checking for C compiler default output file name... a.out
checking whether the C compiler works... yes
checking whether we are cross compiling... no
checking for suffix of executables... 
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether cc accepts -g... yes
checking for cc option to accept ISO C89... none needed
checking how to run the C preprocessor... cc -E
checking for icc... no
checking for suncc... no
checking whether cc understands -c and -o together... yes
checking for system library directory... lib
checking if compiler supports -R... no
checking if compiler supports -Wl,-rpath,... yes
checking build system type... x86_64-unknown-linux-gnu
checking host system type... x86_64-unknown-linux-gnu
checking target system type... x86_64-unknown-linux-gnu
checking for PHP prefix... /usr
checking for PHP includes... -I/usr/include/php -I/usr/include/php/main -I/usr/include/php/TSRM -I/usr/include/php/Zend -I/usr/include/php/ext -I/usr/include/php/ext/date/lib
checking for PHP extension directory... /usr/lib64/php/modules
checking for PHP installed headers prefix... /usr/include/php
checking if debug is enabled... no
checking if zts is enabled... no
checking for re2c... no
configure: WARNING: You will need re2c 0.13.4 or later if you want to regenerate PHP parsers.
checking for gawk... gawk
checking whether pHash is available... yes, shared
checking for g++... g++
checking whether we are using the GNU C++ compiler... yes
checking whether g++ accepts -g... yes
checking how to run the C++ preprocessor... g++ -E
checking for pHash in default path... found in /usr/local
checking for ANSI C header files... yes
checking for sys/types.h... yes
checking for sys/stat.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for memory.h... yes
checking for strings.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for unistd.h... yes
checking pHash.h usability... no
checking pHash.h presence... no
checking for pHash.h... no
configure: error: 'pHash.h' header not found

So apparently pHash has been installed correctly checking for pHash in default path... found in /usr/local but pHash.h is not found.

pHash.h is located in /usr/local/include. I'm trying to debug the configure script to see how come this file is not located but for now I'm not really successful.

If anyone have an idea I would much appreciate. Thanks.



Apparently according the config.log: it's caused by CImg.h library so I'm wondering if I have to register somewhere this header file...

configure:5136: checking pHash.h usability
configure:5153: g++ -c -g -O2  -I/usr/include/php -I/usr/include/php/main -I/usr/include/php/TSRM -I/usr/include/php/Zend -I/usr/include/php/ext -I/usr/include/php/ext/date/lib -I/usr/local/include -DHAVE_PHASH conftest.cpp >&5
In file included from conftest.cpp:51:
/usr/local/include/pHash.h:50:18: error: CImg.h: No such file or directory
In file included from conftest.cpp:51:
/usr/local/include/pHash.h:51: error: 'cimg_library' is not a namespace-name
/usr/local/include/pHash.h:51: error: expected namespace-name before ';' token
In file included from conftest.cpp:51:
/usr/local/include/pHash.h:144: error: expected ';' before '<' token
/usr/local/include/pHash.h:211: error: expected ',' or '...' before '<' token
/usr/local/include/pHash.h:250: error: expected ',' or '...' before '<' token
/usr/local/include/pHash.h:273: error: expected ',' or '...' before '<' token
In file included from conftest.cpp:51:
/usr/local/include/pHash.h:292: error: expected initializer before '<' token


ok, so I've run cpp -Wp,-v to see which default paths was loaded by the pre-compiler:

$ cpp -Wp,-v
ignoring nonexistent directory "/usr/lib/gcc/x86_64-redhat-linux/4.4.7/include-fixed"
ignoring nonexistent directory "/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../x86_64-redhat-linux/include"
#include "..." search starts here:
#include <...> search starts here:
End of search list.

So /usr/local/include is part of the default path so I've copied CImg.h in this folder and try to run the ./configure again. Now I have an issue with audiophash.h which apparently is a known issue.

I'll try to fix it and come back here to hopefully answer my question.

share|improve this question

3 Answers 3

up vote 2 down vote accepted

ok so here is the complete answer:

Download required libraries

$ cd ~/download
$ yum install libsndfile-devel unzip
$ wget https://downloads.sourceforge.net/project/cimg/CImg-1.5.4.zip
$ wget http://phash.org/releases/pHash-0.9.5.tar.gz
$ wget http://www.mega-nerd.com/SRC/libsamplerate-0.1.8.tar.gz
$ wget http://sourceforge.net/projects/mpg123/files/mpg123/1.15.1/mpg123-1.15.1.tar.bz2/download

Compile required library for pHash. We need to enable the audio and image support because of the PHP extension.

$ tar xvf libsamplerate-0.1.8.tar.gz
$ cd libsamplerate-0.1.8
$ ./configure
$ make && make install
$ tar xvf mpg123-1.15.1
$ cd mpg123-1.15.1
$ ./configure
$ make && make install
We need to copy CImg.h in the /user/local/include folder
$ unzip CImg-1.5.4.zip
$ cp CImg-1.5.4/CImg.h /usr/local/include

Compile pHash library

$ tar xvf pHash-0.9.5.tar.gz
$ cd pHash-0.9.5
$ ./configure --enable-video-hash=no
$ make && make install
Compile the PHP extension
$ cd bindings/php
$ phpize
$ ./configure LIBS="-lpthread"

Edit pHash.cpp

I had to edit pHash.cpp to fix a compilation error. I think you only need to do it if you are using php >=5.3

$ vi /root/download/pHash-0.9.5/bindings/php/pHash.cpp
# line 106, replace "function_entry" by "zend_function_entry"
# save and close
Finish the compilation
$ make
$ make test
$ make install
# finally enable pHash in the php.ini adding extension=pHash.so
# restart apache

Optional - If you want to store the hash in the database (SQL):

You need to edit the pHash.cpp to modify the return value to the hash.

By default ph_dct_imagehash($file) return a *ulong64 (pointer) we need to retrieve a string to store it in the database.

see: https://github.com/lucidix/phash/commit/5be2d454c932152e9b2395e21f97a008c6bd8766

share|improve this answer
Thank you very much for the detailed instructions! –  jamix Sep 20 '13 at 13:41

I know this is a bit off-topic, but I struggled to install pHash + php extension on Ubuntu 12.04 LTS amd64, so I'm sharing my installation log as well :

$ sudo apt-get install make libsndfile-dev checkinstall
$ sudo apt-get install cimg-dev libjpeg62 libfftw3-3 imagemagick graphicsmagick

$ wget http://downloads.sourceforge.net/project/libpng/libpng15/1.5.18/libpng-1.5.18.tar.gz
$ tar xvf libpng-1.5.18.tar.gz
$ cd libpng-1.5.18
$ ./configure
$ make check
$ make install

cimg has a lot of dependencies, which are required if you need to manipulate other formats than bitmap (given that you do not want to handle the conversion yourself):
libjpeg62 => jpeg support
libpng15 => png support
libfftw3-3 => Fourier transformation
imagemagick => for format conversion
graphicsmagick => imagemagick fork, required

$ sudo apt-get install libsamplerate0-dev libmpg123-dev

These two libraries are required for audio hashing. The php bindings currently require the pHash library to have audio hashing enabled to compile (see http://lists.phash.org/htdig.cgi/phash-support-phash.org/2012-December/000139.html)

$ cd
$ wget http://phash.org/releases/pHash-0.9.6.tar.gz
$ tar xvf pHash-0.9.6.tar.gz
$ cd pHash-0.9.6
$ ./configure --enable-openmp=yes --enable-video-hash=no LIBS='-lpthread'
$ make
$ sudo checkinstall --pkgname=phash --pkgversion="1:$(date +%Y%m%d%H%M)-0.9.6" --backup=no \
  --deldoc=yes --fstrans=no --default

I use checkinstall to create and manage a phash package, but you can go for a make install instead. The LIBS='-lpthread' tells the configure script to use the lpthread library (otherwise it won't compile on my machine)

The shipped php bindings won't work when compiled with my php version (5.3) because of an obscure API version problem, so I used this source instead :

$ cd
$ git clone --depth=1 http://github.com/Alexis2004/php-phash
$ cd php-phash
$ pear install CodeGen_PECL
$ ./compile.sh
$ make test
$ make install

All you have to do now is to add 'extension=pHash.so' to your php.ini file(s), and you're good to go!

share|improve this answer

@maxwell2022 implementation did not cover libpng and ffmpeg. Without these dependencies, the PHP binding did not for me.

Here is my install log:

yum install libsndfile-devel -y

wget http://www.mega-nerd.com/SRC/libsamplerate-0.1.8.tar.gz
tar xvf libsamplerate-0.1.8.tar.gz
cd libsamplerate-0.1.8
make && make install

wget http://sourceforge.net/projects/mpg123/files/mpg123/1.15.4/mpg123-1.15.4.tar.bz2/download
tar xvf mpg123-1.15.4.tar.bz2
cd mpg123-1.15.4
make && make install

wget http://sourceforge.net/projects/libpng/files/libpng15/1.5.17/libpng-1.5.17.tar.gz/download
tar xvf libpng-1.5.17.tar.gz
cd libpng-1.5.17
make && make install

wget https://downloads.sourceforge.net/project/cimg/CImg-1.5.6.zip
unzip CImg-1.5.6.zip
cp CImg-1.5.6/CImg.h /usr/local/include

su -c 'yum localinstall --nogpgcheck http://download1.rpmfusion.org/free/el/updates/6/i386/rpmfusion-free-release-6-1.noarch.rpm http://download1.rpmfusion.org/nonfree/el/updates/6/i386/rpmfusion-nonfree-release-6-1.noarch.rpm'

yum install ffmpeg ffmpeg-devel libpng-devel -y

ln -s /usr/include/ffmpeg/libavutil /usr/include/libavutil
ln -s /usr/include/ffmpeg/libavformat /usr/include/libavformat
ln -s /usr/include/ffmpeg/libavcodec /usr/include/libavcodec
ln -s /usr/include/ffmpeg/libswscale /usr/include/libswscale

wget http://phash.org/releases/pHash-0.9.6.tar.gz
tar xvf pHash-0.9.6.tar.gz
cd pHash-0.9.6

make && make install

cd bindings/php
make install

echo 'extension=pHash.so' > /etc/php.d/phash.ini

And incase you need to start over... a quick clean up.

cd ~/libsamplerate-0.1.8 && make uninstall
cd && rm -fr libsamplerat*

cd ~/mpg123-1.15.4 && make uninstall
cd && rm -fr mpg123-1.15.*

cd ~/libpng-1.5.17 && make uninstall
cd && rm -fr libpng-1.5.*

cd ~/pHash-0.9.6 && make uninstall
cd && rm -fr pHash*

rm -fr ~/CImg-1.5.6
rm -f CImg*
rm -f /usr/local/include/CImg.h
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.