If you’re looking to encrypt PHP code in your application – ionCube is a great choice.
Using ionCube allows you to pass your PHP source code through their PHP encoder before an application is distributed which protects the code from being human-readable.
By default, PHP code that is encrypted/encoded in this way cannot be executed directly on your server – this is where ionCube loader comes in, to ensure that the PHP engine is able to process and run your code.
So – without further ado – let’s dive right in:
Table Of Contents
- What is ionCube Loader
- Installing ionCube Loader
- Checking ionCube Installation
- Removing ionCube Loader
- Updating Your PHP Version
- Backwards Compatilibility And Limitations
What is ionCube Loader
The ionCube loader is a PHP module that can be used to load encrypted PHP files. This allows you to protect your scripts from theft and change by others. The loader is supplied as a PHP extension module for Windows, Linux, and macOS which can be installed into a PHP installation and is freely redistributable.
The ionCube PHP Loader is a proprietary, yet open-source encoding for PHP scripts. It has been developed by ionCube and is available as both a freeware and commercial product. The loader encodes the PHP script so that it can only be executed in combination with an IonCube encoded file containing a decryption key. The loader makes it possible to easily protect your website’s PHP scripts from casual observation, theft, or change by others.
Installing ionCube Loader
Before you begin installing the ionCube Loader you’ll need to know which PHP version your website is running on. At RunCloud, we offer multiple versions of PHP, from 7.0 right up to the latest 8.1 release. If you’re not sure which PHP version your website is on, log in to your dashboard, and head over to ‘Settings’ on the left:
So, as an example, if you find that your website is currently running PHP version 7.4, then you’ll need to make sure you install the 7.4 version of ionCube. We’ve provided all of the code you’ll need for every version of PHP.
Once you’ve determined the PHP version you need, log in to your web server as root, and run the appropriate command below to download the right version of ionCloud, and extract it:
Download & Extract
cd wget https://downloads.ioncube.com/loader_downloads/ioncube_loaders_lin_x86-64.tar.gz tar -zxvf ioncube_loaders_lin_x86-64.tar.gz
Once you’ve done this, you’re ready to install the ionCube Loader, so choose the correct PHP version code from below, and run it on your server:
cp ioncube/ioncube_loader_lin_7.0.so /RunCloud/Packages/php70rc/lib/php/extensions/no-debug-non-zts-20151012/ echo "zend_extension=ioncube_loader_lin_7.0.so" > /etc/php70rc/conf.d/ioncube.ini systemctl restart php70rc-fpm
cp ioncube/ioncube_loader_lin_7.1.so /RunCloud/Packages/php71rc/lib/php/extensions/no-debug-non-zts-20160303/ echo "zend_extension=ioncube_loader_lin_7.1.so" > /etc/php71rc/conf.d/ioncube.ini systemctl restart php71rc-fpm
cp ioncube/ioncube_loader_lin_7.2.so /RunCloud/Packages/php72rc/lib/php/extensions/no-debug-non-zts-20170718/ echo "zend_extension=ioncube_loader_lin_7.2.so" > /etc/php72rc/conf.d/ioncube.ini systemctl restart php72rc-fpm
cp ioncube/ioncube_loader_lin_7.3.so /RunCloud/Packages/php73rc/lib/php/extensions/no-debug-non-zts-20180731/ echo "zend_extension=ioncube_loader_lin_7.3.so" > /etc/php73rc/conf.d/ioncube.ini systemctl restart php73rc-fpm
cp ioncube/ioncube_loader_lin_7.4.so /RunCloud/Packages/php74rc/lib/php/extensions/no-debug-non-zts-20190902/ echo "zend_extension=ioncube_loader_lin_7.4.so" > /etc/php74rc/conf.d/ioncube.ini systemctl restart php74rc-fpm
cp ioncube/ioncube_loader_lin_8.0.so /RunCloud/Packages/php80rc/lib/php/extensions/no-debug-non-zts-20200930 echo "zend_extension=ioncube_loader_lin_8.0.so" > /etc/php80rc/conf.d/ioncube.ini systemctl restart php80rc-fpm
cp ioncube/ioncube_loader_lin_8.1.so /RunCloud/Packages/php81rc/lib/php/extensions/no-debug-non-zts-20210902 echo "zend_extension=ioncube_loader_lin_8.1.so" > /etc/php81rc/conf.d/ioncube.ini systemctl restart php81rc-fpm
Checking ionCube Installation
Once you’ve installed ionCube you may want to verify that it’s installed properly and that everything is running correctly. To do this you simply need to enter one line of code, which will vary depending on your PHP version, as shown below:
/RunCloud/Packages/php70rc/bin/php -m | grep -i ioncube
/RunCloud/Packages/php71rc/bin/php -m | grep -i ioncube
/RunCloud/Packages/php72rc/bin/php -m | grep -i ioncube
/RunCloud/Packages/php73rc/bin/php -m | grep -i ioncube
/RunCloud/Packages/php74rc/bin/php -m | grep -i ioncube
/RunCloud/Packages/php80rc/bin/php -m | grep -i ioncube
/RunCloud/Packages/php81rc/bin/php -m | grep -i ioncube
If your installation is success, you will see the output as follows:
ionCube Loader the ionCube PHP Loader (enabled) + Intrusion Protection from ioncube24.com (unconfigured)
Removing ionCube Loader
Should you no longer need the ionCube facility, it can be removed very easily. Just as with installing it, you’ll need to know the PHP version you’re running on.
When you remove the ionCube loader, this will also remove the .so library. We’ve included the code you need to run below, depending on your PHP version.
rm ioncube/ioncube_loader_lin_7.0.so /RunCloud/Packages/php70rc/lib/php/extensions/no-debug-non-zts-20151012/
rm ioncube/ioncube_loader_lin_7.1.so /RunCloud/Packages/php71rc/lib/php/extensions/no-debug-non-zts-20160303/
rm ioncube/ioncube_loader_lin_7.2.so /RunCloud/Packages/php72rc/lib/php/extensions/no-debug-non-zts-20170718/
rm ioncube/ioncube_loader_lin_7.3.so /RunCloud/Packages/php73rc/lib/php/extensions/no-debug-non-zts-20180731/
rm ioncube/ioncube_loader_lin_7.4.so /RunCloud/Packages/php74rc/lib/php/extensions/no-debug-non-zts-20190902/
rm ioncube/ioncube_loader_lin_8.0.so /RunCloud/Packages/php80rc/lib/php/extensions/no-debug-non-zts-20200930
rm ioncube/ioncube_loader_lin_8.1.so /RunCloud/Packages/php81rc/lib/php/extensions/no-debug-non-zts-20210902
Updating Your PHP Version
From time to time, you will almost certainly want to update the PHP version you are running, so how does this affect the version of ionCube you have installed?
Fortunately, it’s actually very straightforward, since ionCube has its own separate directory for each version of PHP it’s installed for. This means that, for example, if you had PHP 7.1, and installed the appropriate version of ionCube for that, but then upgraded to PHP 8.0, all you would need to do is to install the version of ionCube for that particular version of PHP.
It would be good practice though to remove the unused version of ionCube, but having two versions wouldn’t directly cause any issues.
Just remember to install a new version of ionCube each time you upgrade the PHP version your site is using.
To install and remove ionCube versions, just follow the steps detailed above.
Backwards Compatilibility And Limitations
If you’re upgrading your version of PHP, it may not always be necessary to remove ionCube and install a newer version.
Encoded files can, in general, run on versions of PHP equal to or greater than the source language of the Encoder used to produce them. So a file produced by the Encoder for PHP 7.2 can be run by the Loaders for PHP 7.2, 7.3, and 7.4, but not 7.1. This means that the Loaders offer good backwards compatibility, however there are the following limitations:
- The Loader for PHP 8.1 can only run files produced by the version 12 Encoder for PHP 8.1.
- The Loaders for PHP 7.1 through 7.4 can only run files produced by the Encoders for PHP 7.
- The Loader for PHP 7.0 can only run files produced by the Encoder for PHP 5.6.
- The Loaders for PHP 5.5 and PHP 5.6 cannot run files produced by the PHP 4 Encoder.
ionCube’s tools are hugely valuable in both protecting and optimizing your PHP code. By encrypting and obfuscating your code you are guarding your code from prying eyes, protecting your intellectual property from being used without permission, or in any way you don’t approve of.
By using the ionCube tools your PHP code will no longer be able to be reverse engineered, copied or stolen, but as well as this it will also help speed up your code. It achieves this by compressing them before sending them back to the clients requesting that particular resource. This compression results in faster load times for end users who are trying to view or interact with your application from their browser, making for more enjoyable user experiences overall.