WARNING This script is not supported by i-MSCP team and its usage is not commended WARNING
(Maybe you should check my new post using precompiled php versions: PhpSwitcher with precompiled php packages)
Changelog:
- 15.02.2018 (started changelog)
- Added php 7.2 support (untested, waiting for PhpSwitcher receives 7.2)
- Changed download url for ioncube (to https, thx to @Speedy )
- Fixed wrong paths for php 7.1 apcu
- Updated apcu installation links 5.1.8 -> 5.1.9
- Added symlincs inside /opt/phpswitcher/ (e.g. /opt/phpswitcher/php7.1) which directly links to php executable (to be used for cronjobs / programs)
- Added missing cleanup - ioncube was downloaded but never updated
- 07.03.2018
- added --auto-setup again which auto register the new compiled php versions
- modified folder name from 20180307141723 to 20180307_141723 to seperate the date from the time
- 09.12.2018
- updated the script according to Speedy Post PhpSwitcher: compile all versions, add APCU and IONCUBE (big thx!)
Changes: new apcu version 5.1.15, added php 7.3 section (you need to uncomment it to use it)
- updated the script according to Speedy Post PhpSwitcher: compile all versions, add APCU and IONCUBE (big thx!)
- 28.07.2019
- added modules to be enabled by default: gmt, sqlite3 and pdo_sqlite
- 29.09.2019
- no longer compile inside the script, only add additional things
- compatibility with PhpSwticher 5
- switched to new static paths
- added support for new php versions
- removed no longer possible php versions 5.4 and 5.5
- added Imageick
- added nginx restart to make sure phpversions are shown correctly inside the panel
- 30.09.2019
- modules like gmp and sqlite are no longer needed to be enabled - they are enabled by default now
- 03.10.2019
- replaced my script with the optimized version from Starlight - big thx!
- 27.04.2020
- Updated apcu to 5.1.18
- Pecl installs now silent with default values (this should allow the script to run completely silent)
- Add second ioncube downloader for PHP 7.4 RC (ioncube beta version)
- Adds mcrypt (for PHP 7.3 and newer
- 23.05.2020
- Just updated the post and removed outdated and no longer valid information
- 17.07.2020
- Updated ioncube loader - 7.4 no longer in beta status (thx to Speddy)
- Add tested php versions
- Add information about how to update php versions to compile inside PhpSwitcher plugin
- 24.07.2020
- Updated how to update php versions for 7.4.7 (last compatible one) because the direct download was not working for me.
- 25.07.2020
- Tested Athar php 7.4.8 solution and added his solution (and link)
- 18.10.2020
- Updated php versions to 7.2.34, 7.3.23, 7.4.11.
- 06.12.2021
- Add information about my new Howto using precompiled php versions
What this script is doing:
- Compile PHP Versions
- Adding APCU support
- Adding Imagick support
- Adding Ioncube support
- Enabling some default extensions
Why I wrote this?
Every time a new PhpSwitcher plugin or PHP version is released I had to do the steps to enable APCU for two versions - so I decided to build a shell script which is doing all together. It is maybe not the best script, but it is working for me :-).
And all in all the basic was optimized by Starlight which has much better skills of doing batch scripts big thx!
Tested on:
- Ubuntu 18.04 LTS (x64)
- I-MSCP 1.5.3
- PhpSwitcher 5.0.1
- Tested PHP versions
- 5.6.40
- 7.1.33
- 7.2.32
- 7.3.20
- 7.4.8
PHP >= 7.4.8:
Till php 7.4.7 the original code is working fine. If you plan to update to > 7.4.7 please read the Athar post. For me solution 2 without environment variable worked. PhpSwitcher and 7.4.8
Not working:
- Seems to work fine
How to use:
First of all configure your PhpSwitcher and compile all needed versions (inclusive registration). Then modify the script as you like but make sure to remove php version parts you do not need. Then you can execute this script which is adding some features on top (please take a look into the script to see what it does!).
Be careful: Installing some addons like APCu needs confirmations. So you cannot let it run in the background. (The script tries to not prompt you and do a default install for all addons.)
APCU: There are two versions for APCU. Verison 4 for php versions below 7.0 and version 5 for php7. That is why the script adds two different versions. If there are new APCU versions the pecl path needs to be changed matching the new version numbers.
Ioncube: A source code protection and licensing addon. Special thx to Speedy for his information!
Imagick: I personaly need it for my nextcloud environment.
How to update php versions in PhpSwitcher:
Just edit the file /var/www/imscp/gui/plugins/PhpSwitcher/PhpCompiler/php_compiler.pl. There is a variable %VERSION_NAME_TO_VERSION_TINY_MAP. There you can define the versions you need or want. Here is an example how it could look like:
- # ...
- # ...
- # ...
- # Map PHP version names to tiny PHP versions (last known tiny PHP versions)
- my %VERSION_NAME_TO_VERSION_TINY_MAP = (
- '5.3' => '5.3.29', # End of life: 14 August 2014 - Reached
- #'5.4' => '5.4.45', # End of life: 3 September 2015 - Reached
- #'5.5' => '5.5.38', # End of life: 21 July 2016 - Reached
- '5.6' => '5.6.40', # End of life: 31 December 2018 - Reached
- '7.0' => '7.0.33', # End of life: 01 December 2018 - Reached
- '7.1' => '7.1.33', # End of life: 01 December 2019
- '7.2' => '7.2.34', # End of life: 30 November 2020
- '7.3' => '7.3.23', # End of life: 06 December 2021
- '7.4' => '7.4.11',
- #'7.4' => [ # End of life: December 2022 - Unreleased yet
- # '7.4.7', 'https://www.php.net/distributions/php-7.4.7.tar.gz'
- # ]
- #'7.4' => '7.4.7'
- );
- # ...
- # ...
- # ...
Version 2.0 (optimized version of Starlight ) :
- #!/bin/bash
- #phpVersions='7.4 7.3 7.2 7.1 7.0 5.6'
- phpVersions='5.6 7.1 7.2 7.3 7.4'
- installDir=$(date +'%Y%m%d_%H%M%S')
- ### Do not change anything below this line
- echo 'List of PHP versions:' $phpVersions
- function version_lt() { test "$(echo "$@" | tr " " "\n" | sort -rV | head -n 1)" != "$1"; }
- echo 'Compiling PHP versions'
- #perl /var/www/imscp/gui/plugins/PhpSwitcher/PhpCompiler/php_compiler.pl --install-dir $installDir --register $phpVersions
- perl /var/www/imscp/gui/plugins/PhpSwitcher/PhpCompiler/php_compiler.pl --register $phpVersions
- echo 'Adding Extensions'
- echo "Adding APCU"
- # See https://pecl.php.net/package/APCu for versions
- # version 4 for pre 7.0
- # version 5 for 7.0, 7.1, 7.2, 7.3, 7.4
- for version in $phpVersions
- do
- echo "Adding APCU to PHP version " $version
- if version_lt $version 7.0; then
- printf '\n' | /opt/phpswitcher/static/php$version/bin/pecl install channel://pecl.php.net/apcu-4.0.11
- PHP_EXT_DIR=$(/opt/phpswitcher/static/php$version/bin/php-config --extension-dir)
- echo "extension = $PHP_EXT_DIR/apcu.so" > /opt/phpswitcher/static/php$version/etc/php/conf.d/02_apcu.ini
- else
- printf '\n' | /opt/phpswitcher/static/php$version/bin/pecl install apcu
- PHP_EXT_DIR=$(/opt/phpswitcher/static/php$version/bin/php-config --extension-dir)
- echo "extension = $PHP_EXT_DIR/apcu.so" > /opt/phpswitcher/static/php$version/etc/php/conf.d/02_apcu.ini
- fi
- done
- echo "Adding Imagick"
- aptitude install libmagickwand-dev imagick
- for version in $phpVersions
- do
- echo "Adding Imagick to PHP version " $version
- printf '\n' | /opt/phpswitcher/static/php$version/bin/pecl install imagick
- PHP_EXT_DIR=$(/opt/phpswitcher/static/php$version/bin/php-config --extension-dir)
- echo "extension = $PHP_EXT_DIR/imagick.so" > /opt/phpswitcher/static/php$version/etc/php/conf.d/03_imagick.ini
- done
- echo "Adding Mcrypt"
- aptitude install libmcrypt-dev libc-dev autoconf pkg-config
- for version in $phpVersions
- do
- if version_lt $version 7.2; then
- echo "Ignoring version $version for Mcrypt (to low)"
- else
- echo "Adding Mcrypt to PHP version " $version
- printf '\n' | /opt/phpswitcher/static/php$version/bin/pecl install mcrypt
- PHP_EXT_DIR=$(/opt/phpswitcher/static/php$version/bin/php-config --extension-dir)
- echo "extension = $PHP_EXT_DIR/mcrypt.so" > /opt/phpswitcher/static/php$version/etc/php/conf.d/03_mcrypt.ini
- fi
- done
- #echo "Adding additional extensions"
- #for version in $phpVersions
- #do
- # PHP_EXT_DIR=$(/opt/phpswitcher/static/php$version/bin/php-config --extension-dir)
- # echo "extension = $PHP_EXT_DIR/mysqli.so" > /opt/phpswitcher/static/php$version/etc/php/conf.d/04_mysqli.ini
- # echo "extension = $PHP_EXT_DIR/opcache.so" > /opt/phpswitcher/static/php$version/etc/php/conf.d/04_opcache.ini
- #done
- echo "Adding ioncube"
- cd /usr/local/src
- # cleanup first
- rm /usr/local/src/ioncube_loaders_lin_x86-64.tar.gz
- rm -r /usr/local/src/ioncube/
- # loading ioncube
- wget https://downloads.ioncube.com/loader_downloads/ioncube_loaders_lin_x86-64.tar.gz
- tar -xzf ioncube_loaders_lin_x86-64.tar.gz
- rm ioncube_loaders_lin_x86-64.tar.gz
- cd ioncube
- # --- 7.4 is no longer in a special beta archive ---
- # --- (codes stays in cases of another beta iconcube loader ---
- # loading BETA ioncube (has no ioncube subfolder)
- #wget https://www.ioncube.com/php-7.4.0-beta-loaders/ioncube_loaders_lin_x86-64_7.4_BETA2.tar.gz
- #tar -xzf ioncube_loaders_lin_x86-64_7.4_BETA2.tar.gz
- #rm ioncube_loaders_lin_x86-64_7.4_BETA2.tar.gz
- for version in $phpVersions
- do
- echo "Adding Ioncube to PHP version" $version
- PHP_EXT_DIR=$(/opt/phpswitcher/static/php$version/bin/php-config --extension-dir)
- cp ioncube_loader_lin_$version.so $PHP_EXT_DIR/ioncube.so
- echo "zend_extension = $PHP_EXT_DIR/ioncube.so" > /opt/phpswitcher/static/php$version/etc/php/conf.d/01_ioncube.ini
- # --- Code if there is a beta version
- # if version_lt $version 7.4; then
- # echo "Adding Ioncube to PHP version" $version
- # PHP_EXT_DIR=$(/opt/phpswitcher/static/php$version/bin/php-config --extension-dir)
- # cp ioncube_loader_lin_$version.so $PHP_EXT_DIR/ioncube.so
- # echo "zend_extension = $PHP_EXT_DIR/ioncube.so" > /opt/phpswitcher/static/php$version/etc/php/conf.d/01_ioncube.ini
- # else
- # echo "Adding BETA Ioncube to PHP version" $version
- # PHP_EXT_DIR=$(/opt/phpswitcher/static/php$version/bin/php-config --extension-dir)
- # cp ioncube_loader_lin_7.4_10.4.0_beta2.so $PHP_EXT_DIR/ioncube.so
- # echo "zend_extension = $PHP_EXT_DIR/ioncube.so" > /opt/phpswitcher/static/php$version/etc/php/conf.d/01_ioncube.ini
- # fi
- done
- cd
- echo "Restarting services..."
- for version in $phpVersions
- do
- service psw$version-fpm restart
- done
- service apache2 restart
- service nginx restart
- echo "Done"
WARNING This script is not supported by i-MSCP team and its usage is not commended WARNING