You are here: Home / Debian GNU/Linux / Servers / PHP / Install PHP5.3 on Debian 7.0 Wheezy

Install PHP5.3 on Debian 7.0 Wheezy

by Pierre-Yves Landuré last modified Nov 11, 2017 09:45

Debian 7.0 Wheezy provide by default PHP 5.4. This can be a problem with some Web applications. This howto describe the installation of PHP 5.3 from the DotDeb repositories for Squeeze on Debian 7.0 Wheezy.

This howto is tested on :

  • Debian 7.0 Wheezy

Installation

Repository setup

Install the needed software :

command apt-get install lsb-release

Detect the distribution name :

DEBIAN_VERSION="$(command lsb_release -cs)"

Detect the currently used download mirror :

MIRROR=$(command egrep "^deb.*${DEBIAN_VERSION}" '/etc/apt/sources.list' \
    | command egrep -v "updates|-src|cdrom" \
| command head -n 1 \
    | cut --delimiter=" " --fields=2)

Add the Squeeze repositories to Apt configuration :

DEBIAN_VERSION="squeeze"
command echo "# Debian contrib repository.
deb http://ftp.fr.debian.org/debian/ ${DEBIAN_VERSION} main
deb-src http://ftp.fr.debian.org/debian/ ${DEBIAN_VERSION} main

deb http://security.debian.org/ ${DEBIAN_VERSION}/updates main
deb-src http://security.debian.org/ ${DEBIAN_VERSION}/updates main" \
    > "/etc/apt/sources.list.d/${DEBIAN_VERSION}.list"

Add the DotDeb Squeeze repositories to Apt configuration :

command echo "# DotDeb repository.
deb http://packages.dotdeb.org ${DEBIAN_VERSION} all
deb-src http://packages.dotdeb.org ${DEBIAN_VERSION} all" \
    > "/etc/apt/sources.list.d/dotdeb-org-${DEBIAN_VERSION}.list"

Add the signing ssl key for the repository to Apt key ring :

command wget 'http://www.dotdeb.org/dotdeb.gpg' \
--quiet --output-document=- \
| command apt-key add -

Assign a low priority to Dotdeb packages :

command echo "Package: *
Pin: origin packages.dotdeb.org
Pin-Priority: 200" \
> '/etc/apt/preferences.d/dotdeb-org'

Update the available packages list :

command apt-get update

Installation of PHP 5.3

Fetch the list of PHP5 and PECL packages available in Dotdeb repository :

PACKAGES="$(command wget "http://packages.dotdeb.org/dists/${DEBIAN_VERSION}/php5/binary-$(command dpkg --print-architecture)" \
--quiet --output-document=- \
| command grep "href=" | command grep -v "h1" | command grep -v "\.\./" \
| command sed -e 's/^[^>]*>\([^_]*\)_.*$/\1/' | command tr "\n" " ")"
PECL_PACKAGES="$(command wget "http://packages.dotdeb.org/dists/${DEBIAN_VERSION}/php5-pecl/binary-$(command dpkg --print-architecture)" \
--quiet --output-document=- \
| command grep "href=" | command grep -v "h1" | command grep -v "\.\./" \
| command sed -e 's/^[^>]*>\([^_]*\)_.*$/\1/' | command tr "\n" " ")"
ALL_PACKAGES="$(command wget "http://packages.dotdeb.org/dists/${DEBIAN_VERSION}/php5/binary-all" \
 --quiet --output-document=- \
| command grep "href=" | command grep -v "h1" | command grep -v "\.\./" \
| command sed -e 's/^[^>]*>\([^_]*\)_.*$/\1/' | command tr "\n" " ")"

Assign a high priority to Dotdeb PHP packages :

command echo "Package: ${PACKAGES} \\
${PECL_PACKAGES} \\
${ALL_PACKAGES}
Pin: origin packages.dotdeb.org
Pin-Priority: 600" \
> '/etc/apt/preferences.d/dotdeb-org-php5'

Make sure that PHP session files stay in "/var/lib/php5" and prevent PHP to manage their deletion (handled by a cron script) :

command mkdir --parents '/etc/php5/conf.d' '/var/lib/php5'
command chmod 733 '/var/lib/php5'
command chmod o+t '/var/lib/php5'
echo '; Store sessions to /var/lib/php5
session.save_path = "/var/lib/php5"
session.gc_probability = 0' \
    > '/etc/php5/conf.d/000-session-store-default.ini'

Replace installed PHP5 packages by the 5.3 version :

command apt-get install $(command dpkg --get-selections \
    | command grep 'php5' \
    | command cut --fields=1 \
    | command sed -e 's|.*|&/squeeze|g')

If PHP is not installed, reffer to  Install PHP-FPM on Debian.

Remerciements