Ioncube Loader Script for Multiple PHP Versions

Discussion in 'Tips/Tricks/Mods' started by ahrasis, Jan 8, 2021.

  1. ahrasis

    ahrasis Well-Known Member HowtoForge Supporter

    I thought of sharing this for those who need it, though one may found that this method is a little different than other tutorials available (or may be more) but I believe that this is how this php module should be managed, so enjoy.
    Code:
    # Donwload, extract & move respective Ioncube Loader .so file accordingly
    cd /tmp
    sudo  wget https://downloads.ioncube.com/loader_downloads/ioncube_loaders_lin_x86-64.tar.gz
    sudo  tar xzf ioncube_loaders_lin_x86-64.tar.gz
    cd ioncube
    if [ -e "ioncube_loader_lin_5.6.so" ]; then sudo cp -a ioncube_loader_lin_5.6.so /usr/lib/php/20131226/ioncube.so; fi
    if [ -e "ioncube_loader_lin_7.0.so" ]; then sudo cp -a ioncube_loader_lin_7.0.so /usr/lib/php/20151012/ioncube.so; fi
    if [ -e "ioncube_loader_lin_7.1.so" ]; then sudo cp -a ioncube_loader_lin_7.1.so /usr/lib/php/20160303/ioncube.so; fi
    if [ -e "ioncube_loader_lin_7.2.so" ]; then sudo cp -a ioncube_loader_lin_7.2.so /usr/lib/php/20170718/ioncube.so; fi
    if [ -e "ioncube_loader_lin_7.3.so" ]; then sudo cp -a ioncube_loader_lin_7.3.so /usr/lib/php/20180731/ioncube.so; fi
    if [ -e "ioncube_loader_lin_7.4.so" ]; then sudo cp -a ioncube_loader_lin_7.4.so /usr/lib/php/20190902/ioncube.so; fi
    if [ -e "ioncube_loader_lin_8.0.so" ]; then sudo cp -a ioncube_loader_lin_8.0.so /usr/lib/php/20200930/ioncube.so; fi
    
    # Create ioncube.ini & copy it to respective php module folder
    sudo  cat <<EOT >> ioncube.ini
    ; configuration for php ioncube module
    ; priority=10
    zend_extension=ioncube.so
    ioncube.enable=1
    EOT
    sudo  xargs -n 1 cp -v ioncube.ini<<<"/etc/php/5.6/mods-available/ /etc/php/7.0/mods-available/ /etc/php/7.1/mods-available/ /etc/php/7.2/mods-available/ /etc/php/7.3/mods-available/ /etc/php/7.4/mods-available/ /etc/php/8.0/mods-available/"
    
    # Enable Ioncube Loader & restart all php-fpm
    phpenmod ioncube
    if [ $(dpkg-query -W -f='${Status}' php5.6-fpm 2>/dev/null | grep -c "ok installed") -eq 1 ]; then sudo service php5.6-fpm restart; fi
    if [ $(dpkg-query -W -f='${Status}' php7.0-fpm 2>/dev/null | grep -c "ok installed") -eq 1 ]; then sudo service php7.0-fpm restart; fi
    if [ $(dpkg-query -W -f='${Status}' php7.1-fpm 2>/dev/null | grep -c "ok installed") -eq 1 ]; then sudo service php7.1-fpm restart; fi
    if [ $(dpkg-query -W -f='${Status}' php7.2-fpm 2>/dev/null | grep -c "ok installed") -eq 1 ]; then sudo service php7.2-fpm restart; fi
    if [ $(dpkg-query -W -f='${Status}' php7.3-fpm 2>/dev/null | grep -c "ok installed") -eq 1 ]; then sudo service php7.3-fpm restart; fi
    if [ $(dpkg-query -W -f='${Status}' php7.4-fpm 2>/dev/null | grep -c "ok installed") -eq 1 ]; then sudo service php7.4-fpm restart; fi
    if [ $(dpkg-query -W -f='${Status}' php8.0-fpm 2>/dev/null | grep -c "ok installed") -eq 1 ]; then sudo service php8.0-fpm restart; fi
    cd /root
    
     
  2. Dennis_sp

    Dennis_sp Member

    Thanks for this script!
     
    ahrasis likes this.
  3. WolfTongue

    WolfTongue New Member

    Thank you very much for your script! I do not know if the php paths could change but if they can this could be more stable:

    Changes:
    It uses the php-config command to get the extension directory.

    Code:
    # Donwload, extract & move respective Ioncube Loader .so file accordingly
    cd /tmp
    sudo  wget https://downloads.ioncube.com/loader_downloads/ioncube_loaders_lin_x86-64.tar.gz
    sudo  tar xzf ioncube_loaders_lin_x86-64.tar.gz
    cd ioncube
    if [ -e "ioncube_loader_lin_5.6.so" ]; then sudo cp -a ioncube_loader_lin_5.6.so $(/usr/bin/php-config5.6 --extension-dir)/ioncube.so; fi
    if [ -e "ioncube_loader_lin_7.0.so" ]; then sudo cp -a ioncube_loader_lin_7.0.so $(/usr/bin/php-config7.0 --extension-dir)/ioncube.so; fi
    if [ -e "ioncube_loader_lin_7.1.so" ]; then sudo cp -a ioncube_loader_lin_7.1.so $(/usr/bin/php-config7.1 --extension-dir)/ioncube.so; fi
    if [ -e "ioncube_loader_lin_7.2.so" ]; then sudo cp -a ioncube_loader_lin_7.2.so $(/usr/bin/php-config7.2 --extension-dir)/ioncube.so; fi
    if [ -e "ioncube_loader_lin_7.3.so" ]; then sudo cp -a ioncube_loader_lin_7.3.so $(/usr/bin/php-config7.3 --extension-dir)/ioncube.so; fi
    if [ -e "ioncube_loader_lin_7.4.so" ]; then sudo cp -a ioncube_loader_lin_7.4.so $(/usr/bin/php-config7.4 --extension-dir)/ioncube.so; fi
    if [ -e "ioncube_loader_lin_8.0.so" ]; then sudo cp -a ioncube_loader_lin_8.0.so $(/usr/bin/php-config8.0 --extension-dir)/ioncube.so; fi
    
    # Create ioncube.ini & copy it to respective php module folder
    sudo  cat <<EOT >> ioncube.ini
    ; configuration for php ioncube module
    ; priority=10
    zend_extension=ioncube.so
    ioncube.enable=1
    EOT
    sudo  xargs -n 1 cp -v ioncube.ini<<<"/etc/php/5.6/mods-available/ /etc/php/7.0/mods-available/ /etc/php/7.1/mods-available/ /etc/php/7.2/mods-available/
     /etc/php/7.3/mods-available/ /etc/php/7.4/mods-available/ /etc/php/8.0/mods-available/"
    
    # Enable Ioncube Loader & restart all php-fpm
    phpenmod ioncube
    if [ $(dpkg-query -W -f='${Status}' php5.6-fpm 2>/dev/null | grep -c "ok installed") -eq 1 ]; then sudo service php5.6-fpm restart; fi
    if [ $(dpkg-query -W -f='${Status}' php7.0-fpm 2>/dev/null | grep -c "ok installed") -eq 1 ]; then sudo service php7.0-fpm restart; fi
    if [ $(dpkg-query -W -f='${Status}' php7.1-fpm 2>/dev/null | grep -c "ok installed") -eq 1 ]; then sudo service php7.1-fpm restart; fi
    if [ $(dpkg-query -W -f='${Status}' php7.2-fpm 2>/dev/null | grep -c "ok installed") -eq 1 ]; then sudo service php7.2-fpm restart; fi
    if [ $(dpkg-query -W -f='${Status}' php7.3-fpm 2>/dev/null | grep -c "ok installed") -eq 1 ]; then sudo service php7.3-fpm restart; fi
    if [ $(dpkg-query -W -f='${Status}' php7.4-fpm 2>/dev/null | grep -c "ok installed") -eq 1 ]; then sudo service php7.4-fpm restart; fi
    if [ $(dpkg-query -W -f='${Status}' php8.0-fpm 2>/dev/null | grep -c "ok installed") -eq 1 ]; then sudo service php8.0-fpm restart; fi
    cd -
     
    ahrasis and Jesse Norell like this.
  4. ahrasis

    ahrasis Well-Known Member HowtoForge Supporter

    Smart and thank you very much. I remember @Jesse Norell were trying to integrate this into ISPConfig Auto Installer so hopefully your improvement shall ease that, though the AI is in php but this could help as well.
     

Share This Page