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!

@lostandwaiting
Copy link

lostandwaiting commented Sep 18, 2021

Hello,
After following this tutorial i get raw text on the website (apache2), can you add how to fix that problem?
(i did everything from your tutorial without errors).
thank you

@keriat
Copy link
Author

keriat commented Sep 18, 2021

Hey, @risimini 👋

Hello,
After following this tutorial i get raw text on the website (apache2), can you add how to fix that problem?
(i did everything from your tutorial without errors).
thank you

Most likely your Apache config is missing the php processing.

sudo a2dismod php7.X
sudo a2enmod php7.3
sudo service apache2 restart

If you got an error then you can check which module exact name:

cd /etc/apache2/mods-enabled
ls -la | grep php

@lostandwaiting
Copy link

hello @keriat

the a2dismod and a2enmod was the last lines of the above tutorial and i executed them,

this is the php content in mods-enabled
lrwxrwxrwx 1 root root 27 set 17 21:47 php5.conf -> ../mods-available/php5.conf
lrwxrwxrwx 1 root root 27 set 17 21:47 php5.load -> ../mods-available/php5.load
lrwxrwxrwx 1 root root 27 set 18 23:19 php7.load -> ../mods-available/php7.load

no php7.conf anywhere,

after enabling php7 with a2enmod the main webpage shows the following
https://i.imgur.com/t29GnZN.png

@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