Installation
Overview
Aspose.Slides for PHP via Java runs in two processes. Your PHP script uses PHP classes that pass every call through PHP/Java Bridge to Aspose.Slides, which runs on Java inside Apache Tomcat. This article explains how to set up both sides, install the package with Composer, and run a short script to verify the installation.
Prerequisites
- PHP 7.0 to 8.3, with
allow_url_include = Oninphp.ini. Your scripts load the bridge’s client library,Java.inc, from Tomcat over HTTP. On PHP 8.4 and later,Java.incstops with the error “end() expects exactly 1 argument” whenever PHP’sxmlextension is loaded, and the Windows builds of PHP always load it. - Composer.
- Java 8 or later. A JRE is enough.
- Apache Tomcat 9. PHP/Java Bridge is built on the
javax.servletAPI, which Tomcat 10 and later no longer provide, so the bridge does not start there. - PHP/Java Bridge 7.2.1, its latest release. Its web application,
JavaBridge.war, runs in Tomcat.
This article runs Tomcat and your PHP scripts on the same computer. Aspose.Slides opens and saves files inside Tomcat, so every path that your scripts pass to it must be valid there.
Install on Linux
These commands install everything in your home folder on Ubuntu 24.04. On other distributions, install the same packages with the distribution’s package manager.
-
Install PHP, Composer, Java, and the download tools, then turn on
allow_url_includefor the PHP command line:sudo apt-get update sudo apt-get install -y php-cli composer default-jre-headless curl unzip sudo sed -i 's/^allow_url_include = Off/allow_url_include = On/' "$(php -r 'echo php_ini_loaded_file();')" -
Download Apache Tomcat 9 and PHP/Java Bridge, put the bridge’s
JavaBridge.warinto Tomcat’swebappsfolder, and start Tomcat. Tomcat unpacks the WAR file intowebapps/JavaBridgeas it starts:cd ~ curl -fsSLO https://archive.apache.org/dist/tomcat/tomcat-9/v9.0.122/bin/apache-tomcat-9.0.122.tar.gz tar -xzf apache-tomcat-9.0.122.tar.gz curl -fsSL -o php-java-bridge.zip "https://sourceforge.net/projects/php-java-bridge/files/Binary%20package/php-java-bridge_7.2.1/php-java-bridge_7.2.1_documentation.zip/download" unzip -o php-java-bridge.zip JavaBridge.war -d apache-tomcat-9.0.122/webapps apache-tomcat-9.0.122/bin/startup.sh -
Create a project folder and install Aspose.Slides for PHP via Java from Packagist:
mkdir ~/hello-slides cd ~/hello-slides composer require aspose/slides -
Stop Tomcat, copy the Aspose.Slides JAR file from the package to the bridge’s
WEB-INF/libfolder, replace the bridge’sJava.incwith the PHP 8 version from the package, and start Tomcat again:~/apache-tomcat-9.0.122/bin/shutdown.sh cp vendor/aspose/slides/jar/aspose-slides-*-php.jar ~/apache-tomcat-9.0.122/webapps/JavaBridge/WEB-INF/lib/ unzip -o vendor/aspose/slides/Java.inc.php8.zip -d ~/apache-tomcat-9.0.122/webapps/JavaBridge/java/ ~/apache-tomcat-9.0.122/bin/startup.shOn PHP 7, skip the
Java.increplacement. Tomcat takes a few seconds to start, and it must be running whenever your scripts use Aspose.Slides.
Install on Windows
-
Install PHP 8.3 for Windows and add its folder to the
PATHenvironment variable. Copyphp.ini-productiontophp.iniin the same folder. Inphp.ini, setallow_url_include = Onand uncomment theextension_dir = "ext",extension=openssl, andextension=ziplines. Composer needsopensslto download packages, andzipto unpack them unless 7-Zip is installed or anunzipcommand is onPATH. -
Install Composer.
-
Install Java and set the
JAVA_HOMEenvironment variable to its folder. Tomcat does not start without it. -
In Command Prompt, download Apache Tomcat 9 and PHP/Java Bridge, put the bridge’s
JavaBridge.warinto Tomcat’swebappsfolder, and start Tomcat. Tomcat’s scripts find Tomcat through theCATALINA_HOMEvariable, so keep using the same Command Prompt window for the next steps. Tomcat unpacks the WAR file intowebapps\JavaBridgeas it starts:cd %USERPROFILE% curl -fsSLO https://archive.apache.org/dist/tomcat/tomcat-9/v9.0.122/bin/apache-tomcat-9.0.122-windows-x64.zip tar -xf apache-tomcat-9.0.122-windows-x64.zip set CATALINA_HOME=%USERPROFILE%\apache-tomcat-9.0.122 curl -fsSL -o php-java-bridge.zip "https://sourceforge.net/projects/php-java-bridge/files/Binary%20package/php-java-bridge_7.2.1/php-java-bridge_7.2.1_documentation.zip/download" tar -xf php-java-bridge.zip -C "%CATALINA_HOME%\webapps" JavaBridge.war "%CATALINA_HOME%\bin\startup.bat" -
Create a project folder and install Aspose.Slides for PHP via Java from Packagist:
mkdir %USERPROFILE%\hello-slides cd %USERPROFILE%\hello-slides composer require aspose/slides -
Stop Tomcat, copy the Aspose.Slides JAR file from the package to the bridge’s
WEB-INF\libfolder, replace the bridge’sJava.incwith the PHP 8 version from the package, and start Tomcat again:"%CATALINA_HOME%\bin\shutdown.bat" copy vendor\aspose\slides\jar\aspose-slides-*-php.jar "%CATALINA_HOME%\webapps\JavaBridge\WEB-INF\lib\" tar -xf vendor\aspose\slides\Java.inc.php8.zip -C "%CATALINA_HOME%\webapps\JavaBridge\java" "%CATALINA_HOME%\bin\startup.bat"On PHP 7, skip the
Java.increplacement. Tomcat takes a few seconds to start, and it must be running whenever your scripts use Aspose.Slides.
Verify the Installation
Save this script as hello.php in the project folder. It creates a presentation with one text box and saves it next to the script:
<?php
require_once("http://localhost:8080/JavaBridge/java/Java.inc");
require_once(__DIR__ . "/vendor/aspose/slides/lib/aspose.slides.php");
use aspose\slides\Presentation;
use aspose\slides\SaveFormat;
use aspose\slides\ShapeType;
$presentation = new Presentation();
try {
$slide = $presentation->getSlides()->get_Item(0);
$shape = $slide->getShapes()->addAutoShape(ShapeType::Rectangle, 50, 50, 400, 100);
$shape->getTextFrame()->setText("Hello, Aspose.Slides!");
$presentation->save(__DIR__ . "/hello.pptx", SaveFormat::Pptx);
} finally {
$presentation->dispose();
}
Run it from the project folder:
php hello.php
The script writes hello.pptx, with one slide that holds the text box. Without a license, the slide also carries an evaluation watermark; see Licensing.
The script includes aspose.slides.php directly: Composer’s autoloader cannot load these classes, because they are all defined in that one file. It also passes an absolute path to save, because Aspose.Slides runs inside Tomcat and resolves a relative path against Tomcat’s working folder, not your script’s.
FAQ
How can I verify that Aspose.Slides is integrated correctly?
Run the script in Verify the Installation. If it writes hello.pptx without errors, PHP, PHP/Java Bridge, and Aspose.Slides are working together.
Why does my script stop with “Failed opening required ‘http://localhost:8080/JavaBridge/java/Java.inc’”?
PHP could not load Java.inc from Tomcat. If the message before it says that the http:// wrapper is disabled, set allow_url_include = On in the php.ini file that your PHP command line loads; php --ini shows which file that is. If it says “Connection refused”, Tomcat is not running yet: start it, or wait a few seconds until it has started.
How can I limit memory consumption when processing large presentations?
Raise JVM memory limits only as high as needed, and close each Presentation instance in a finally block to release the cache promptly. This prevents out‑of‑memory errors and keeps overall memory usage predictable during batch operations.
Can I exclude unwanted export formats to shrink the final JAR size?
Current Aspose.Slides releases are shipped as a single monolithic library, so you cannot disable specific exporters such as PDF or SVG at build time.