Run php5.3 and php 5.2 on cPanel servers

Quags

Administrator
Staff member
PHP 5.3 is the current supported version of PHP, so I recommend running this version. However, sometimes more time is needed for your clients to migrate their code to php 5.3. For example zendoptimzer encoder scripts will not run on php 5.3, because they are no longer in the correct encoded format. You can follow the below to give the option of php 5.2 in addition to 5.3. As of this writing the PHP 5.2 source is patched against known exploits.

The below is for cPanel based servers

First, download php-5.2.17-backports-20120526.tar.gz from http://mirror.trouble-free.net/sources/php-5.2.17-backports-20120526.tar.gz

Code:
wget http://mirror.trouble-free.net/sources/php-5.2.17-backports-20120526.tar.gz
Untar this with

Code:
tar -zxvf php-5.2.17-backports-20120526.tar.gz
move to the new directory

Code:
cd php-5.2.17
Now you need to compile it. This varies based on your current php configuration. The main difference is the prefix changes, you do not run it with apxs and add enable-cgi and --enable-force-cgi-redirect

Code:
./configure --enable-bcmath --enable-calendar --enable-ftp --enable-gd-native-ttf --enable-libxml --enable-magic-quotes --enable-mbstring --enable-pdo=shared --enable-sockets --enable-zend-multibyte --prefix=//opt/php5 --with-curl=/opt/curlssl/ --with-curlwrappers --with-freetype-dir=/usr --with-gd --with-gettext --with-imap=/opt/php_with_imap_client/ --with-imap-ssl=/usr --with-jpeg-dir=/usr --with-kerberos --with-libxml-dir=/opt/xml2/ --with-mcrypt=/opt/libmcrypt/ --with-mm=/opt/mm/ --with-mysql=/usr --with-mysql-sock=/var/lib/mysql/mysql.sock --with-openssl=/usr --with-openssl-dir=/usr --with-pcre-regex=/opt/pcre --with-pdo-mysql=shared --with-pdo-sqlite=shared --with-png-dir=/usr --with-sqlite=shared --with-xpm-dir=/usr --with-zlib --with-zlib-dir=/usr --enable-inline-optimization --disable-debug --enable-cgi --enable-force-cgi-redirect
Then run

Code:
 make && make install
The binary will be installed in /opt/php5/bin/php-cgi

Now you need the wrapper for cpanel, so create the file /usr/local/cpanel/cgi-sys/php5217

Code:
#!/bin/sh
 
exec /opt/php5/bin/php-cgi
The permissions need to be set to 755 and group wheel

Code:
chmod 755 /usr/local/cpanel/cgi-sys/php5217
chgrp wheel /usr/local/cpanel/cgi-sys/php5217

Restart apache when done. Finally to use this you just need to edit .htaccess on a site that needs php 5.2.17. In .htaccess add

Code:
AddHandler php-script .php
Action php-script /cgi-sys/php5217
 

ramiss

New Member
Hello,

I want to thank you for this. I have the latest cPanel running on CentOS. With a few modifications (installing mm libraries etc) I completed this, however, I now receive the following error on the sites that have the new .htaccess file handling php.

I am mostly a Window Admin and still new to linux. Can you help point me in the right direction. I did restart apache and all of the above steps completed successfully.

Thanks in advance!

Richard


Internal Server Error

The server encountered an internal error or misconfiguration and was unable to complete your request.
Please contact the server administrator, xxxx@xxxx.com and inform them of the time the error occurred, and anything you might have done that may have caused the error.

More information about this error may be available in the server error log.
Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.

Apache/2.2.23 (Unix) mod_ssl/2.2.23 OpenSSL/1.0.0-fips mod_auth_passthrough/2.1 mod_bwlimited/1.4 FrontPage/5.0.2.2635 Server at www.xxx.com Port 80
 

Quags

Administrator
Staff member
Open the url with the 500 error message, while watching the error log - I would use tail -f /usr/local/apache/logs/error_log and it should give a better reason for the error. Paste the error here.

Make sure the new PHP binary is owned by root (it should be 755 permissions as well)
 

ramiss

New Member
Thanks for the fast response!

I get the following:

[Sat Nov 24 12:12:53 2012] [error] [client 70.173.87.7] php5217: line 2: /opt/php5/bin/php-cgi: No such file or directory
[Sat Nov 24 12:12:53 2012] [error] [client 70.173.87.7] php5217: line 2: exec: /opt/php5/bin/php-cgi: cannot execute: No such file or directory
[Sat Nov 24 12:12:53 2012] [error] [client 70.173.87.7] Premature end of script headers: php5217
[Sat Nov 24 12:12:53 2012] [error] [client 70.173.87.7] File does not exist: /disk1/home/meganpol/public_html/500.shtml
[Sat Nov 24 12:12:53 2012] [error] [client 70.173.87.7] File does not exist: /disk1/home/meganpol/public_html/favicon.ico
[Sat Nov 24 12:12:53 2012] [error] [client 70.173.87.7] File does not exist: /disk1/home/meganpol/public_html/404.shtml
Richard
 

ramiss

New Member
I have confirmed that there is no binary in the folder /opt/php5/bin/php-cgi even after the make ended successfully. Does this get put somewhere else on a CentOS system?
 

ramiss

New Member
it does exist, just no php-cgi file.

Below is the complete config file. Another strange thing is that I searched the server and found 1 5.2 php-cgi under
/usr/local/cpanel/3rdparty/etc/

So I changed the /usr/local/cpanel/cgi-sys/php5217 path to that and I have it working!

I would still love to know why this didn't go to plan, or is that 3rdparty directory where it got installed?


./configure --enable-bcmath --enable-calendar --enable-ftp --enable-gd-native-ttf --enable-libxml --enable-magic-quotes --enable-mbstring --enable-pdo=shared --enable-sockets --enable-zend-multibyte --prefix=//opt/php5 --with-curl=/opt/curlssl/ --with-curlwrappers --with-freetype-dir=/usr --with-gd --with-gettext --with-imap=/opt/php_with_imap_client/ --with-imap-ssl=/usr --with-jpeg-dir=/usr --with-kerberos --with-libxml-dir=/opt/xml2/ --with-mcrypt=/opt/libmcrypt/ --with-mm=/opt/mm/ --with-mysql=/usr --with-mysql-sock=/var/lib/mysql/mysql.sock --with-openssl=/usr --with-openssl-dir=/usr --with-pcre-regex=/opt/pcre --with-pdo-mysql=shared --with-pdo-sqlite=shared --with-png-dir=/usr --with-sqlite=shared --with-xpm-dir=/usr --with-zlib --with-zlib-dir=/usr --enable-inline-optimization --disable-debug --enable-cgi --enable-force-cgi-redirect --with-openssl --with-libdir=lib64
 

Quags

Administrator
Staff member
Glad you have it working. My guess, is that php did not compile (it probably error-ed out)
 

ramiss

New Member
Ok, thank you. I may run this again just to watch more closely for an error.

I appreciate all of your help!
 

Quags

Administrator
Staff member
UPDATE: If you get the error
Node.c: In function 'dom canonicalization':

use this patch

Code:
--- ext/dom/node.c 2012-08-06 17:49:48.826716692 +0800
+++ ext/dom/node.c 2012-08-06 17:52:47.633484660 +0800
@@ -1895,9 +1895,17 @@ static void dom_canonicalization(INTERNA
RETVAL_FALSE;
} else {
if (mode == 0) {
+#ifdef LIBXML2_NEW_BUFFER
+ ret = xmlOutputBufferGetSize(buf);
+#else
ret = buf->buffer->use;
+#endif
if (ret > 0) {
+#ifdef LIBXML2_NEW_BUFFER
+ RETVAL_STRINGL((char *) xmlOutputBufferGetContent(buf), ret, 1);
+#else
RETVAL_STRINGL((char *) buf->buffer->content, ret, 1);
+#endif
} else {
RETVAL_EMPTY_STRING();
}
--- ext/dom/documenttype.c 2012-08-06 18:02:16.019640870 +0800
+++ ext/dom/documenttype.c 2012-08-06 18:06:16.612228905 +0800
@@ -205,7 +205,13 @@ int dom_documenttype_internal_subset_rea
if (buff != NULL) {
xmlNodeDumpOutput (buff, NULL, (xmlNodePtr) intsubset, 0, 0, NULL);
xmlOutputBufferFlush(buff);
+
+#ifdef LIBXML2_NEW_BUFFER
+ ZVAL_STRINGL(*retval, xmlOutputBufferGetContent(buff),
+ xmlOutputBufferGetSize(buff), 1);
+#else
ZVAL_STRINGL(*retval, buff->buffer->content, buff->buffer->use, 1);
+#endif
(void)xmlOutputBufferClose(buff);
return SUCCESS;
}
--- ext/simplexml/simplexml.c 2012-08-06 18:10:44.621017026 +0800
+++ ext/simplexml/simplexml.c 2012-08-06 18:12:48.016270419 +0800
@@ -1417,7 +1417,12 @@ SXE_METHOD(asXML)

xmlNodeDumpOutput(outbuf, (xmlDocPtr) sxe->document->ptr, node, 0, 0, ((xmlDocPtr) sxe->document->ptr)->encoding);
xmlOutputBufferFlush(outbuf);
+#ifdef LIBXML2_NEW_BUFFER
+ RETVAL_STRINGL((char *)xmlOutputBufferGetContent(outbuf),
+ xmlOutputBufferGetSize(outbuf), 1);
+#else
RETVAL_STRINGL((char *)outbuf->buffer->content, outbuf->buffer->use, 1);
+#endif
xmlOutputBufferClose(outbuf);
}
} else {
 
Top