How to use PHP inside Confluence pages
Platform Notice: Data Center Only - This article only applies to Atlassian products on the Data Center platform.
Note that this KB was created for the Data Center version of the product. Data Center KBs for non-Data-Center-specific features may also work for Server versions of the product, however they have not been tested. Support for Server* products ended on February 15th 2024. If you are running a Server product, you can visit the Atlassian Server end of support announcement to review your migration options.
*Except Fisheye and Crucible
Purpose
For security reasons, Confluence does not allow PHP code inside pages. However, it's possible to install an Apache and PHP module on the same server, and include the PHP file so that the output can be shown inside Confluence.
Solution
Install Apache + PHP in a server (it can be the same server used for Confluence).
In Confluence navigate to Confluence Admin > Manage Add-ons and enable the
html
andhtml-include
macros.Create a PHP file for test purposes on your Apache. Make sure that it's working locally.
Copy the URL from the PHP file and paste it in Confluence Admin > Whitelist so that Confluence will trust it.
Create a page on Confluence and use the
html-include
macro with the URL from Step 4.This will allow the PHP file to be interpreted by Apache, and the result will be shown in Confluence.
Was this helpful?