How to install Ioncube Loader on Ubuntu with PHP7.2
First, we need to find out which version of PHP we have installed.
$ php -v
The response will be similar to this:
PHP 7.2.19-0ubuntu0.19.04.2 (cli) (built: Aug 13 2019 11:45:23) ( NTS ) Copyright (c) 1997-2018 The PHP Group Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies with the ionCube PHP Loader + ionCube24 v10.3.9, Copyright (c) 2002-2019, by ionCube Ltd. with Zend OPcache v7.2.19-0ubuntu0.19.04.2, Copyright (c) 1999-2018, by Zend Technologies
In this case the major version of PHP we are running is 7.2.
Now we need to determine if our system is running a 32 or 64bit OS.
dpkg --print-architecture
If you are on a 64-bit architecture the response should be:
amd64
If you are on a 32-bit architecture the response should be:
i386
Now we can determine the correct location to place extensions for PHP.
$ php -i | grep extension_dir
My response looks like this:
$ extension_dir => /usr/lib/php/20170718 => /usr/lib/php/20170718
Now we can move move to the extension folder:
$ cd /usr/lib/php/20170718
Lets download the appropriate version of ioncube for our OS:
x86 systems:
$ wget https://downloads.ioncube.com/loader_downloads/ioncube_loaders_lin_x86.tar.gz
64bit systems:
$ wget https://downloads.ioncube.com/loader_downloads/ioncube_loaders_lin_x86-64.tar.gz
Now we need to extract the ioncube loader package we just downloaded:
$ tar -xvf ioncube_loaders_lin_x86-64.tar.gz
Lets move the the proper version of ioncube for your php version into the extensions folder. In my case I am going to move lin_7.2.
$ mv ./ioncube/ioncube_loader_lin_7.2.so ./
Now we can delete the ioncube folder
$ rm -Rf ./ioncube
The next step is to add ioncube to a new PHP config file.
Move into the php config directory and we are going to create a new config file for the CLI and PHP-fpm.
$ cd /etc/php/7.2/mods-available/
Create the extension file for ioncube and let’s populate it with the location of the extension we want to load:
$ echo "zend_extension = /usr/lib/php/20170718/ioncube_loader_lin_7.2.so" > ioncube.ini
Almost finished: we need to create symlinks into the cli and fpm folders:
$ ln -s /etc/php/7.2/mods-available/ioncube.ini /etc/php/7.2/cli/conf.d/01-ioncube.ini
$ ln -s /etc/php/7.2/mods-available/ioncube.ini /etc/php/7.2/fpm/conf.d/01-ioncube.ini
The 01 in front of the symlink indicates the loading order of the extension.
At this point we should be able to restart and use ioncube:
$ sudo service apache2 restart
If everything were fine we should be able to run:
$ php -v
Which will output something like:
PHP 7.2.19-0ubuntu0.19.04.2 (cli) (built: Aug 13 2019 11:45:23) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
with the ionCube PHP Loader + ionCube24 v10.3.9, Copyright (c) 2002-2019, by ionCube Ltd.
with Zend OPcache v7.2.19-0ubuntu0.19.04.2, Copyright (c) 1999-2018, by Zend Technologies
If instead you get an error such as:
Failed loading /usr/lib/php/20170718
/ioncube_loader_lin_7.2.so: wrong ELF class: ELFCLASS32
or:
Failed loading /usr/lib/php/20170718
/ioncube_loader_lin_7.2.so: /usr/lib/php/20170718
2/ioncube_loader_lin_7.2.so: wrong ELF class: ELFCLASS64
it means that you’re using the wrong ioncube version for your system. In that case you just need to swap the file under /usr/lib/php/20170718/ioncube_loader_lin_7.0.so with the correct one and restart php again.