PHP Mac Zend ionCube Extension Disaster

ionCube

Getting ionCube working on most servers (e.g. Linux, Mac, and Windows), is, and always will be, a challenge. Of all the software I'm forced to use, setting this is up once or twice a year, is never fun. This is the same story for the last 10+ years.

Lately I've been using a Mac M2 and Laravel Herd, and again, I pretty much had to relearn the whole experience from scratch. Unfortunately deployment issues keeps one away from programming so it's critically important to make the installation friction as close to zero as possible.

The dreaded message

Script error: the ionCube Loader for PHP needs to be installed. The ionCube Loader is the industry standard PHP extension for running protected PHP code, and can usually be added easily to a PHP installation. For Loaders please visit get-loader.ioncube.com and for an instructional video please see http://ioncu.be/LV

Download the files

To start, first download the files. Already this is a challenge with their website and their trap to get you to volunteer your email address. But here is the closest to a direct link that I could find:

https://www.ioncube.com/loaders.php

On there are too many choices, but for Linux use the 64 bits one and for Mac Mx use the ARM M1 one. Skip their trap.

Store the files to a temporary location

This might seem like the most obvious step, but if you have to download these files every six months it would be good to know where you stored them the last time heh? Let me quickly make it clear - the desktop is not the best place.

Decompress the files

ionCube makes things hazy by showing both `tar.gz` and `zip` downloads. It's 2024, both are available on everywhere.

Find the PHP location

Next comes the huge challenge. Where to store these damned files? Remeber on a Mac you need the `loader_dar` files...

So you could try this for Herd:

➜  ~ cp ~/Desktop/ioncube/ioncube_loader_dar_8.2.so /opt/homebrew/lib/php/pecl/20220829
cp: /opt/homebrew/lib/php/pecl/20220829/ioncube_loader_dar_8.2.so: Permission denied

As you can see, not possible, not good, and either way `20220829` was a guess. So what next? First, let's establish what exactly `20220829` is supposed to be:

➜  ~ php -v
PHP 8.1.29 (cli) (built: Jun 14 2024 07:21:07) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.1.29, Copyright (c) Zend Technologies
    with Zend OPcache v8.1.29, Copyright (c), by Zend Technologies

As you can see, I'm using PHP version `8.1.29`.

Next, let's deduce what `20XX` is supposed to be. Let's consult with Herd, which fortunately has exceptional documentation:

https://herd.laravel.com/docs/1/advanced-usage/additional-extensions

So heard says store it in `20220829`? Well ok then, let's try the above copy again, this time using sudo:

sudo  cp ~/Desktop/ioncube/ioncube_loader_dar_8.1.so /opt/homebrew/lib/php/pecl/20220829

That works. What next? Let's update the `.ini` file for Herd:

sudo vi "/Users/username/Library/Application Support/Herd/config/php/81/php.ini"

Add this line:

zend_extension=/opt/homebrew/lib/php/pecl/20220829/ioncube_loader_dar_8.1.so

When you click save, you'll get this convoluted mess:

O deployment god please help me
In the terminal you'll now see this disaster:

php -v
Failed loading /opt/homebrew/lib/php/pecl/20220829/ioncube_loader_dar_8.1.so:  dlopen(/opt/homebrew/lib/php/pecl/20220829/ioncube_loader_dar_8.1.so, 0x0009): tried: '/opt/homebrew/lib/php/pecl/20220829/ioncube_loader_dar_8.1.so' (code signature in <A8D637F2-757A-3E67-A848-F49AE7C58A28> '/opt/homebrew/lib/php/pecl/20220829/ioncube_loader_dar_8.1.so' not valid for use in process: library load disallowed by system policy), '/System/Volumes/Preboot/Cryptexes/OS/opt/homebrew/lib/php/pecl/20220829/ioncube_loader_dar_8.1.so' (no such file), '/opt/homebrew/lib/php/pecl/20220829/ioncube_loader_dar_8.1.so' (code signature in <A8D637F2-757A-3E67-A848-F49AE7C58A28> '/opt/homebrew/lib/php/pecl/20220829/ioncube_loader_dar_8.1.so' not valid for use in process: library load disallowed by system policy)
PHP 8.1.29 (cli) (built: Jun 14 2024 07:21:07) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.1.29, Copyright (c) Zend Technologies
    with Zend OPcache v8.1.29, Copyright (c), by Zend Technologies

Fix Mac

I wanted to call this title Fix Mac Permissions but in my opinion Mac is broken for developers so let's move on quickly.

sudo xattr -d com.apple.quarantine /opt/homebrew/lib/php/pecl/20220829/ioncube_loader_dar_8.1.so

Finally we have a working copy.

➜  ~ sudo xattr -d com.apple.quarantine /opt/homebrew/lib/php/pecl/20220829/ioncube_loader_dar_8.1.so
➜  ~ php -v
PHP 8.1.29 (cli) (built: Jun 14 2024 07:21:07) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.1.29, Copyright (c) Zend Technologies
    with the ionCube PHP Loader v13.3.1, Copyright (c) 2002-2024, by ionCube Ltd.
    with Zend OPcache v8.1.29, Copyright (c), by Zend Technologies

Restart Herd

But will your application work? Nope, ionCube is attached to a webserver and / or FPM process so the web server has to be restarted.

If you don't, you still see this:

Script error: the ionCube Loader for PHP needs to be installed. The ionCube Loader is the industry standard PHP extension for running protected PHP code, and can usually be added easily to a PHP installation. For Loaders please visit get-loader.ioncube.com and for an instructional video please see http://ioncu.be/LV

Bonus Round

Localhost fixing for blank MariaDB password for WHMCS

WHMCS insist on having a password the MySQL user, which kind of makes sense, but not if you're using standard Laravel workflows for localhost.

To fix this:

mysql -u root [ENTER]mysql> CREATE USER 'whmcs_user'@'localhost' IDENTIFIED BY '12345678';
Query OK, 0 rows affected (0.02 sec)

mysql> GRANT ALL PRIVILEGES ON whmcs_2024.* TO 'whmcs_user'@'localhost';
Query OK, 0 rows affected (0.01 sec)

Rebooted, back to square one?

After rebooting, you might experience the same Mac security warning nonsense. Do this:

sudo xattr -d com.apple.quarantine /opt/homebrew/lib/php/pecl/20220829/ioncube_loader_dar_8.2.so

Symbol not found in flat namespace error

You might receive this problem:

Failed loading /opt/homebrew/lib/php/pecl/20220829/ioncube_loader_dar_8.2_ts.so:  dlopen(/opt/homebrew/lib/php/pecl/20220829/ioncube_loader_dar_8.2_ts.so, 0x0009): symbol not found in flat namespace '_compiler_globals_offset'

My advice is don't use the _ts.so file. Use `vi` to remove it:

vi "/Users/eugene/Library/Application Support/Herd/config/php/82/php.ini"

Other troubleshooting Steps

cat "/Users/username/Library/Application Support/Herd/config/php/82/php.ini"
curl.cainfo=/Users/eugene/Library/Application Support/Herd/config/php/cacert.pem
openssl.cafile=/Users/eugene/Library/Application Support/Herd/config/php/cacert.pem
pcre.jit=0

memory_limit=2048M
upload_max_filesize=2M



auto_prepend_file=/Applications/Herd.app/Contents/Resources/valet/dump-loader.php


zend_extension=/opt/homebrew/lib/php/pecl/20220829/ioncube_loader_dar_8.2.so
zend_extension=/opt/homebrew/lib/php/pecl/20220829/ioncube_loader_dar_8.2_ts.so


Also try


sudo xattr -d com.apple.quarantine /opt/homebrew/lib/php/pecl/20220829/ioncube_loader_dar_8.2.so

sudo xattr -d com.apple.quarantine /opt/homebrew/lib/php/pecl/20220829/ioncube_loader_dar_8.2_ts.so


Good luck