Setting up Moodle for development

Setting up Moodle for development

by hajar zankadi -
Number of replies: 15

Hello moodlers 

I hope you are doing well

I have many questions concerning the configuration of moodle environment for development and I would like to know what i am missing ( I am new to moodle development)

1- I installed wampserver 64 and downloaded the moodle package for moodle 3.6.2+

2- I launched the install script from wamp ( I unpacked the package in the www directory of wamp and I configured all the necessary requierements to launch the installation) ---> Success

3- I Installed ECLIPSE PDT ( including the necessary plugins: PHP development tools + PHP development SDK)

4- I configured the debugging: For the web server ( Apache), in Eclipse and in Chrome browser

5- I Installed Egit for Eclipse and I cloned the moodle repository into eclipse

6- when it comes to choose the branch to work with, here I am confused: should I clone the master branch or a stable branch ( I am still not good with Git)

I want to know what I still missing in my configuration, note that my OS is Windows 7 64 bit. is there something else to install/configure.

Thank you for your help

Average of ratings: -
In reply to hajar zankadi

Re: Setting up Moodle for development

by Mark Johnson -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

In general, that set up sounds pretty good for getting started with development. We mainly use PHPStorm instead of Eclipse, as it has better integration with automated testing tools than PDT, and tends to perform better in my experience. However, PHPStorm isn't free.

One other thing you should look at setting up is Selenium for running behat tests.

Assuming you are developing plug-ins, you will want to develop against either the latest stable branch, or the latest LTS stable branch, depending on your support requirements: https://docs.moodle.org/dev/Releases#Version_support

If you are doing core development, you should develop against the master branch. If you are doing bug fixes, you will also need to test your fixes against supported stable branches.

Average of ratings: Useful (4)
In reply to Mark Johnson

Re: Re: Setting up Moodle for development

by hajar zankadi -
Thank you for you clarification
I want to develop a course format plugin so according to what you've highlighted above, I am doing a core development so I should work on a master branch ( correct if i'm wrong)
As i said i installed moodle 3.6.2+ package so i am developing against a stable branch not a LTS one ( again correct me if i'm wrong)
Thank you again for your help and if there is something else that will be useful to me (as i am begginer) let me know it
kind regards
In reply to hajar zankadi

Re: Setting up Moodle for development

by Michael Milette -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers Picture of Translators
Hi Hajar,
Here are a few relevant articles I wrote which will be relevant to you getting started:

Getting Started with Moodle Development
https://www.tngconsulting.ca/getting-started-moodle-development/

Getting Started with Moodle Development - Your first Moodle block
https://moodle.org/mod/forum/discuss.php?d=355789

Developing a new plugin
https://moodle.org/mod/forum/discuss.php?d=352360#p1429639

As for cloning Moodle using GIT, you actually clone a repository. This includes every version of Moodle since the beginning of time. Then you checkout a branch (the version of Moodle you want to work on). So, for example, if you wanted to clone Moodle and work on Moodle 3.6, you would:

cd path_to_your_webroot
git clone git://git.moodle.org/moodle.git
cd moodle
git branch --track MOODLE_36_STABLE origin/MOODLE_36_STABLE
git checkout MOODLE_36_STABLE

This will setup the Moodle files for the latest release of Moodle 3.6, not Moodle 3.6.2. Nobody will ever let you submit a change to a past minor release.

You don't normally want to modify the core Moodle code unless you are fixing a bug or creating new functionality. I would suggest you familiarize yourself with the Moodle code/database and how it works before tackling such changes. When you do start working on Moodle core issues, you will want to fork (clone) a copy to your own GitHub account first. This is because you cannot contribute directly to the Moodle project. You will need to create a copy of the branch, make your changes, commit them, push them to your GitHub repository fork and submit an issue in the Moodle Tracker. When it comes time to integrate the changes, you will need to submit the change for all currently supported versions of Moodle.

There was a little talk about editors. I use PHPStorm ($$) however I have also used Sublime Text and NetBeans for debugging. For editing without a debugging, I often use Notepad++ which work really well for Moodle's large library files. Recent versions of VSCode have improved in terms of handling large PHP files. For more ideas, see https://www.cloudways.com/blog/top-ide-and-code-editors-php-development/ .

Regardless of which editor you end up using, you will need to setup XDEBUG or XDEBUG. It's a pain to setup. There are others like the Zend Debugger, but most people I know have settled on XDEBUG for PHP development.

I really recommend that you learn how to use GIT from the command line. It is a VERY powerful tool and I have yet to see any IDE which implements all of its functionality. Eventually, you will reach a point where you need to do something and it will only be possible from the command line. GIT for Windows will not only give you the GIT command in Windows, it also gives you a BASH prompt so you can brush up on your Linux command line and a GUI interface. This is what I used when I first started. That lasted about a month before I abandoned the GUI and started using the command line. Besides, all of the instructions and examples for GIT are command line based. Think of it, By using a GUI or IDE, you actually are adding a layer of complexity because you need to figure out how to do what they are showing you using your graphical user interface.

What kind of Moodle development are you planning on doing? A theme, block, activity module, filter, local, etc? If you can share what type of development you are planning on doing, we can probably give you additional advice. For example, there are developer tools specifically geared towards theme development that might be worth mentioning.

Hope this helps.

Best regards,

Michael
Average of ratings: Useful (6)
In reply to Michael Milette

Re: Setting up Moodle for development

by hajar zankadi -

Hello sir

Thank you for this details it s very clair and very useful

I am planning on working on course format plugins 

Now i have a question according to you what is the best OS to work on ( in term of feasibility and configuration )( windows or linux) what do you recommend for me

For the configuration of the Xdebug is there a tutorial or something that will help me setting it up

I have installed Git in my workspace so according to what I understand I don t need to have Git in my IDE ?

Thank you so much again for your help



In reply to hajar zankadi

Re: Re: Setting up Moodle for development

by Michael Milette -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers Picture of Translators
Personally I like to develop in Windows however I know many people who prefer OS X or Linux. Besides being my preferred operating system (because I am familiar with it), it also gives me the opportunity to test my development on multiple operating systems since I deploy on Linux.

As for XDEBUG, the first step is to get it working. Your AMP server may already have it included, even if it is not activated. If not, you will need to do that first. It is a manual process of downloading the right DLL file (for Windows). By right DLL, I mean it has to be one that is compatible with the version of PHP you are using.

Here is an example of the XDEBUG section of my php.ini file for my installation of XAMPP. I am still trying to optimize it as it really slows down my localhost webserver when it is activated.

[XDebug]
zend_extension = "c:\xampp\php\ext\php_xdebug-2.5.5-7.1-vc14.dll"
xdebug.remote_autostart = 0
xdebug.profiler_append = 0
xdebug.profiler_enable = 0
xdebug.profiler_enable_trigger = 0
xdebug.profiler_output_dir = "c:\xampp\tmp"
xdebug.remote_connect_back = 0
xdebug.profiler_output_name = "cachegrind.out.%t-%s"
xdebug.default_enable = 1
xdebug.remote_enable = 1
xdebug.remote_handler = "dbgp"
xdebug.remote_host = "127.0.0.1"
xdebug.remote_log = "c:\xampp\tmp\xdebug.txt"
xdebug.remote_port = 9000
xdebug.trace_output_dir = "c:\xampp\tmp"
xdebug.remote_cookie_expire_time = -9999
xdebug.idekey="PHPSTORM"

If you or anyone else has ideas on how to optimize this, I am always open to suggestions.

The next thing you will need is a plugin for Chrome to turn XAMPP on and off. I use "XDEBUG Helper". You'll find it at https://chrome.google.com/webstore/detail/xdebug-helper/eadndfjplgieldjbigjakmdgkmoaaaoc?hl=en

As for having GIT in your IDE, you don't need to. You may find it convenient at times to do certain things. Personally, I got use to the command line and never looked back.

For course plugins, I would start by looking at an existing course plugin in the plugins repository on Moodle.org. Find the simplest one possible.

Hope this helps.

Best regards,

Michael
Average of ratings: Useful (2)
In reply to Michael Milette

Re: Re: Re: Setting up Moodle for development

by Richard Jones -
Picture of Plugin developers Picture of Testers
I have found this particularly helpful in setting up xdebug on your preferred IDE: https://gist.github.com/odan/1abe76d373a9cbb15bed in a Windows environment. It does list the dll's you need for various flavours of PHP as well.
Average of ratings: Useful (3)
In reply to Richard Jones

Re: Re: Re: Re: Setting up Moodle for development

by hajar zankadi -
Thank you Richard
I checked it out it's very clair and helpful
In reply to hajar zankadi

Re: Re: Re: Re: Re: Setting up Moodle for development

by hajar zankadi -
I checked my php.ini, this is  what the section of xdebug looks like:
[xdebug]
zend_extension = c:\wamp64\bin\php\php7.2.14\ext\php_xdebug-2.7.1-7.2-vc15-x86_64.dll

xdebug.remote_enable = on
xdebug.profiler_enable = off
xdebug.profiler_enable_trigger = Off
;xdebug.profiler_output_name = cachegrind.out.%t.%p
xdebug.profiler_output_dir ="c:/wamp64/tmp"
xdebug.show_local_vars=0

it seems that i am missing the other additional lines, should i add them manually or not
thank you
In reply to Michael Milette

Re: Re: Re: Setting up Moodle for development

by hajar zankadi -
Hello
Thank you for your reply
as for the dll i've already set that up as well as the Xdebuger helper. do i need to set it up also in my IDE? when i checked my php.ini i am missing this line "xdebug.idekey="PHPSTORM". should i set it up manually or there is a way that it would be added automatically
Thank you again for your help
In reply to Michael Milette

Re: Re: Setting up Moodle for development

by Michael Milette -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers Picture of Translators
One more area that existing plugins need help with in order to work with recent versions of Moodle (3.3 or later) is the pix_url() function. There are many plugins out there that are either stuck at Moodle 3.2 or the developer just never bothered to fix the issue (it happens more often than you'd think). So what is the issue?

Every once in a while, functions in Moodle become obsolete and are deprecated (removed) because it is either no longer needed or it has been replaced by a new (and hopefully better) way of doing things. This is what happened to the pix_url() function in Moodle 3.3. It was replaced by two new functions, image_url for images and pix_icon for icons.

You can identify the issue by Setting Moodle DEBUG mode to DEVELOPPER (it's in the Developer / Debugging menu). Then reload pages that make use of the plugin. If you see the following message, on the screen or in view-source, you know that the plugin needs to be fixed:

pix_url is deprecated. Use image_url for images and pix_icon for icons.

Alternatively, you can simply scan the source code for "pix_url".

I have seen developers keep things backwards compatible by checking Moodle release number and then calling the available function and others who decide to cut ties with older versions of Moodle and strictly focus on the currently supported releases. Personally I like to keep things backwards compatible as long as it is just a minor accommodation that has negligible impact on performance. Which approach you choose is really up to you.

For more information about this and other changes to the Moodle API, take a look at your /lib/upgrade.txt file. In fact, you'll find a similar upgrade.txt file in /blocks, /themes, /mod and many other directories off of your webroot.

Hope you find this useful. Looking forward to seeing your contributions to the Moodle community.

Best regards,

Michael
Average of ratings: Useful (2)
In reply to Michael Milette

Re: Re: Re: Setting up Moodle for development

by hajar zankadi -
Thank you for the information
looking forward to that too
In reply to hajar zankadi

Re: Setting up Moodle for development

by Stuart Mealor -

Hello Hajar (and others who may be new to Moodle development).
There have been some excellent post replies here from very experienced developers - which is awesome.
I thought it might be useful to add that we have a completely free basic introduction to Moodle development available online: https://www.moodlebites.com/enrol/index.php?id=228 
We actually use this course to help new developers evaluate if they are ready for one of the more in-depth Moodle developers courses.
Anyway, feel free to try this course out Hajar (and anyone else!) as we would really value any feedback you would like to provide smile
Hope it helps, Stu.
Average of ratings: Useful (2)