-
Notifications
You must be signed in to change notification settings - Fork 37
PHPStorm (or IntelliJ) Integration
- If you are using IntelliJ IDEA, you'll need to install the PHP, PHP Docker and PHP Remote Interpreter plugins from the marketplace (PHPStorm comes with these by default)
- Install PHPUnit for your site as per these instructions.
- Open settings
- Go to PHP (In IntelliJ this is found under Languages & Frameworks)
- Under CLI Interpreter, click the ... button
- Remove any existing interpreters in the list
- Add an interpreter, selecting From Docker, Vagrant, VM, WSL, Remote...
- Select Docker Compose
- Under Server, click New and add a new Docker daemon using the relevant type for your OS then click OK
- MacOS: Rancher Desktop, or if you don't have Rancher, Docker Desktop
- Windows: Docker for Windows
- Linux: Unix socket

- Add Configuration files, with the files being: (in the following order)
totara-docker-dev/docker-compose.yml
, andtotara-docker-dev/compose/php.yml
(wheretotara-docker-dev
is the path of this docker-dev respository on your machine)

- Select a PHP container under Service, e.g. php-8.3-debug
- Click OK
- Untick Visible only for this project
- Set Lifecycle to Connect to existing container
- Your CLI interpreter should look something like this:

- Click OK
- For CLI Interpreter, select the interpreter you just added and click OK
- Under Path mappings, add a mapping for your local totara code directory, where Local Path = your local sites folder (e.g.
/Users/mark/totara-sites
) and Remote Path =/var/www/totara/src
(i.e. theLOCAL_SRC
andREMOTE_SRC
vars in your docker-dev.env
file)

- Go to PHP > Test Frameworks
- Add a test framework, selecting PHPUnit by Remote Interpreter
- Select the interpreter you added and click Apply
- Set Path to script to be
/var/www/totara/src/SITENAME/test/phpunit/vendor/autoload.php
, whereSITENAME
is the name of your site's subdirectory (if you do not have multiple sites set up, this can be omitted). Note: For Totara 12 or older/Moodle, this will need to be/var/www/totara/src/SITENAME/vendor/autoload.php
- Set Default configuration file under Test Runner to be
/var/www/totara/src/SITENAME/test/phpunit/phpunit.xml
, whereSITENAME
is the name of your site's subdirectory (if you do not have multiple sites set up, this can be ommitted). Note: For Totara 12/Moodle or older, this will need to be/var/www/totara/src/SITENAME/phpunit.xml
- Click OK

You should now be able to run unit tests directly from within the IDE. If you set up XDebug as documented below, you will also be able to set breakpoints within in your tests too.

-
Ubuntu & Windows: Set the
HOST_IP
variable in your docker-dev.env
file to be172.17.0.1
. Mac Users can skip this step - Open settings
- Go to PHP > Servers
- Add a server, with the name being
totaraXX
(whereXX
= the PHP version, e.g.83
), the host beingtotaraXX.debug
, the port being80
, and the debugger beingXdebug
. If you have multiple sites set up with subdomains, you can set the host to beSITENAME.totaraXX
. Note: the name beingtotaraXX
is important, it won't work if you useSITENAME.totaraXX
orSITENAME.totaraXX.debug
. - Tick Shared (next to Name)
- Tick Use path mappings, and set the absolute path on the server to be
/var/www/totara/src
(or/var/www/totara/src/SITENAME
if you have multiple sites set up)

XDebug should now work and the IDE will listen and activate breakpoints when the Start Listening for PHP Debug Connections setting is enabled.
You can trigger your breakpoints when visiting http://SITENAME.totaraXX.debug/
pages in your browser, or when running unit tests within the IDE (if you are using a totaraXX.debug
host), or when running a PHP script while in a php-X.X-debug
container.
-
In the database tool pane, add a new database and select the DBMS you wish to view (e.g. PostgreSQL or MySQL) under Data Source
-
Set the Host to be
localhost
-
Set the Port, User and Password values to be the same as what is listed in this table
-
Download Drivers if they are missing

- Under the Schemas tab, select the database schemas you want to be able to view (or select All schemas_)
- Click OK
- Click Refresh in the Database panel
You should now be able to view tables and use the database console for the DBMS you added.
PHPStorm/IntelliJ can be slow when indexing Totara project files due to the sheer amount of code we have. It can be made quicker by excluding some directories that we don't need from indexing.
You can add non-important files and directories to the list of exclusions by copying the contents of this file into your project's main .iml file,
which will be located at .idea/PROJECTNAME.iml
(e.g ~/totara-sites/integration/.idea/integration.iml
)
This can make the indexing of your project up to 30-40% faster.
Copyright (c) 2025 Totara Learning Solutions Limited