Advanced search  

News:

cpg1.5.48 Security release - upgrade mandatory!
The Coppermine development team is releasing a security update for Coppermine in order to counter a recently discovered vulnerability. It is important that all users who run version cpg1.5.46 or older update to this latest version as soon as possible.
[more]

Pages: [1]   Go Down

Author Topic: Development Environment for Coppermine  (Read 1752 times)

0 Members and 1 Guest are viewing this topic.

406man

  • Contributor
  • Coppermine novice
  • ***
  • Offline Offline
  • Posts: 45
Development Environment for Coppermine
« on: August 01, 2023, 06:22:14 pm »

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.
Logged
Pages: [1]   Go Up
 

Page created in 0.017 seconds with 20 queries.