Thursday, June 26, 2008

Practical PHP and MySQL

I'm taking a summer course in Building Data Driven Websites - not that I thought I'd learn much in such a course at SCILS, but I'd like to graduate on time, and need the credits, and Bill Crosbie is just the type of rare teacher that can keep even me awake and interested. Our book is Practical PHP and MySQL: Building Eight Dynamic Web Applications (Amazon by Jono Bacon. Now, I know it's not a real book like, say, ESA3 by Frisch, which has a healthy web presense. But this thing is all code and doesn't even have a web site, let alone easy code downloads!


The book does come with a heavily customized Ubuntu LiveCD. However, when I popped it in my OpenSuSE workstation, I couldn't really make much out of the CD - there was certainly no easy-to-find "this is the code" directory. Well, after some exploring, I mounted the SquashFS filesystem and poked around a bit. Strange... seems to only have one real user (root) and, though they claim this is a fully-functional LAMP server, no Apache or MySQL. Really weird. Well, after poking for a few minutes, I found the holy grail - /root/.bash_history was intact! Just a quick look through it with less and I found what I was looking for: /opt/lampp. It appears that the install is actually ApacheFriends' LAMPP, or XAMPP for Linux (gotta wonder if the guy writing this book doesn't even know how to install Apache... I'm sure XAMPP for Linux is more bloated than a customized build of Apache/MySQL/PHP from source, especially since it's only being used to host 8 sample projects, so a lot could be left out).


Anyway, it appears that LAMPP is running in a chroot'ed environment. The actual sample code is rooted at /opt/lampp/htdocs/sites. It seems that all of the PHP files are also owned by root and chmod'ed 777! And the top-level index.php file makes use of absolute links, so obviously he never thought that someone may want to copy the sample code and use it on a real box.


I just can't imagine someone who's a beginner with Linux, let alone a Windows person, trying to get this source code onto a machine where they can actually play with it. And... to make the situation worse... the LiveCD has vi and vim, but no Emacs!!!! Eeeek!!


For anyone who needs it, I have the archive available on my site. For non-*nix people, you'll need Gzip or an equivalent program to extract it.

Labels: , , , ,

Wednesday, June 18, 2008

Custom MediaWiki Sidebar; New Blog?

As you may have noticed, some Firefox 3 buttons have popped up not only here on my blog, but also on my wiki. While adding the buttons to Blogger was a simple addition to the template, getting them in the sidebar of MediaWiki wasn't exactly as easy (yeah, I'm considering the arduous project of moving my whole 102+ page wiki to Drupal or another good F/OSS CMS).

After some serious grepping through the source, and adding HTML comments to see where they appeared, I finally found a solution to add the button to the MediaWiki sidebar - though I'd really like it to appear below the search box (I guess that's something for my to-do list). I'm using the MonoBook skin (though somewhat modified). I'm using "MonoBook nouveau", and it should be the version that shipped with MW 1.10.1. In this version, I added the code around line 166. Specifically, this was added before the <div id="p-search" class="portlet"> line, and after the end of the foreach ($this->data['sidebar'] as $bar => $cont) loop. This threw the button in a box directly above the search box, and below all of my sidebar links.

The code looked something like:

<?php } ?>
<!-- firefox link added to MonoBook.php by jantman 2008-06-18 -->
<div class='portlet' id='p-logos'>
<h5>Cool Stuff</h5>
<div class='pBody'>
<ul>
<li><a href="http://www.spreadfirefox.com/node&id=238326&t=305"
target="_blank"><img border="0" alt="Firefox 3" title="Firefox 3"
src="http://sfx-images.mozilla.org/affiliates/Buttons/firefox3/110x32_best-yet.png"
/></a></li>
</ul>
</div>
</div>
<!-- end firefox link -->
<div id="p-search" class="portlet">


In other news, I'm taking a Data Driven Websites class this summer (PHP/MySQL, but for some reason they switched to a Windows server... endless problems, and I can't even edit with Nano on the server, let alone emacs). Our first project was to build a blog engine, which I'm working on right now. Anyway, it got me thinking... the one thing that Blogger is missing is the ability to post to a given category, and allow users to view or subscribe to a specific category (or everything). So I think I may look into writing something like that myself, if I can't find a good alternative that's already done and is F/OSS. Regardless, I'll probably be keeping the Blogger template as well as (ugh) moving over all of my current posts, which Blogger chose to store in raw HTML. So there's going to be a lot of parsing on my future...

PS - When I get a new blog engine, I'm also going to go for a slightly modified template that uses relative widths and placement - so that code, like the snippet here, fits the screen correctly.

Labels: , , ,

Monday, September 17, 2007

Bug/Issue Tracking - Update / Review of Eventum

So, after many hours of investigating potential bug/issue tracking packages, I have chosen one. And gone live with it, all in one weekend. After much evaluation, my final choice was Eventum from MySQL (I'm using the current version, 2.0.1). I will admit that it is not perfect. There are some features I wanted that weren't there, and the documentation is awful. But it's written in PHP.

That being said, it is very much a community-driven project. The support on the mailing list, both from other community members and from Bryan Alsdorf, has been wonderful. I had some issues viewing the help documents, specifically those in pop-ups, but I've been told that most new documentation has been moved to the wiki at the link above.

The project provides for advanced bug- and issue-tracking including time tracking, file attachments, and customizable statuses, priorities, and categories. It also provides email integration, both in terms of sending email alerts and opening issues (as well as updating and tracking) by parsing incoming emails. The email alerts worked out-of-the-box, but I did not configure parsing of emails.

One of my main requirements which was met perfectly by Eventum is its' ability to easily handle multiple projects. It also has a built-in capability to allow anonymous issue submission (enabled on a project-by-project basis). You can define custom fields for issues on a project-by-project basis, and set them as required fields for either registered users, anonymous users, or both.

One feature that I found lacking was the possibility for a user to view all of the open issues assigned to them. Currently, all user interface is on a project-by-project basis. Therefore, listing of open issues is only available for the currently selected project. To cope with this, I hacked together a little PHP script that just queries the database for issues by user and displays it in a simple little page.

One of the major features about Eventum that caught my eye was integration with a version control system (SCM, as far as the Eventum docs are concerned). The feature list stated integration with CVS and SVN. When I actually looked into integrating it with CVS, however, the problems began. Firstly, the javascript-based help popup would not display anything, let alone the proper page. Installation was otherwise perfect under Apache2. I was forced to browse to the included HTML file manually and check it out. The overview seemed simple enough - throw a script in your CVSROOT loginfo file, update a few variables in the web-based Eventum configuration, and you're off to the races. Reading on, I found that the installation page was a confusing jumble of references to a deprecated perl script and the current PHP script to call from loginfo. Furthermore, database access is provided by having the script called from loginfo parse the logging information and then *run a HTTP GET* on a local script served in the Eventum web directory. This added level of abstraction not only confuses me to no end, but also introduces the possibility for malicious users to insert data in the Eventum SCM database simply by visiting a well-known URL.

More importantly, the script provided to be called by loginfo seems to expect the old CVS logging format, not the new one being provided by my installation of CVS 1.12.12. While annoying, this ended up being a minor fix in the provided "process_cvs_commits.php" - I simply had to rewrite the argument parsing code so that it no longer expects the file, old version, and new version (%{sVv}) information to be space-separated on the command line in the form of s,V,v tuples, but expects everything to be space-separated. I should be cleaning up my fix a bit and submitting it for inclusion in the next release.

Once patched, CVS integration works perfectly. Simply append an identifier to the end of your commit log message, such as "(issue: 21)" or "(bug: 21)" and the commit will be automatically associated with the issue of that number. When viewing an issue, a list of associated CVS commits can be viewed.

It must be remembered that, as I have read, Eventum is used internally by MySQL. It is, therefor, a mature project that is well tested in one circumstance. I believe that it is mature and generally well-working (though I've heard reports that the 2.x tree isn't as stable as the older versions, which are most likely still in use at MySQL). It must also be noted that the issue with CVS integration is most likely only with the newer CVS versions using the new logging format (I don't know when the switch was made) and will probably not be noticed in older projects which have established CVS systems.

Now, for the opinion section. Eventum has thousands of features. I have detailed every issue that I have, which total about five. I found it to be a stable system, ready-to-run out of the box. Overall, I think it has the best feature set of the open-source bug tracking systems that I surveyed, which are probably most of the ones out there. It's a great project which I'd recommend to anyone, though if you want more advanced features (like integration with CVS, or things not offered such as anonymous issue viewing) you should be comfortable with coding in PHP until someone makes patches available.

Labels: , , , ,

Wednesday, March 21, 2007

Poor PHP

Well, as mentioned below, today I was doing a little research. On the futility of a Computer Science major. Specifically, on the fact that the overwhelming odds are that in a career in IT, system administration, or even web programming, I'll probably never apply 90% of what I learn in CS courses.



So, I went looking for online certificate programs, knowing that most of the vendors' programs run $500 or more just for testing. I came by eCertificates.com. And this brings me to another topic... I clicked on the "Software Programming" category, and was surprised to see no PHP test. On a hunch, I looked under "Web Design", and sure enough, there it was.



I know this is a common misconception, and I know that because it plays so well with the web, and Apache, PHP has been pigeonholed as a web language. Maybe I'm just crazy, or maybe it's just because I know PHP better than anything else. But PHP is NOT a web programming language. It is a programming language that happens to work very well with web applications.



Using fread() and fwrite() I can slam together a command-line menu-based PHP script for administration quicker than I could write the def's for a Python script. I've done it, I have a number of PHP CLI-based scripts running on my machines. Database access with PHP is a no-brainer. And one day, when I get around to reading my "ancient" pile of books and learning NCurses, PHP will be right there with me.



So I guess it is just a fact of the modern web mentality. But PHP has myriad uses aside from web applications and web content handling. Sure, my web site is written in it. But one of my backup scripts is, too. And more importantly, if I'm working with a database that already has a PHP-based web frontend, PHP seems like the natural choice for a CLI-based administration backend.

Labels: , , , ,