php_file.icoRendering macro to execute PHP script
Developed by

Thomas Mortagne, XWiki Development Team

Active Installs67
0 Votes
LicenseGNU Lesser General Public License 2.1

Installable with the Extension Manager


Macro used as an entry point to execute PHP script. It's based on Quercus PHP engine and synchronized on its versions.


Unlike the other scripting languages available for XWiki, PHP is a semi-templating scripting language, which means that it must explicitly wrap code sections inside <?php ?> markers:

Parameters definition

See the Script Macro for details.

Example 1

{{php}}<?php echo 'Hello World!'; ?>{{/php}}

Hello World!

Example 2

Some *wiki* content.
{{php}} Some static content inside the PHP macro,
<?php echo("and some dynamic content."); ?> {{/php}}

Example 3

Calling Java methods.

{{php}}<?php echo($doc->getDocumentReference()); ?>{{/php}}



A current limitation of the Quercus library is that variables and class definitions are only valid inside the same macro block.

{{php}} <?php $i = 5; ?>
$i will be visible inside the same macro block:
<?php echo ($i); ?>
The correct value of i will be printed, 5.

Unfortunately, here $i will not be valid:

{{php}} <?php echo ($i); ?> {{/php}}

Prerequisites & Installation Instructions

We recommend using the Extension Manager to install this extension (Make sure that the text "Installable with the Extension Manager" is displayed at the top right location on this page to know if this extension can be installed with the Extension Manager). Note that installing Extensions when being offline is currently not supported and you'd need to use some complex manual method.

You can also use the manual method which involves dropping the JAR file and all its dependencies into the WEB-INF/lib folder and restarting XWiki.

Release Notes




  • The extension is now a Contrib extension synchronized on Quercus versions.
  • Upgraded to Quercus 4.0.46


Dependencies for this extension (org.xwiki.contrib:macro-php 4.0.65):

  • org.xwiki.platform:xwiki-platform-rendering-macro-script 6.4
  • com.caucho:quercus 4.0.65

Get Connected