How do I install and configure PHP on Windows for Matomo?
Once you’ve setup MySQL on Windows for Matomo, continue with setting up PHP using the step-by-step guide below.
Install PHP
-
Download PHP Thread Safe and select the right processor architecture (64 bit or 32 bit)
-
Extract the content of this file to a secure location, for example
C:\Program Files\PHP
. Make sure this directory inherits secure permissions (admin-only write access). -
Optionally, add
php.exe
to System Properties > Environment Variables > User variables. Select Path and click Edit. In the Variable value field, add the path to the secure location:
C:\Program Files\PHP
Note: Do not extract PHP into a user-writable location such as C:\PHP
and do not add the directory to the system-wide PATH using setx /M
. Doing so permits DLL hijacking and can allow non-admin users to execute code with elevated (SYSTEM) privileges.
Ensure that you can run PHP from the Windows Command Line
To test if the PHP installation is successful, run the following from the command line prompt:
php -m
If you get the following error screen when trying to run php
, download and install the Visual C++ Redistributable for Visual Studio 2015 from the following link: https://www.microsoft.com/en-us/download/details.aspx?id=48145.
Configure PHP and load all required PHP extensions
Several PHP extensions are required in order to run Matomo Enterprise. Most (but not all) of required extensions are enabled by default in PHP7. Required extensions include: PDO with MySQL driver, GD, json, libxml, dom, SimpleXML, zlib, SPL, iconv, mbstring, Reflection.
Follow these instructions to configure PHP to install Matomo:
-
Navigate to the PHP folder and copy the
php.ini-production
file and rename it tophp.ini
-
Open the
C:\Program Files\PHP\php.ini
file with your favorite text editor -
Find the
extension_dir
directive and change so that it properly locates the ‘ext’ folder, i.e.:
extension_dir = "C:\Program Files\PHP\ext"
- Similarly, configure the session path to point to your temp folder:
session.save_path = "C:\Windows\Temp"
- Next, configure the memory limit:
memory_limit = 2G
- Next, configure the maximum execution time:
max_execution_time = 600
- Next, enable the logging of errors in the error log file:
log_errors = On
- Next, disable the logging of errors on screen:
display_errors=Off
- Enable the following Extensions used in PHP by Matomo.
Add the following lines at the top of the file under the[PHP]
section:
(Note: For PHP 8.0 onwards, please usephp_gd.dll
overphp_gd2.dll
)
; Activate PHP extensions required by Matomo
extension=php_curl.dll
extension=php_gd2.dll
extension=php_mbstring.dll
extension=php_mysqli.dll
extension=php_openssl.dll
extension=php_pdo_mysql.dll
- Save the file as
php.ini
You can now test that PHP still works by running in the command from the Windows Command Line:
php -m
Note that at the start of the installation process, Matomo will automatically report if any of the required PHP extensions are missing from your system. And when you have installed Matomo successfully, you can open the system check at any time by going to Matomo > Administration > Diagnostic > System Check.
PHP should now be successfully setup on your Windows server.
- Next, you will need to go through setting up IIS for Matomo on Windows: How do I install and configure IIS on Windows for Matomo?
- If you don’t already have MySQL setup, you can follow the steps in the guide: How do I install and configure MySQL on Windows for Matomo?.
- Once you have everything setup, don’t forget to setup a scheduled task for archiving reports in Matomo.