CentOS / Red Hat Linux Install PHP 5.x PECL Filter Extension

Q. How do I install filter extension for safely dealing with input parameters supplied via a web form using filter_var()?

A. This extension is part of PHP Core version 5.20 and above. Unfortunately, RHEL / CentOS comes with PHP version 5.1.6. So you need to install this extension by typing the following commands.

Install php-devel

You need to install php-devel to compile php extensions:
# yum install php-devel

Download php source code

php_pcre.h header file is not includes with php source code 5.1.6, so you need php source code as well. Visit php.net to grab latest version and store to /opt directory. Use lynx and elinks:
# cd /opt
# elinks http://www.php.net/get/php-5.2.6.tar.bz2/from/a/mirror

Save php source to code to disk. Next, extract source code:
# tar -jxvf php-5.2.6.tar.bz2

Download filter extension

Visit pecl extension to grab latest source code for filter:
# cd /opt
# wget http://pecl.php.net/get/filter-0.11.0.tgz

Install filter extension

Unrar file:
# tar -jxvf filter-0.11.0.tgz
# cd filter-0.11.0

Open logical_filters.c file:
# vi logical_filters.c
Find line that read as follows:

#include "ext/pcre/php_pcre.h"

Change to (the absolute path of php_pcre.h is required):

#include "/opt/php-5.2.6/ext/pcre/php_pcre.h"

Save and close the file. Finally, type the following commands to compile extension:
# phpize
# ./configure
# make install

Configure Filter Extension

Type the following command:
# echo 'extension=filter.so' > /etc/php.d/filter.ini
Restart httpd:
# service httpd restart


🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 6 comments so far... add one


CategoryList of Unix and Linux commands
Disk space analyzersdf duf ncdu pydf
File Managementcat cp mkdir tree
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Modern utilitiesbat exa
Network UtilitiesNetHogs dig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg glances gtop jobs killall kill pidof pstree pwdx time vtop
Searchingag grep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
6 comments… add one
  • Wendall Cada Oct 13, 2008 @ 2:49

    You also need to install pcre-devel.

    # yum install pcre-devel

    • Leonardo Macedo Jul 1, 2014 @ 19:26

      This is it.

      Thanks.

  • sathish Oct 18, 2008 @ 5:57

    Hai

    Can u help us for installing apc extension. We are on suse 10.3

  • ISEDC May 20, 2010 @ 15:24

    How can you install this on RHEL?

  • Adriano Dec 5, 2012 @ 12:22

    On CentOS 6 (PHP 5.3.6)…

    [root@xxx]# make
    /bin/sh /opt/filter-0.11.0/libtool –mode=compile cc -I. -I/opt/filter-0.11.0 -DPHP_ATOM_INC -I/opt/filter-0.11.0/include -I/opt/filter-0.11.0/main -I/opt/filter-0.11.0 -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 -DHAVE_CONFIG_H -g -O2 -c /opt/filter-0.11.0/filter.c -o filter.lo
    libtool: compile: cc -I. -I/opt/filter-0.11.0 -DPHP_ATOM_INC -I/opt/filter-0.11.0/include -I/opt/filter-0.11.0/main -I/opt/filter-0.11.0 -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 -DHAVE_CONFIG_H -g -O2 -c /opt/filter-0.11.0/filter.c -fPIC -DPIC -o .libs/filter.o
    /opt/filter-0.11.0/filter.c: In function ‘zm_startup_filter’:
    /opt/filter-0.11.0/filter.c:236: error: too few arguments to function ‘sapi_register_input_filter’
    make: ** [filter.lo] Erro 1

  • Greg Booth Mar 27, 2013 @ 16:14

    Very helpful, thanks!
    Since PHP 5.2.6 is getting old, I had to find the source and the PECL extension elsewhere.
    PHP source:
    http://autosetup1.googlecode.com/files/php-5.2.6.tar.gz
    Filter extension:
    http://pecl.php.net/package/filter/0.11.0

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre> for code samples. Still have questions? Post it on our forum