Although Drupals 7+ run smoothly on PHP 5.3, Drupal 6 still feels much better with PHP 5.2. Even though D6 core is compatible with PHP 5.3 for quite some time now, a lot of contributes modules still get nasty hiccup when asked to run on the newer version. Therefore developing for both D7 and D6 at the same time becomes much less painful when running both versions of PHP in parallel.

One way of doing it is using mod_php5 Apache module to serve PHP 5.3 applications, while running PHP 5.2 applications using fastcgimodule. Under Ubuntu 12.04 this can be achieved by installing PHP 5.3 from the repositories and manually compiling and installing PHP 5.2 afterwards.

Installing PHP 5.3 from repositories is fairly easy process, which you most probably already have under your belt, so let's just say that it looks more or less like this:

sudo apt-get install php5 php5-common php5-cli php5-dev php5-mysql phpmyadmin php5-pgsql phppgadmin php5-gd php5-mcrypt php5-curl php-pear libapache2-mod-php5 php5-xdebug php5-codesniffer

What is much more interesting though, and what this post will focus on, is how to add PHP 5.2 to the whole picture and make both those versions work nicely together.

Please note that this tutorial is for Apache's name-based virtual hosts, and essentially leaves PHP 5.3 enabled globally while allowing to use PHP 5.2 on specific, selected virtual hosts only.

Download PHP sources

Let's then start with downloading PHP 5.2 sources from Unsupported Historical Releases list.

I have originally started with version 5.2.10 (as it is the same version that we have on our production servers), but then was stopped short by OpenSSL error during configuration stage:

/usr/include/openssl/conf.h:132:7: note: expected 'struct lhash_st_CONF_VALUE *' but argument is of type 'int *'
make: *** [ext/openssl/openssl.lo] Error 1

to which I was not able to find any good fix (relatively easy to apply anyway), so finally ended up with the most recent version from 5.2 branch - 5.2.17, where those errors haven't occured anymore.

Let's then download and uncompress PHP sources into ~/Downloads/php-5.2.17 directory:

mkdir -p ~/Downloads/php-5.2.17
cd ~/Downloads/php-5.2.17
wget http://museum.php.net/php5/php-5.2.17.tar.gz
tar
 zxf php-5.2.17.tar.gz

Configure

Time to configure the package. Example ./configure call could look as follows:

sudo ./configure \
  --prefix=/usr/share/php52 \
  --datadir=/usr/share/php52 \
  --mandir=/usr/share/man \
  --bindir=/usr/bin/php52 \
  --with-libdir=lib64 \
  --includedir=/usr/include \
  --sysconfdir=/etc/php52/apache2 \
  --with-config-file-path=/etc/php52/cli \
  --with-config-file-scan-dir=/etc/php52/conf.d \
  --localstatedir=/var \
  --disable-debug \
  --with-regex=php \
  --disable-rpath \
  --disable-static \
  --disable-posix \
  --with-pic \
  --with-layout=GNU \
  --with-pear=/usr/share/php \
  --enable-calendar \
  --enable-sysvsem \
  --enable-sysvshm \
  --enable-sysvmsg \
  --enable-bcmath \
  --with-bz2 \
  --enable-ctype \
  --with-db4 \
  --without-gdbm \
  --with-iconv \
  --enable-exif \
  --enable-ftp \
  --enable-cli \
  --with-gettext \
  --enable-mbstring \
  --with-pcre-regex=/usr \
  --enable-shmop \
  --enable-sockets \
  --enable-wddx \
  --with-libxml-dir=/usr \
  --with-zlib \
  --with-kerberos=/usr \
  --with-openssl=/usr \
  --enable-soap \
  --enable-zip \
  --with-mhash \
  --with-exec-dir=/usr/lib/php5/libexec \
  --without-mm \
  --with-curl=shared,/usr \
  --with-zlib-dir=/usr \
  --with-gd=shared,/usr \
  --enable-gd-native-ttf \
  --with-gmp=shared,/usr \
  --with-jpeg-dir=shared,/usr \
  --with-xpm-dir=shared,/usr/X11R6 \
  --with-png-dir=shared,/usr \
  --with-freetype-dir=shared,/usr \
  --with-ttf=shared,/usr \
  --with-t1lib=shared,/usr \
  --with-ldap=shared,/usr \
  --with-mysql=shared,/usr \
  --with-mysqli=shared,/usr/bin/mysql_config \
  --with-pgsql=shared,/usr \
  --with-pspell=shared,/usr \
  --with-unixODBC=shared,/usr \
  --with-xsl=shared,/usr \
  --with-snmp=shared,/usr \
  --with-sqlite=shared,/usr \
  --with-tidy=shared,/usr \
  --with-xmlrpc=shared \
  --enable-pdo=shared \
  --without-pdo-dblib \
  --with-pdo-mysql=shared,/usr \
  --with-pdo-pgsql=shared,/usr \
  --with-pdo-odbc=shared,unixODBC,/usr \
  --with-pdo-dblib=shared,/usr \
  --enable-force-cgi-redirect  --enable-fastcgi \
  --with-libdir=/lib/x86_64-linux-gnu \
  --with-pdo-sqlite=shared \
  --with-sqlite=shared \
  --enable-ipv6 \
  --with-mcrypt \
  --with-imap-ssl

Obviously you need to adapt it to yur specific needs by adding and/or removing relevant options. You can read more about options you want (or don't want) to include in PHP core configure options documentation.

Configure errors

Now, that probably didn't work out of the box, did it?

In most cases quite a lot of dependencies will be missing. You can try to take care of them in one shot, if you don't care too much about installing a little too much compared to what is really needed:

sudo apt-get install libxml2-dev libpcre3-dev libbz2-dev libcurl4-openssl-dev libdb4.8-dev libjpeg-dev libpng12-dev libxpm-dev libfreetype6-dev libmysqlclient-dev postgresql-server-dev-9.1 libt1-dev libgd2-xpm-dev libgmp-dev libsasl2-dev libmhash-dev unixodbc-dev freetds-dev libpspell-dev libsnmp-dev libtidy-dev libxslt1-dev libmcrypt-dev

You can also remedy missing dependencies one by one, and install only those packages that are really needed.

Let's go through some of the possible errors then (you can skip to the next section if your ./configure finished without any errors and displayed nice Thank you for using PHP at the end of its execution):

  • configure: error: xml2-config not found. Please check your libxml2 installation.

    This error message suggests you don't have libxml2 installed. What it really means though is that you don't have its developmentversion installed!

    Let's then search what we can find in available packages, what could help us resolve this issue:

    $ apt-cache search libxml2 | grep dev
    libcroco3-dev - Cascading Style Sheet (CSS) parsing and manipulation toolkit
    libxml++2.6-dev - C++ interface to the GNOME XML library (libxml2)
    libxml2-dev - Development files for the GNOME XML library
    libgdome2-cpp-smart-dev - C++ bindings for GDome2 DOM implementation
    libgdome2-dev - Development files for libgdome2
    libgdome2-ocaml-dev - OCaml bindings for GDome2 DOM implementation
    libgtkmathview-dev - rendering engine for MathML documents
    libsp-gxmlcpp-dev - S+P C++ wrapper for Gnome libxml2/libxslt

    What we are interested in here is libxml2-dev, let's install it then:

    sudo apt-get install libxml2-dev

    The same procedure applies to all other missing libraries as well, so I will include only final install calls from now on.

  • configure: error: Could not find pcre.h in /usr

    sudo apt-get install libpcre3-dev
  • configure: error: Please reinstall the BZip2 distribution

    sudo apt-get install libbz2-dev
  • configure: error: Please reinstall the libcurl distribution - easy.h should be in /include/curl/

    sudo apt-get install libcurl4-openssl-dev
  • configure: error: DBA: Could not find necessary header file(s).
    checking for db4 major version... configure: error: Header contains different version

    sudo apt-get install libdb4.8-dev
  • configure: error: libjpeg.(a|so) not found.

    sudo apt-get install libjpeg-dev
  • configure: error: libpng.(a|so) not found.

    sudo apt-get install libpng12-dev
  • configure: error: libXpm.(a|so) not found.

    sudo apt-get install libxpm-dev
  • configure: error: freetype.h not found.

    sudo apt-get install libfreetype6-dev
  • You need to install postgresql-server-dev-X.Y for building a server-side extension or libpq-dev for building a client-side application.
    configure: error: Cannot find libpq-fe.h. Please specify correct PostgreSQL installation path

    sudo apt-get install postgresql-server-dev-9.1

    Make sure you check result of apt-cache search especially in case of this error, as there could be later version of PostgreSQL available.

  • checking for FreeType 1 support... no - FreeType 2.x is to be used instead
    configure: error: Your t1lib distribution is not installed correctly. Please reinstall it.

    sudo apt-get install libt1-dev
  • configure: error: Unable to find gd.h anywhere under /usr

    sudo apt-get install libgd2-xpm-dev
  • configure: error: Unable to locate gmp.h

    sudo apt-get install libgmp-dev
  • configure: error: Cannot find MySQL header files under /usr.
    Note that the MySQL client library is not bundled anymore!

    sudo apt-get install libmysqlclient-dev
  • configure: error: sasl.h not found!

    sudo apt-get install libsasl2-dev
  • configure: error: Please reinstall libmhash - I cannot find mhash.h

    sudo apt-get install libmhash-dev
  • checking for unixODBC support... configure: error: ODBC header file '/usr/include/sqlext.h' not found!

    sudo apt-get install unixodbc-dev
  • configure: error: Directory /usr is not a FreeTDS installation directory

    sudo apt-get install freetds-dev
  • configure: error: Cannot find pspell

    sudo apt-get install libpspell-dev
  • configure: error: SNMP sanity check failed. Please check config.log for more information.

    sudo apt-get install libsnmp-dev
  • configure: error: Cannot find libtidy

    sudo apt-get install libtidy-dev
  • configure: error: xslt-config not found. Please reinstall the libxslt >= 1.1.0 distribution

    sudo apt-get install libxslt1-dev
  • configure: error: mcrypt.h not found. Please reinstall libmcrypt.

    sudo apt-get install libmcrypt-dev
  • configure: error: Cannot find OpenSSL's libraries

    Add following switch to your ./configure options (optionally updating the path to reflect your system):

    --with-libdir=/lib/x86_64-linux-gnu
  • configure: error: You've configured extension pdo_sqlite to build statically, but it depends on extension pdo, which you've configured to build shared. You either need to build pdo_sqlite shared or build pdo statically for the build to be successful.

    Add following switches to your ./configure options:

      --with-pdo-sqlite=shared
      --with-sqlite=shared

Make

Everything configured properly and without errors? Then it is time to compile (and go for a coffee while it is running):

sudo make

Now sipping your coffee wait for approaching errors...

Make errors

Yes, things can go awry here too. And most probably will.

There are two make errors and one warning you are most probably going to experience:

  • ext/openssl/.libs/xp_ssl.o: In function `php_openssl_setup_crypto':
    ext/openssl/xp_ssl.c:357: undefined reference to `SSLv2_server_method'
    ext/openssl/xp_ssl.c:337: undefined reference to `SSLv2_client_method'

    This is due to PHP bug#54736, which could be easily resolved using patch debian_patches_disable_SSLv2_for_openssl_1_0_0.patchattached to that bug report.

    Download this patch to your ~/Downloads/php-5.2.17 directory, and execute:

    patch -p1 < debian_patches_disable_SSLv2_for_openssl_1_0_0.patch.patch

    You should see friendly success messages like these:

    patching file ext/openssl/xp_ssl.c
    Hunk #1 succeeded at 332 (offset 4 lines).
    Hunk #2 succeeded at 354 (offset 4 lines).
    Hunk #3 succeeded at 583 (offset -50 lines).
    Hunk #4 succeeded at 819 (offset -98 lines).
  • ext/gmp/gmp.c: In function ‘zif_gmp_random’:
    ext/gmp/gmp.c:1399:69: error: ‘__GMP_BITS_PER_MP_LIMB’ undeclared (first use in this function)
    ext/gmp/gmp.c:1399:69: note: each undeclared identifier is reported only once for each function it appears in

    This time it's PHP bug#50990. In one of comments there susan dot smith dot dev at gmail dot com suggested solution which works and does its magic:

    I solved replacing the outdated __GMP_BITS_PER_MP_LIMB defined constant with GMP_LIMB_BITS. The latter is present in all previous versions, and MPIR define it too.

    You have to edit file ext/gmp/gmp.c and replace one occurence of __GMP_BITS_PER_MP_LIMB with GMP_LIMB_BITS, in my case it was in line 1399.

  • ext/zip/lib/.libs/zip_dirent.o: In function `memset':
    /usr/include/x86_64-linux-gnu/bits/string3.h:82: warning: memset used with constant zero length parameter; this could be due to transposed parameters

    Finally PHP bug#53568, with a pretty easy fix: edit file ext/zip/lib/zip_dirent.c and in line 478 replace:

    memset(&tm, sizeof(tm), 0);

    with

    memset(&tm, 0, sizeof(tm));

There, no more errors!

Install

The simplest way of installing your new shiny PHP 5.2 now is:

sudo make install

Alternatively, if you plan to repeat the same installation again on other machines, or just want to keep the installation package file for the future, you can run:

sudo checkinstall

which, together with installing new PHP, would also create .debpackage file in your current directory.

Whichever way you choose, now you have PHP 5.2 installed in /usr/bin/php52

Apache conf files

The /etc/php52/apache2/ configuration directory for PHP 5.2 should have already been created during the installation process (create it now if it is not the case). Now you need to let PHP 5.2 use the same extensions as your version 5.3 is using:

sudo ln -s /etc/php5/conf.d /etc/php52
sudo ln -s /etc/php5/cli /etc/php52

Copy example php.ini-recommended file provided with PHP installation into its new directory (which will be defined in the next step):

sudo cp php.ini-recommended /etc/php52/apache2/php.ini

and make required amends to it if need be.

Apache and FastCGI

Next thing to do is to set up Apache to run PHP 5.2 using FastCGI. Start with installing fastcgi module:

sudo apt-get install libapache2-mod-fastcgi

Make sure all required modules are enabled and restart Apache:

sudo a2enmod cgi fastcgi actions
sudo service apache2 restart

Create a wrapper script called php52-cgi to run the fastcgi enabled version of PHP and place it under /usr/lib/cgi-bin/, with the following content:

#!/bin/sh
PHPRC="/etc/php52/apache2/"
export PHPRC
PHP_FCGI_CHILDREN=4
export PHP_FCGI_CHILDREN
PHP_FCGI_MAX_REQUESTS=5000
export PHP_FCGI_MAX_REQUESTS
exec /usr/bin/php52/php-cgi

The PHPRC parameter tells PHP 5.2 where to look for a php.ini.
The PHP_FCGI_CHILDREN pre-forks threads with the FastCGI process manager.
The PHP_FCGI_MAX_REQUESTS limits the requests.
Finally the exec executes php. You can read more about this on FastCGI site.

Make sure the file is executable:

sudo chmod +x /usr/lib/cgi-bin/php52-cgi

Finally create new include file /etc/apache2/php52.conf, which will be used by those virtual hosts that need to run off PHP 5.2. Add the following content to it:

# Include file for virtual hosts that need to run PHP 5.2

<FilesMatch "\.php">
   SetHandler application/x-httpd-php5
</FilesMatch>

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

The FilesMatch forces the handler to execute files with the suffix .php. This must be set, because if mod_php with PHP 5.3 is installed, the module interprets the php file and not the cgi script.
The ScriptAlias sets the path to the cgi script.
The AddHandler registers a new handler.
The Action activates the cgi script for the files passed from the handler.

PHP安装所最到的问题-解决方案的更多相关文章

  1. Ubuntu 下安装 apt-get install npm 失败的解决方案

    Ubuntu 下安装 apt-get  install npm 失败的解决方案: sudo apt-get remove nodejs npm ## remove existing nodejs an ...

  2. Oracle安装时先决条件检查失败的解决方案

      Oracle安装时先决条件检查失败的解决方案 [java] 安装环境:Win7-64bit专业版,内存6G,硬盘空间足够 安装版本:Oracle Database 11g Release 2 (1 ...

  3. ubuntu 的mysql 安装过程和无法远程的解决方案

    ubuntu 的mysql 安装过程和无法远程的解决方案 安装完mysql-server启动mysqlroot@ubuntu:# /etc/init.d/mysql start (如果这个命令不可以, ...

  4. 安装OFFICE2016错误代码0-1018(0)的解决方案 和激活方案

    一.安装OFFICE2016错误代码0-1018(0)的解决方案 下面方法亲测有效:Step 1. Go to C:\Program Files\Common Files\microsoft shar ...

  5. CocoaPods安装教程 pod setup很慢解决方案

    CocoaPods安装教程 pod setup很慢解决方案 http://www.jianshu.com/p/6230eec137f6

  6. 关于WIN7下IE8IE7浏览器无法安装微信支付商户证书的解决方案

    关于WIN7下IE8IE7浏览器无法安装微信支付商户证书的解决方案 解决方案就是使用 chrome浏览器 默认的chorme浏览器  打开微信商户平台 会提示让安装控件  然后反复安装 其实要解决这个 ...

  7. 安装 PostgreSQL 时丢失 libintl-8.dll 解决方案

     发表于 2013 年 11 月 13 日     修订于 2018 年 05 月 05 日 PostgreSQL 比 MySQL 有更多的高级特性,而且微信支付的数据库也是基于 PostgreSQL ...

  8. Nginx安装步骤及本地浏览器不通解决方案,Nginx在Linux发布项目,Tomcat 与本地浏览器不通解决方案

    Nginx安装步骤及本地浏览器不通解决方案 1.将安装包放到usr/local文件夹下 2..进入local目录,解压 tar -zxvf nginx-1.17.5.tar.gz 3.进入 nginx ...

  9. Apache的详细安装教程和遇到的问题解决方案

    Apache是世界使用排名第一的Web服务器软件.它可以运行在几乎所有广泛使用的计算机平台上,由于其跨平台和安全性被广泛使用,是最流行的Web服务器端软件之一 (一)Apache安装软件下载 1.访问 ...

  10. 使用ruby过程中遇到安装gem失败的一些通用解决方案

    ruby语言升级还是比较勤快的.但是数量众多的版本使得程序库的兼容性成了大问题.有些gem表示明确不支持某个特定版本以前的ruby,而有些gem则与较高的版本不兼容.再加上gem本身也有版本,简直是乱 ...

随机推荐

  1. 用c语言编写直接插入法

    #include<stdio.h> //直接插入法 void D_insert(int s[],int n); int main() { int i; ]; printf("pl ...

  2. Yii 提示Invalid argument supplied for foreach() 等错误

    Yii 提示Invalid argument supplied for foreach() 或者 undefined variable: val等错误 只需要在对应的文件中加入error_report ...

  3. Windows Store App 获取文件及文件夹列表

    通过使用13.2.1小节给出的方法和属性,不仅可以对用户库中的文件和文件夹进行操作,还可以获取其中所有的文件或者文件夹,比如为了完整地展现整个音乐库,可以获取并列举出音乐库中所有的音乐文件,以便能够在 ...

  4. BestCoder Round #41

    T1:ZCC loves straight flush(hdu 5228) 题目大意: 给出5张牌,问至少替换多少张牌可以构成同花顺. 题解: 1.直接枚举所有同花顺(枚举花色A-D和最小的数字1-1 ...

  5. SSH框架之一详解maven搭建多模块项目

    闲来无事,思量着自己搭建一个ssh框架,一来回顾熟悉一下ssh的内容,hibernate还就没用过了,生疏了都.二来整合一下,将其他掌握的和正在学习的框架核技术糅合到一起,就当是做一个demo练手了. ...

  6. Linux gcc 编译日记

    gcc 编译器是众多编译器组合入口,例如在编译 .cpp 文件时,使用c++ 编译器,编译.c 文件时,使用c编译器. 在编译c++程序时, 库文件与头文件可通过 -L[dir] 指定库目录 , -l ...

  7. Install Java1.6

    声明:一下内容主要来自网络,本来在此基础上根据自己的成功经验做了一些浅陋的(但有价值的)备注说明和修改. (本人也是ubuntu 11.10版本,但是是64位的,因此安装的java也是64位版本.) ...

  8. 使用excel快速制表 拒绝粗心

    办公室打印个表格 使用了word打印后 发现 id重复很多 只好网上找了点excel 2003资料 学习小 快速制作表格 新建一个excel文件. 在新建excel中,用鼠标选中需要的表格行数列数,然 ...

  9. Adaboost 2

    本文不定期更新.原创文章,转载请注明出处,谢谢. Adaboost是一种迭代算法,其核心思想是针对同一个训练集训练不同的分类器(弱分类器),然后把这些弱分类器集合起来,构成一个更强的最终分类器(强分类 ...

  10. Git基本命令行操作 (转)

    Git远程操作详解   作者: 阮一峰 Git是目前最流行的版本管理系统,学会Git几乎成了开发者的必备技能. Git有很多优势,其中之一就是远程操作非常简便.本文详细介绍5个Git命令,它们的概念和 ...