Top Problems with PHP installation-solutions

Source: Internet
Author: User
Tags gmp mcrypt pear snmp sqlite ocaml

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 HICCU P When asked-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 PA Rallel.

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

Installing PHP 5.3 from repositories are fairly easy process, which your most probably already has 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's much more interesting though, and what's this post would focus on, are how to add PHP 5.2 to the whole picture and MAK E Both those versions work nicely together.

Please note the This tutorial are for Apache ' s name-based virtual hosts, and essentially leaves PHP 5.3 enabled globally W Hile allowing to the use of 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, and we have in our production servers), and 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 wasn't able to find any good fix (relatively easy to apply anyway), so finally ended up with the most recent V Ersion 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 call could look as ./configure 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 need to adapt it-yur specific needs by adding and/or removing relevant options. You can read more about the options you want (or don ' t want) to the include in PHP core configure options documentation.

Configure errors

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

In the most cases quite a lot of dependencies'll be missing. You can try the to take care of them in one shot, if you don ' t care too much about installing a little too much compared to WH At 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 is really needed.

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

  • Configure:error:xml2-config not found. Please check your LIBXML2 installation.

    This error message suggests you do not have libxml2 installed. What the It really means though is so you don ' t has 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're interested in here's libxml2-dev , let's install it then:

    sudo apt-get install libxml2-dev
    The same procedure applies to all and missing libraries as well, so I'll include only final install calls from now on.
  • Configure:error:Could not find pcre.h in/usrsudo apt-get install libpcre3-dev
  • Configure:error:Please Reinstall the BZIP2 distributionsudo 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 versionsudo 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 pathsudo apt-get install postgresql-server-dev-9.1
    Make sure your check result apt-cache search of especially in case of this error, as there could is later version of PostgreSQL Availa ble.
  • 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/USRsudo apt-get install libgd2-xpm-dev
  • Configure:error:Unable to locate Gmp.hsudo apt-get install libgmp-dev
  • Configure:error:Cannot find MySQL header files under/usr.
    Note that the MySQL client library isn't 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.Hsudo 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 Directorysudo apt-get install freetds-dev
  • Configure:error:Cannot Find Pspellsudo apt-get install libpspell-dev
  • Configure:error:SNMP sanity check failed. Please check the Config.log for more information.sudo apt-get install libsnmp-dev
  • Configure:error:Cannot Find Libtidysudo apt-get install libtidy-dev
  • Configure:error:xslt-config not found. Please reinstall the LIBXSLT >= 1.1.0 distributionsudo 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 ' V E configured to build shared. You either need to build pdo_sqlite gkfx 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 was time to compile (and go for a coffee while it was running):

sudo make


Now sipping your coffee wait for approaching errors ...

Make errors

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

There is errors and one warning you is 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 the 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 with this function)
    Ext/gmp/gmp.c:1399:69:note:each Undeclared identifier are reported only once F or each function it appears the

    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 do Es 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 has 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 is 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 is due to transposed parameters

    Finally PHP Bug #53568, with a pretty easy Fix:edit file and on line ext/zip/lib/zip_dirent.c 478 Replace:

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

There, no more errors!

Install

The simplest to 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 the Create package .deb file in your current directory.

Whichever-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 has already been created during the installation process (create it Now if it isn't 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 to its new directory (which'll be defined in the next step):

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


And make required amends to it if need is.

Apache and FastCGI

Next thing to does 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 is 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 Followin G 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'll be used by those virtual hosts this 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 are set, because if mod_php with PHP 5.3 are 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.

Top Problems with PHP installation-solutions

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.