PhpSwitcher with precompiled php packages

  • WARNING This script is not supported by i-MSCP team WARNING

    Hi there,

    I was very frustrated bringing php 8.0 and 8.1 up with the PhpSwitcher plugin. So I checked alternatives and found other tools like IspConfig which are using package reposirories with precompiled php versions. So I started to check if these version could be used for the PhpSwitcher as it makes the implementing it into I-MSCP more easier. And the good part is that I found a solution.


    • This HowTo is for Ubuntu and tested only on Ubuntu.
    • Use at your own risk!
    • I made this after bringing the new version to work - so some steps could be not precised as I want them to be.
    • In some cases you need root access - in these cases place a sudo in front of the commands.

    If all precompiled versions are working (which they should), you can install the following packages:

    • 5.6
    • 7.0
    • 7.1
    • 7.2
    • 7.3
    • 7.4
    • 8.0
    • 8.1



    • phpSwitcher (paid module)
    • shell access to your server (with root permissions)
    • shell knowledge (never trust online shell commands!)

    Installing the package repository:

    To install the packages I use the Ondrej php versions:

    1. apt install software-properties-common
    2. add-apt-repository ppa:ondrej/php
    3. apt-get update

    Install php version with basic needs (example is for php 8.1):

    1. apt-get install php8.1-cgi php8.1-fpm php8.1-dev libapache2-mod-php8.1

    In my case I install all the packages I need:

    1. apt-get install php8.1-cgi php8.1-fpm php8.1-xml php8.1-bz2 php8.1-sqlite3 php8.1-pdo-sqlite php8.1-mysql php8.1-mbstring php8.1-imap php8.1-imagick php8.1-gd php8.1-curl php8.1-apcu php8.1-dev php8.1-memcached php8.1-pdo-mysql php8.1-pdo-sqlite php8.1-pgsql php8.1-zip php8.1-redis php8.1-mcrypt libapache2-mod-php8.1

    (In some cases an apt-get upgrade is needed after this step.)

    Install PEARL (optional):
    WARNING: This is only needed if you want to configure the versions on your own and only if you want a seperate folder for each php version!

    Installation of PEARL is really easy but you need to make sure to change the directory:

    1. # create the folders you want pear to be installed to (in my case /opt/pear/8.1)
    2. mkdir /opt/pear
    3. mkdir /opt/pear/8.1
    4. # download installer and start it
    5. cd /opt/pear
    6. wget
    7. php8.1 /opt/pear/go-pear.phar # see below before executing!

    The last command opens the following list, the paths below are a suggestion:

    Now press 1 and change the path to /opt/pear/8.1

    After that press 12 and change it to /opt/pear/pear8.1.conf

    Now it should look like:

    Press enter to start the installation process.

    Installing additional pecl packages (optional):

    WARNING: First of all check if there is a precompiled packages which comes with the Ondrej packages using apt search php | grep mymodulename.

    WARNING: I had troubles using this and avoided using it. So be careful with this and test it before trying to use it productive!

    First of all you need to change the default php version:

    1. update-alternatives --set php /usr/bin/php8.1
    2. update-alternatives --set php-cgi /usr/bin/php-cgi8.1
    3. update-alternatives --set php-cgi-bin /usr/lib/cgi-bin/php8.1
    4. update-alternatives --set php-config /usr/bin/php-config8.1
    5. update-alternatives --set php-fpm.sock /run/php/php8.1-fpm.sock
    6. update-alternatives --set phpize /usr/bin/phpize8.1

    Now install your pecl module - in this example the module is called <module>:

    1. printf '\n' | pecl install -f <module>
    2. PHP_EXT_DIR=$(/usr/bin/php-config8.1 --extension-dir) \
    3. && echo "extension = <module>" > /etc/php/8.1/mods-available/<module>.ini
    4. if [ -f /etc/php/8.1/mods-available/<module>.ini ]; then
    5. ln -s /etc/php/8.1/mods-available/<module>.ini /etc/php/8.1/cgi/conf.d/50_<module>.ini
    6. ln -s /etc/php/8.1/mods-available/<module>.ini /etc/php/8.1/apache2/conf.d/50_<module>.ini
    7. ln -s /etc/php/8.1/mods-available/<module>.ini /etc/php/8.1/cli/conf.d/50_<module>.ini
    8. ln -s /etc/php/8.1/mods-available/<module>.ini /etc/php/8.1/fpm/conf.d/50_<module>.ini
    9. echo "extension does not exist: /etc/php/8.1/mods-available/<module>.ini"
    10. fi

    Switch PHP version back to your old one - in this case 7.0:

    1. # some of the commands below could fail due to not installed in your main php version
    2. update-alternatives --set php /usr/bin/php7.0
    3. update-alternatives --set php-cgi /usr/bin/php-cgi7.0
    4. update-alternatives --set php-cgi-bin /usr/lib/cgi-bin/php7.0
    5. update-alternatives --set php-config /usr/bin/php-config7.0
    6. update-alternatives --set php-fpm.sock /run/php/php7.0-fpm.sock
    7. update-alternatives --set phpize /usr/bin/phpize7.0

    Install Ioncube (optional):

    First of all we need to download the ioncube package:

    1. mkdir /opt/ioncube
    2. cd /opt/ioncube
    3. wget
    4. tar -xzf ioncube_loaders_lin_x86-64.tar.gz

    Now install it for the version you wanna use. At this moment php8.1 is not in the list but shown above as an example:

    And remove the garbage 8):

    1. rm -rf /opt/ioncube


    After this you need to restart all php services. I also added some more details about the output versions, but in general they are not really needed:

    Installing in I-MSCP:

    There are two ways to install the packages:

    Using built in phpSwitcher function:

    Make sure the version is in the compiler file (not known versions are not searched and therefore cannot be added). Check the file /var/www/imscp/gui/plugins/PhpSwitcher/PhpCompiler/ and add the versions you want and need (the most recent versions can be found at

    After that you can add the php versions with the following command (only specify the versions you want or simply do not specify any version to add them all):

    WARNING: If you already have a configured compiled version this is going to overwrite them!

    1. perl /var/www/imscp/gui/plugins/PhpSwitcher/PhpCompiler/ --register --packaged --packaged-only 5.6 7.0 7.1 7.2 7.3 7.4 8.0 8.1

    Do it on your own:

    All you need now is to switch to your new php version. So add it with the following parameters (example still with 8.1):

    General -> Pear folder
    or if you do not have an own folder for pear
    FastCGI -> path to binary file
    PHP-FPM -> path to binary file
    PHP-FPM -> path to config file
    PHP-FPM -> path to pool folder


    If there is a new version in the package repository all you need to do is a normal packages update. As this has not happened till this howto was made I recommend to check the admin panel if everything works fine.

    Finally 2 (optional):

    If you liked it please leave a thumbs up :thumbsup:.

    WARNING This script is not supported by i-MSCP team WARNING

    Edited 13 times, last by UncleSam ().

  • Wait a minute, you did that to add PHP 8.x to your iMSCP setup right ?

    If so, why ?

    The standard PHP Switcher plugin handle it without any issue (you know you can either to the old "compile" way, or the packaged way (which seems similar to your solution))

  • for me it is not working with 8.0 or 8.1 - nonstop compile errors (maybe because I tried multiple howtos without any luck)

  • Yeah, the compilation way is broken (even for some 7.4.x release), but with PHP Switcher you have the ability to use the packaged version, it's embedded and working just fine, not need for your modifications, it's already available with the plugin :/

  • kess thx for the information, I found it using wayback (…hp?id=plugins:phpswitcher).

    I also was able to replace all compiled versions with the packaged versions. I have just a short question about that:

    Is this also installing all needed php versions from the package (which makes my howto obsolete - almost) or is the installation still a part you have to do on your own?

    Short description how to useit:

    1. Add 8.0 and 8.1 to /var/www/imscp/gui/plugins/PhpSwitcher/PhpCompiler/
    2. run perl /var/www/imscp/gui/plugins/PhpSwitcher/PhpCompiler/ --register --packaged --packaged-only 5.6 7.0 7.1 7.2 7.3 7.4 8.0 8.1