Development Environment for Coppermine Development Environment for Coppermine
 

News:

CPG Release 1.6.26
Correct PHP8.2 issues with user and language managers.
Additional fixes for PHP 8.2
Correct PHP8 error with SMF 2.0 bridge.
Correct IPTC supplimental category parsing.
Download and info HERE

Main Menu

Development Environment for Coppermine

Started by 406man, August 01, 2023, 06:22:14 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

406man

There's a posting elsewhere in this forum about creating a suitable environment for developing Coppermine but it's years out of date. Earlier this year I created my own environment and thought that others who are considering developing code for Coppermine might be interested in it. I won't claim that this is the best possible set of tools or that it's the only solution but it has worked for me. I found the most difficult part was getting PHP debugging to work which took several days and a lot of web searching.  In retrospect it's not difficult. The problem for me was the lack of suitable instructions – or at least I didn't find any despite a lot of searching. There are numerous different areas that need configuring and the available instructions only cover specific areas. Nothing I found covered the whole picture so I had to piece it all together from various web sites and forum postings. It was this factor more than anything else that drove me to write this article. I've kept the article short and hope others find it understandable and useful. If it encourages you to develop some code for Coppermine I've succeeded.

All the software I will describe is free and available for download at the time of writing (August 2023). As I'm a Windows user all software runs on Windows 10. 

PHP Script and Text File Editor
PSPad from pspad.com     A neat little editor covering multiple languages. I used version 5.0.7 which unfortunately is not bug-free. If you avoid editing text files (.txt) it's adequately reliable. I kept using it despite the crashes because it has so many good features including line numbers and small text size. The display of matching pairs of normal and curly brackets is brilliant when trying to get the coding right: just click the cursor to the left of the bracket you're interested in. Also the ability to indent or un-ident selected blocks of code. The colour coding of different elements in a PHP script is very helpful, particularly the different colour for comments. From memory I think display of line numbers has to be enabled in the settings. You must have this when developing PHP as error messages refer to line numbers.

PHP and Web Run-time Environment.
When Coppermine is deployed it typically runs on a shared server at an Internet Hosting company. For development purposes there's no need to use a hosting environment. You can run everything on a single PC at home, even on a laptop. It does help to have large screens and a proper keyboard and mouse, however.

The WAMP package (www.wampserver.com) contains everything you need. W is Windows, A is Apache (the web server), M is MySQL (the database), P is PHP. It also includes PHPMyAdmin for database administration. A brilliant feature is that it holds multiple versions of PHP and allows you to swap between them. This is great for running old CPG 1.5.x code on PHP 5, CPG 1.6.x code on PHP 7 and trying out CPG 1.6.x on PHP 8. If the PHP version you want isn't included in the distribution you can download it from one of the WAMP download sites and install it. Also included is Xdebug, a debugger add-on for PHP.

To use it, the WAMP environment needs to be started, usually via an icon it creates on the desktop. It then puts a little icon in the Windows system tray. It's green when all is running well. Left and right mouse clicking on the icon brings up different menus to shut down, restart, change versions etc

Debugging Environment
If you want to run PHP code with an interactive debugger (which you really should do if you're developing PHP code and want to save time & effort) you must have a suitable development environment. I used VS Code: https://code.visualstudio.com/download   Despite being maintained by Microsoft it is free.

I've written a short guide to debugging Coppermine PHP code with Xdebug and VSCode in a separate article.

VSCode is an editor and can be used to edit your PHP scripts and other files. It will check syntax which can be useful although it is buggy. Frequently I found that after a problem was identified and I fixed it, VSCode said there was another problem when there wasn't. I had to close the file and re-open it to clear the warning message. To restrict VSCode to a particular part of the file structure in your application  - for example Coppermine's plugin directory – use the Open Folder option on the File menu to select that directory.

The Variables window in VSCode is fantastic. You can check the value of a variable at any time by drilling down through the list. Really useful is being able to check Object structures or what's in the Supercage.

Web Browser
Everyone has their favourite but here I recommend Firefox as it has a very good debugging environment for HTML and CSS (Press the F12 key) and an excellent add-on for PHP Xdebug called "Xdebug Helper".  It is a must-have in my opinion. Feel free to disagree but add a reply here to say what you use and why it's better.

File Search Utility
It's essential to be able to search the Coppermine code to find, for example, variables and function names. For example you may want to find the scripts where function get_pic_data is called and defined.
AstroGrep (https://astrogrep.sourceforge.net) is superb

File Comparison
At some point you'll want to compare two different versions of a file to find the differences between them. WinMerge is excellent for this (winmerge.org)

Summary
The tools I've described are those I've used when developing plugins. They all worked well for me. If you prefer different tools, do please reply to this posting to say what they are and their advantages.