PhpStorm can be configured to use mdc containers directly which eliminates the need to install PHP binaries, webserver or database in your macOS.
There is also a simple Docker manager in Services tab in PhpStorm which can be used to stop/start the containers.
To enable PHP Xdebug debug mode add following into your mdc.env
file and do a full MDC rebuild:
MDC_PHP_XDEBUG_MODE=debug
For performance reasons you may set MDC_PHP_XDEBUG_MODE=off
and then instead of php
use php-debug
in remote interpreter settings.
Then verify mdc instance is up and running - see Quick start section above.
Then open your Moodle project directory in PhpStorm and add a remote PHP CLI interpreter:
- Open "Preferences / PHP"
- Add new CLI Interpreter by clicking "..."
- Click "+" and select "From Docker, Vagrant, VM, WSL, remote..."
- Select existing Docker server or click "Docker compose" and press "New..." in "Server:" field
- Select ./compose.yaml file in "Configuration files:" field
- Select webserver in "Service:" field
- Press "OK"
- Switch lifecycle to Connect to existing container ('docker-compose exec')
- If you have set
MDC_PHP_XDEBUG_MODE=off
for performance reasons, then change PHP binary tophp-debug
- Press reload icon in "PHP executable:" field, PhpStorm should detect correct PHP binary
- if you enabled Xdebug you should also see "Debugger: Xdebug 3.x.x"
- You should customise the interpreter name at the top and make it "Visible only for this project"
- Press "OK" to save interpreter settings
- Verify the new interpreter is selected in "CLI Interpreter:" field
- Press "OK" to save PHP settings
First make sure your MDC project is running and PHPUnit was initialised. The remote PHP CLI interpreter must be already configured in your PhpStorm.
- Run MDC
phpunit-init
command - Open "Preferences / PHP / Test Frameworks"
- Click "+" and select "PHPUnit by remote interpreter"
- Select your Docker interpreter that was created for this project and press "OK"
- Verify "Path to script:" field is set to
/var/www/html/vendor/autoload.php
- Verify "Default configuration file:" field is enabled and set it to
/var/www/html/phpunit.xml
- Press "Apply" and verify correct PHPUnit version was detected
- Press "OK"
- Optionally delete all pre-existing PHP interpreters
You may want to delete all unused interpreters. To execute PHPUnit tests open a testcase file and click on a green arrow gutter icon.
First make sure your MDC project is running and Behat was initialised. The remote PHP CLI interpreter must be already configured in your PhpStorm.
- Run MDC
behat-init
command - Open "Preferences / PHP / Test Frameworks"
- Click "+" and select "Behat by remote interpreter"
- Select your Docker interpreter that was created for this project and press "OK"
- Set "Path to Behat executable:" field to
/var/www/html/vendor/behat/behat/bin/behat
- Enable "Default configuration file:" field and se it to
/var/www/behatdata/behatrun/behat/behat.yml
- Press "Apply" and verify correct Behat version was detected
- Press "OK"
- Optionally delete all pre-existing Behat interpreters
Remote Node.js interpreter does not seem to work correctly with MDC containers.
You can let PhpStorm download and install Node.js in macOS if necessary, see "Preferences / Languages & Frameworks / Node.js".
You can connect to database directly using container domains.
Make sure your MDC project is running and test site was initialised.
Then setup new database connection in PhpStorm through the exposed port, for example:
- Open "Database" tab in PhpStorm
- Press "+" and select "Database source / PostgreSQL"
- Set "User:" field to
moodle
- Set "Password:" field to
m@0dl3ing
- Set "Database:" field to
moodle
- Set "Host:" to "db.<project_directory_name>.orb.local", keep "Port:" to default database port
- Press "OK"
- Refresh the database metadata
- Open "Preferences / Language & Frameworks / SQL Dialects"
- Set "Project SQL Dialect:" field to "PostgreSQL"
- Press "OK"
- Copy
.phpstorm.meta.php/dml.php
file frommdc/templates/
directory into your Moodle project - You may need to use "File / Invalidate caches..." and restart the IDE
As a test open lib/accesslib.php and find some full SQL statement and verify the SQL syntax is highlighted and SQL syntax errors are detected.