Setup LibXL in PHP

Many thanks to Ilia Alshanetsky for the php_excel extension for PHP 8.3+. Read his post with installation instructions, examples and benchmarks. For older PHP versions please use the php extension from Jan Ehrhardt.

Also special thanks to Maxim Shuguroff for the additional php extension for PHP8.2+, Johannes Mueller, Philip Hofstetter, Stephan Fischer, Pierre Joye and Darren Odden for additional contributions.

Linux / macOS

The easiest path is PIE (PHP Installer for Extensions), the official PECL replacement:
pie install iliaal/php-excel \
  --with-libxl-incdir=/opt/libxl/include_c \
  --with-libxl-libdir=/opt/libxl/lib64
Or build from source:
git clone https://github.com/iliaal/php_excel.git
cd php_excel
phpize
./configure --with-excel \
  --with-libxl-incdir=/opt/libxl/include_c \
  --with-libxl-libdir=/opt/libxl/lib64
make
sudo make install
Then add to your php.ini:
extension=excel.so
Make sure the LibXL shared library is in your linker path. Either install it to a standard location or set LD_LIBRARY_PATH:
echo "/opt/libxl/lib64" | sudo tee /etc/ld.so.conf.d/libxl.conf
sudo ldconfig

Windows

Pre-built DLLs for PHP 8.3 and 8.4 (both x64 and x86, TS and NTS) are attached to every GitHub release. Download the DLL matching your PHP version and architecture, drop it into your ext directory, and add to php.ini:
extension=excel
You'll also need libxl.dll from the LibXL Windows package placed somewhere in your system PATH, or in the same directory as php.exe.

License key

If you have a LibXL license, store the credentials in php.ini rather than your source code:
[excel]
excel.license_name="Your Name"
excel.license_key="your-license-key-here"
The extension reads these automatically. Pass null for the license parameters in the ExcelBook constructor and they'll be picked up from the ini settings.

The extension is open source under the PHP-3.01 license.

See PHP code examples here.

See also this article about LibXL performance in PHP.