Skip to content

Instantly share code, notes, and snippets.

@keriat
Last active July 17, 2023 12:41
Show Gist options
  • Save keriat/647a2f8da6913825cd498860260a03dd to your computer and use it in GitHub Desktop.
Save keriat/647a2f8da6913825cd498860260a03dd to your computer and use it in GitHub Desktop.
Install php7.* on Debian 7 Wheezy

How to install PHP 7.* on Debian 7.* "Wheezy"

Download Apache Dev Headers

apt-get install apache2-threaded-dev

Download PHP source

sudo apt-get install git
cd /tmp
git clone https://github.com/kasparsd/php-7-debian.git
cd php-7-debian/

Add APSX2 to Build.sh

Use vim build.sh command to edit build.sh script

You’ll need to add line --with-apxs2=/usr/bin/apxs2 \ to your CONFIGURE_STRING and place make clean before make command.

Modified part of a build.sh:

CONFIGURE_STRING="--prefix=/usr/local/php7 \
                  --enable-huge-code-pages \
                  --with-apxs2=/usr/bin/apxs2 \
                  --with-config-file-scan-dir=/usr/local/php7/etc/conf.d \
                  --enable-bcmath \
                  --with-bz2 \
                  --enable-calendar \
                  --enable-intl \
                  --enable-exif \
                  --enable-dba \
                  --enable-ftp \
                  --with-gettext \
                  --with-gd \
                  --with-jpeg-dir \
                  --enable-mbstring \
                  --with-mhash \
                  --enable-mysqlnd \
                  --with-mysqli \
                  --with-mysql-sock=yes \
                  --with-pdo-mysql \
                  --with-openssl \
                  --enable-pcntl \
                  --with-pspell \
                  --enable-shmop \
                  --enable-soap \
                  --enable-sockets \
                  --enable-sysvmsg \
                  --enable-sysvsem \
                  --enable-sysvshm \
                  --enable-wddx \
                  --with-zlib \
                  --enable-zip \
                  --with-readline \
                  --with-curl \
                  --enable-fpm \
                  --with-fpm-user=www-data \
                  --with-fpm-group=www-data"

./configure $CONFIGURE_STRING

make clean
make -j "$JOB_COUNT"

Compile and install php

  1. Run ./build.sh

  2. To install PHP 7 on Debian 7.x use sudo ./install.sh command

Configure alternatives

$ update-alternatives --install /usr/local/bin/php php /usr/bin/php5 10x
update-alternatives: using /usr/bin/php5 to provide /usr/local/bin/php (php) in auto mode
$ update-alternatives --install /usr/local/bin/php php /usr/local/php7/bin/php 20
update-alternatives: using /usr/local/php7/bin/php to provide /usr/local/bin/php (php) in auto mode

Target alternatives to common bin

Use /usr/local/bin/php instead of /usr/bin/php

$ sudo rm /usr/bin/php
$ update-alternatives --config php
update-alternatives: warning: /etc/alternatives/php is dangling; it will be updated with best choice
There are 2 choices for the alternative php (providing /usr/local/bin/php).

  Selection    Path                     Priority   Status
------------------------------------------------------------
  0            /usr/local/php7/bin/php   20        auto mode
  1            /usr/bin/php5             10        manual mode
Press enter to keep the current choice[*], or type selection number: 0
$ sudo ln -s /usr/local/bin/php /usr/bin/php
$ php -v
PHP 7.2.12 (cli) (built: Jan 15 2019 04:15:05) ( ZTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
    with Zend OPcache v7.2.12, Copyright (c) 1999-2018, by Zend Technologies

$ sudo a2enmod php7
Enabling module php7.
To activate the new configuration, you need to run:
  service apache2 restart
$ sudo a2dismod php5
Module php5 disabled.
To activate the new configuration, you need to run:
  service apache2 restart
$ sudo /etc/init.d/apache2 restart

All done! Good luck!

@CodeSpoof
Copy link

Well, then @risimini, why is your php5 still enabled?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment