PHP5 CGI & CLI with an existing PHP4 Modules installation



Hello,

I’ve changed the existing php-5.1.2-iworx srpm to allow the rpm to be installed on a box with php4 already installed as a module.

The rpm will install both cgi and cli version

Bin are in /usr/bin/php5.2.0

lrwxrwxrwx 1 root root 7 Oct 1 15:42 php -> php-cgi
-r-x–x–x 1 root root 4723472 Oct 1 15:28 php-cgi
-r-x–x–x 1 root root 18004654 Oct 1 15:28 php-cli

Ini files are in /etc/php5/

-rw-r–r-- 1 root root 39517 Oct 1 15:28 php-cgi.ini
-rw-r–r-- 1 root root 39517 Oct 1 15:28 php-cli.ini
drwxr-xr-x 2 root root 4096 Oct 1 19:01 php.d

Extension are in /usr/lib/php5

mysql.so

etcx…

IT WORKS FOR US, BUT IT ?IGHT NOT FOR YOU. WE WON’T ASSUME ANY BROKS IN YOUR SYSTEM. CHECK THE SPEC FILE IF YOU ARE NOT SURE.

The php5.2.0 SRPM
http://clust01-carat01.carat-hosting.com/srpm/php5-5.2.0-CLI_CGI.rhe4x.1.0.2.src.rpm

Rebuild the SRPM will also install all these RPMS-


-rw-r--r--  1 root root  548858 Oct  1 18:50 php-devel-5.2.0-cli_cgi.rhe4x.1.0.2.x86_64.rpm
-rw-r--r--  1 root root   41051 Oct  1 18:50 php-imap-5.2.0-cli_cgi.rhe4x.1.0.2.x86_64.rpm
-rw-r--r--  1 root root   22865 Oct  1 18:50 php-ldap-5.2.0-cli_cgi.rhe4x.1.0.2.x86_64.rpm
-rw-r--r--  1 root root 1018842 Oct  1 18:50 php-mbstring-5.2.0-cli_cgi.rhe4x.1.0.2.x86_64.rpm
-rw-r--r--  1 root root   17406 Oct  1 18:50 php-mcrypt-5.2.0-cli_cgi.rhe4x.1.0.2.x86_64.rpm
-rw-r--r--  1 root root    7710 Oct  1 18:50 php-mhash-5.2.0-cli_cgi.rhe4x.1.0.2.x86_64.rpm
-rw-r--r--  1 root root   26098 Oct  1 18:50 php-mysql-5.2.0-cli_cgi.rhe4x.1.0.2.x86_64.rpm
-rw-r--r--  1 root root   30459 Oct  1 18:50 php-ncurses-5.2.0-cli_cgi.rhe4x.1.0.2.x86_64.rpm
-rw-r--r--  1 root root   31546 Oct  1 18:50 php-odbc-5.2.0-cli_cgi.rhe4x.1.0.2.x86_64.rpm
-rw-r--r--  1 root root    2420 Oct  1 18:50 php-pear-5.2.0-cli_cgi.rhe4x.1.0.2.x86_64.rpm
-rw-r--r--  1 root root   45891 Oct  1 18:50 php-pgsql-5.2.0-cli_cgi.rhe4x.1.0.2.x86_64.rpm
-rw-r--r--  1 root root   14905 Oct  1 18:50 php-snmp-5.2.0-cli_cgi.rhe4x.1.0.2.x86_64.rpm
-rw-r--r--  1 root root   44595 Oct  1 18:50 php-xmlrpc-5.2.0-cli_cgi.rhe4x.1.0.2.x86_64.rpm

To install the RPM do :

1- Download it
wget http://clust01-carat01.carat-hosting.com/srpm/php5-5.2.0-CLI_CGI.rhe4x.1.0.2.src.rpm

2- Rebuild it
rpmbuild --rebuild --with<yourarch> php-5.2.0-cli_cgi.rhe4x.1.0.3.src.rpm

Your arch mightr be
rht90
cos3x
fdr10
fdr20
fdr30
fdr40
whb3x
rhe2x
rhe3x
rhe4x (also for cos4x)

3- Install it
rpm -ivh /usr/src/redhat/RPMS/i386 ou x86_64/php-5.2.0-cli_cgi.rhe4x.1.0.2.rpm

If you want ot give to your users the ability to use PHP5 as CGI just update their vhost conf file or create an .htaccess file with something like this:

AddHandler x-httpd-php5 .php5
Action x-httpd-php5 /php5/php-cgi
ScriptAlias /php5/ /home/account/domaine/html/php5/

in the docroot of the user create a dir named php5 and copy in it the /usr/bin/php5.2.0/php-cgi
Chnage the owner of this file to allow suexec

Here is the reslult of phpinfo.php5 file in the php5 dir
http://clust01-carat01.carat-hosting.com/phpinfo.php5

Hope it helps some of you

Pascal

Carat Hosting : H?bergement de sites Internet

ps : after rebuild process you^ll also have others rpms available to install depending on which extensions you’d like to install with php5

php-5.1.2-cli_cgi.rhe4x.1.0.3.x86_64.rpm           php-mysql-5.1.2-cli_cgi.rhe4x.1.0.3.x86_64.rpm
php-devel-5.1.2-cli_cgi.rhe4x.1.0.3.x86_64.rpm     php-ncurses-5.1.2-cli_cgi.rhe4x.1.0.3.x86_64.rpm
php-imap-5.1.2-cli_cgi.rhe4x.1.0.3.x86_64.rpm      php-odbc-5.1.2-cli_cgi.rhe4x.1.0.3.x86_64.rpm
php-ldap-5.1.2-cli_cgi.rhe4x.1.0.3.x86_64.rpm      php-pear-5.1.2-cli_cgi.rhe4x.1.0.3.x86_64.rpm
php-mbstring-5.1.2-cli_cgi.rhe4x.1.0.3.x86_64.rpm  php-pgsql-5.1.2-cli_cgi.rhe4x.1.0.3.x86_64.rpm
php-mcrypt-5.1.2-cli_cgi.rhe4x.1.0.3.x86_64.rpm    php-snmp-5.1.2-cli_cgi.rhe4x.1.0.3.x86_64.rpm
php-mhash-5.1.2-cli_cgi.rhe4x.1.0.3.x86_64.rpm     php-xmlrpc-5.1.2-cli_cgi.rhe4x.1.0.3.x86_64.rpm

Pascal

Carat Hosting : H?bergement de sites Internet

A note about
AddHandler x-httpd-php5 .php5
Action x-httpd-php5 /php5/php-cgi
ScriptAlias /php5/ /home/account/domaine/html/php5/

We copy the CGI php5 binary in the docroot of the user to allow suexecusergroup to work fine. Indeed we just could do

AddHandler x-httpd-php5 .php5
Action x-httpd-php5 /php5/php-cgi
ScriptAlias /php5/ /usr/bin/php5

but in this case you’ll have to comment and disallow the suexecusergroup directive in the vhost config file of all users whom like to use php5. As the binary is not owned by the user suexec will reject the execution of the php5 binary

It’s why we :

  • copy the php-cgi binary in the docroot of the user
  • chown it to the user
  • chmod it to 550

If your user just like to use PHP5 and no PHP4 script they could create an .htacess file with this line :
AddHandler x-httpd-php5 .php

If your user just like to use PHP5 as main php PHP4 as second one they could create an .htacess file with this line :
AddHandler x-httpd-php5 .php
AddType application/x-httpd-php .php4 .php

We use it for a lot of clients and it works great.

We decided to continue to use Suexec with PHP5 as CGI to not allow somebody to create and run a PHP script in the docroot of a user not owned by this user

Pascal

Carat Hosting : H?bergement de sites Internet

More information to have this RPM PHP5 isntalled with suPHP here

http://interworx.com/forums/showpost.php?p=10251&postcount=3

UPDATES :

Here is the SRPM for the php5.2.0 Version. http://clust01-carat01.carat-hosting.com/srpm/php5-5.2.0-CLI_CGI.rhe4x.1.0.2.src.rpm

Binaries are installed in /usr/bin/php5.2.0/

Here is a phpinfo of php5.2.0 http://clust01-carat01.carat-hosting.com/phpinfo.php5
Here is a phpinfo of php4 installed on the same box http://clust01-carat01.carat-hosting.com/phpinfo.php

Pascal

Carat Hosting : H?bergement de sites Internet

G’Day Pascal,

I am salivating at the thought of using your SRPM’s - but none of your links resolve from China, HK or Australia? :-\

Cheers,
RF.

Arff sorry

Here is the link : http://clust01-carat01.carat-hosting.com/srpm/

Pascal

Actually,

Do you still have the 5.1.6 src rpm handy?

Drupal for one doesn’t like 5.2. :frowning:

Cheers,
RF.

Actually the 5.0.4 is the best version as that is what is in centos plus…

[QUOTE=sinopeach;11470]Actually,

Do you still have the 5.1.6 src rpm handy?

Drupal for one doesn’t like 5.2. :frowning:

Cheers,
RF.[/QUOTE]

What you can do is

  • donwload our php5.2 src.rpm

  • find and download a php5.1.6.tar.gz

  • Install the src.rpm

rpm -ivh /your/path/php5-5.2.0…src.rpm

  • Copy the php5.1.6.tar.gz in the /usr/src/redhat/SOURCES/ directory

  • Change the php5.spec file in /usr/src/redhat/SPEC/

vi /usr/src/redhat/SPEC/php.spec

  • update the second line and enter 5.1.6 rather than 5.2.0

%define pversion 5.1.6

  • Rebuild the rpm

cd /usr/src/redhat/SPEC/
rpmbuild -ba --with rhe4x ./php5.spec

If everything goes well it will create all php5 and php5 modules rpms in /usr/src/redhat/RPMS/yourdistro/

And the src.rpm in /usr/src/redhat/SRPMS/

Hope this help

Pascal

Ok going to give it a try - I guess it is just reuisng your .spec/makefile ? Which is really where your magic has come from? :wink:

very informative post…thanks buddy…

Ok - got it to compile and work - needed to repackage the .tar.gz to place in a php5 directory instead of php to get the rpmbuild to work.

All works OK test.candishosting.com.cn/test.php but I can’t seem to get the mysql module to load and work (rpm is installed) - mysqli appears fine though.

I noticed in the shell a:

/chroot/usr/lib/php4/mysql.so

So I made a:

/chroot/usr/lib/php5/ directory and then:

cp /usr/lib/php5/mysql.so /chroot/usr/lib/php5/

But still no luck. There are numerous /etc/php.ini /etc/php.d /etc/php5 /etcphp5/php.d and /etc/php-cli.ini files… all have mysql correcyty defined…

What am I missing?

Cheers,
RF.

I ran php5 manually and got this:

[root@www-d01 php.d]# cd /usr/bin/
[root@www-d01 bin]# ./php5 -m
PHP Warning: PHP Startup: Unable to load dynamic library ‘/usr/lib/php/modules/imap.so’ - /usr/lib/php/modules/imap.so: cannot open shared object file: No such file or directory in Unknown on line 0
PHP Warning: PHP Startup: Unable to load dynamic library ‘/usr/lib/php/modules/ldap.so’ - /usr/lib/php/modules/ldap.so: cannot open shared object file: No such file or directory in Unknown on line 0
PHP Warning: PHP Startup: Unable to load dynamic library ‘/usr/lib/php/modules/mbstring.so’ - /usr/lib/php/modules/mbstring.so: cannot open shared object file: No such file or directory in Unknown on line 0
PHP Warning: PHP Startup: Unable to load dynamic library ‘/usr/lib/php/modules/mcrypt.so’ - /usr/lib/php/modules/mcrypt.so: cannot open shared object file: No such file or directory in Unknown on line 0
PHP Warning: PHP Startup: Unable to load dynamic library ‘/usr/lib/php/modules/mhash.so’ - /usr/lib/php/modules/mhash.so: cannot open shared object file: No such file or directory in Unknown on line 0
PHP Warning: PHP Startup: Unable to load dynamic library ‘/usr/lib/php/modules//usr/lib/php5/mysql.so’ - /usr/lib/php/modules//usr/lib/php5/mysql.so: cannot open shared object file: No such file or directory in Unknown on line 0
PHP Warning: PHP Startup: Unable to load dynamic library ‘/usr/lib/php/modules/ncurses.so’ - /usr/lib/php/modules/ncurses.so: cannot open shared object file: No such file or directory in Unknown on line 0
PHP Warning: PHP Startup: Unable to load dynamic library ‘/usr/lib/php/modules/odbc.so’ - /usr/lib/php/modules/odbc.so: cannot open shared object file: No such file or directory in Unknown on line 0
PHP Warning: PHP Startup: Unable to load dynamic library ‘/usr/lib/php/modules/xmlrpc.so’ - /usr/lib/php/modules/xmlrpc.so: cannot open shared object file: No such file or directory in Unknown on line 0
[PHP Modules]
bcmath
bz2
calendar
ctype
curl
date
dba
dom
exif
ftp
gd
gettext
gmp
hash
iconv
libxml
mysqli
openssl
pcre
PDO
pdo_mysql
pdo_pgsql
posix
readline
Reflection
session
shmop
SimpleXML
soap
sockets
SPL
SQLite
standard
sysvsem
sysvshm
tokenizer
xml
xmlreader
xmlwriter
xsl
zlib

[Zend Modules]

It seems that the php5 modules all can’t be loaded - mbstring, mysql, etc…

What needs to be changed in the specfile/rpmbuild process to correct this… And yes ALL the new rpms for these modules WERE installed! :wink:

I mean, the support rpms were all made and install fine (ivh) however there is something wrong in a config file somewhere… ?

I just put the carat hosting 5.2 php back in and the results are the same. So there is a definate issue with this approach to use PHP5.x.x with iworx…

[root@www-d01 i386]# /usr/bin/php5 -m

PHP Warning: PHP Startup: Unable to load dynamic library ‘/usr/lib/php/modules/imap.so’ - /usr/lib/php/modules/imap.so: cannot open shared object file: No such file or directory in Unknown on line 0
PHP Warning: PHP Startup: Unable to load dynamic library ‘/usr/lib/php/modules/ldap.so’ - /usr/lib/php/modules/ldap.so: cannot open shared object file: No such file or directory in Unknown on line 0
PHP Warning: PHP Startup: Unable to load dynamic library ‘/usr/lib/php/modules/mbstring.so’ - /usr/lib/php/modules/mbstring.so: cannot open shared object file: No such file or directory in Unknown on line 0
PHP Warning: PHP Startup: Unable to load dynamic library ‘/usr/lib/php/modules/mcrypt.so’ - /usr/lib/php/modules/mcrypt.so: cannot open shared object file: No such file or directory in Unknown on line 0
PHP Warning: PHP Startup: Unable to load dynamic library ‘/usr/lib/php/modules/mhash.so’ - /usr/lib/php/modules/mhash.so: cannot open shared object file: No such file or directory in Unknown on line 0
PHP Warning: PHP Startup: Unable to load dynamic library ‘/usr/lib/php/modules/mysql.so’ - /usr/lib/php/modules/mysql.so: cannot open shared object file: No such file or directory in Unknown on line 0
PHP Warning: PHP Startup: Unable to load dynamic library ‘/usr/lib/php/modules/ncurses.so’ - /usr/lib/php/modules/ncurses.so: cannot open shared object file: No such file or directory in Unknown on line 0
PHP Warning: PHP Startup: Unable to load dynamic library ‘/usr/lib/php/modules/odbc.so’ - /usr/lib/php/modules/odbc.so: cannot open shared object file: No such file or directory in Unknown on line 0
PHP Warning: PHP Startup: Unable to load dynamic library ‘/usr/lib/php/modules/pgsql.so’ - /usr/lib/php/modules/pgsql.so: cannot open shared object file: No such file or directory in Unknown on line 0
PHP Warning: PHP Startup: Unable to load dynamic library ‘/usr/lib/php/modules/snmp.so’ - /usr/lib/php/modules/snmp.so: cannot open shared object file: No such file or directory in Unknown on line 0
PHP Warning: PHP Startup: Unable to load dynamic library ‘/usr/lib/php/modules/xmlrpc.so’ - /usr/lib/php/modules/xmlrpc.so: cannot open shared object file: No such file or directory in Unknown on line 0
[PHP Modules]
bcmath
bz2
calendar
ctype
curl
date
dba
dom
exif
filter
ftp
gd
gettext
gmp
hash
iconv
json
libxml
mysqli
openssl
pcre
PDO
pdo_mysql
pdo_pgsql
pdo_sqlite
posix
readline
Reflection
session
shmop
SimpleXML
soap
sockets
SPL
SQLite
standard
sysvsem
sysvshm
tokenizer
xml
xmlreader
xmlwriter
xsl
zlib

[Zend Modules]

[root@www-d01 i386]#

Look in /usr/lib/php5 and see if the modules are installed there. If so, then, look in /etc/php.ini and make sure the extension_dir= matches.

Socheat

I just put the carat hosting 5.2 php back in and the results are the same. So there is a definate issue with this approach to use PHP5.x.x with iworx…

I use iworx and PHP5.2.0/PHP4.4.4 and suPHP, all works well together

Do you have a x86_64 box or i386 ?

This rpm is created to ONLY install the CLI and CGI version of PHP5. The sapi won’t be installed. So basicly this rpm and src.rpm has been created to install PHP5 on a box already running PHP4

For this reason all files are going in a php5 directory rather than php (which is used for PHP4 install)

So if you have a i386 box.

Look in /usr/lib/php5/ directory. You should have all your installed module there

drwxr-xr-x 2 root root 4096 f?v 5 11:14 build
-rwxr-xr-x 1 root root 1946046 f?v 5 11:11 mbstring.so
-rwxr-xr-x 1 root root 63141 f?v 5 11:11 mysql.so
-rwxr-xr-x 1 root root 398763 d?c 12 13:44 pdf.so

Also as Socheat told you, look in /etc/php5/php.ini and verify that extension_dir= matches.
I have this, because lmy box is a 64 bits,

extension_dir = “/usr/lib64/php5”

if yours is a 32Bits then you should have

extension_dir = “/usr/lib/php5”

Pascal

[QUOTE=sinopeach;11510]I ran php5 manually and got this:

[root@www-d01 php.d]# cd /usr/bin/
[root@www-d01 bin]# ./php5 -m
PHP Warning: PHP Startup: Unable to load dynamic library ‘/usr/lib/php/modules/imap.so’ - /usr/lib/php/modules/imap.so: cannot open shared object file: No such file or directory in Unknown on line 0
PHP Warning: PHP Startup: Unable to load dynamic library ‘/usr/lib/php/modules/ldap.so’ - /usr/lib/php/modules/ldap.so: cannot open shared object file: No such file or directory in Unknown on line 0
[/QUOTE]

What is the binary php5 ?
could you please provide

ls -l /usr/bin/php5

It looks like you don’t use the binary installed by our rpm. Indeed, the rpm install all php5 modules in /usr/lib(64)/php5

Pascal