Dec/090
PHP-on-Tomcat (Part II)
The original goal of being able to run PHP on top of Tomcat was to allow simple development of PHP based applications like Wordpress and/or bbPress. To get these working I needed a database.
The wildly popular mySQL database has a nice installer for OS X. Mine installed to /usr/local. I did the install ages ago and forgot what the “root” database user password was. Ooops! No matter, there are some great resources online talking about how to go about resetting permissions. I opted for the incredibly easy, but utterly insecure method (from inside the terminal) :
- Stop the existing server
- Restart telling it to turn off permissions:
mysqld_safe --skip-grant-tables --user=_mysql & - Jump into the mysql shell application:
mysql -u root mysql - Change the “root” password:
UPDATE mysql.user SET Password=PASSWORD('#########') where user='root'; - Persist privilages:
FLUSH PRIVILEGES;
Next on the list was exposing my mySQL database to the Tomcat hosted PHP code. Step 1 was making sure I have mySQL JDBC drivers installed, Step 2 was creating a JNDI datasource in the context, and step 3 was getting the PHP to use it.
The officially supported mySQL Connector/J was a quick download. The JAR file for it was dropped into the $CATALINA_HOME/lib directly. Good to go. The context file was more of a challenge, under the $CATALINA_HOME/conf/Catalina/localhost I created an XML config file that matched the name of my webapp – php.xml – where I declared the JNDI datasource. It took some tweaking and reading around but finally ended up coming together:
<Context reloadable="true">
<Resource
name="jdbc/mydata"
auth="Container"
type="javax.sql.DataSource"
username="root"
password="#########"
driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/test"
/>
</Context>
The documentation for Quercus states
Scripts can use the jndi name directly:
<?php // standard PHP //mysql_connect($host, $username, $password, $dbname); // using JNDI lookup mysql_connect("java:comp/env/jdbc/myDatabaseName"); ?>
But that doesnt help me to run Wordpress as I’m not about to go modifying their code. Never fear, there’s another option. The documentation for Quercus also says that you can put an entry into the WEB-INF/web.xml file that forces all database connections to go through the same underlying JNDI datasource:
.
.
.
<!--
Tells Quercus to use the following JDBC database and to ignore the
arguments of mysql_connect().
-->
<init-param>
<param-name>database</param-name>
<param-value>jdbc/test</param-value>
</init-param>
.
.
.
So, a quick update to point at my own datasource and wall was ready to go. I downloaded and unzipped wordpress into the PHP webapp directory, pointed a browser at http://localhost:8080/php/wordpress and found myself stepping through the famous 5 minute install. Less than 5 minutes later I was looking at the main page of a fully-functioning Wordpress install.
Dec/092
PHP-on-Tomcat
I am generally a Java programmer (if my day-job is to be believed) and hacking my way through Apache configuration isnt my idea of a fun evening. For some odd reason my trusty old black MacBook hasnt had the best of times when I try to enable “web sharing” and then try executing PHP scripts – all I get is a dump of the source. Time for a creative solution to the problem!
The folks that created the Resin App Server have a 100% Java implementation of PHP 5 released under the Open Source GPL license, known as Quercus. So step 1 was to download the latest release that will run on non-Resin app servers: quercus-4.0.1.war.
This was the point where I also realized that I dont have an up-to-date install of Apache Tomcat on my system either. Step 2 was to go download Tomcat 6.0.20 and install it.
Many applications need to know where Tomcat lives, and that means setting the CATALINA_HOME environment variable to point to the install. In a terminal I edited the global startup file for the terminal: sudo vi /etc/bashrc to add the line:
CATALINA_HOME=/Users/paul/Documents/Devt/3rd-party/apache-tomcat-6.0.20
Step 3 was to $CATALINA_HOME/bin/startup.sh to start tomcat and then point a browser at http://localhost:8080/quercus-4.0.1/ where I saw confirmation that all was well:
Testing for Quercus™…
Congratulations! Quercus™ Open Source 4.0.1 is interpreting PHP pages. Have fun!
I didnt like the URL though, but that’s easily changed. I simply nuked the quercus-4.0.1 directory under $CATALINA_HOME/webapps and renamed the Quercus WAR file “php.war”. I bounced Tomcat and bingo – a “php” directory I could drop files into. As a final test, I created info.php
<?php
phpinfo();
?>
and hit it on the pretty URL: http://localhost:8080/php/info.php. All displayed correctly. I was off and rolling running PHP on top of Apache Tomcat! Stay tuned for Part II – getting Wordpress running on top of PHP running on Tomcat!
Nov/090
Let me count the ways
Eclipse IDE
How do I loathe thee? Let me count the ways.
I hate thee to the depth and breadth and height
My soul can reach, when feeling out of sight
For the ends of Being and ideal Grace.
I loathe thee to the level of everyday’s
Most quiet need, by sun and candle-light.
I despise thee freely, as men strive for Right;
I loathe thee purely, as they turn from Praise.
I loathe thee with the passion put to use
In my old griefs, and with my childhood’s faith.
I loathe thee with a hatred I seemed to lose
With my lost saints,—I loathe thee with the breath,
Smiles, tears, of all my life!—and, if God choose,
I shall but loathe thee better after death.
With apologies to the original author. How is it possible for a simple piece of computer software to draw out such ire? Grrr.
Oct/081
And the score: IBM 0 / MacBook 2
What an amazingly frustrating weekend. <sigh />
The annoying IBM Thinkpad refused to connect … neither wired, or wireless (on any one of three different wireless networks, no less). On the other hand my trusty MacBook hopped online in every given scenario. Oh, and before this turns into a Windows vs. Apple cage match, the Dell Inspiron laptop also connected flawlessly in every case.
Can I have those hours of my life back, maybe trade them in against 5 minutes of something more productive … like fly-fishing in an empty pond or something?
Oh, and running the build-tool (“maven”) offline proved to be interesting – looks like when I get back to the corporate network the central code repository has been “blacklisted” by the tool because it was unreachable in multiple builds. Just perfect!
Sep/080
SCRUM in the news
The gaming site Gamasutra recently posted an article about EA building “Battlefield Heroes”, and how their use of an agile SCRUM-based development methodology allowed them to release in the aggressive timescales that the executives asked for. Very cool!
Sep/081
WrimoRadio
Every year during the National Novel Writing Month they publish a weekly podcast called “WrimoRadio“. I have been consistently impressed with the quality and have thought to send in a small editorial piece to them but was too busy with other things (like writing a 50,000 word novel in a month). I am very tempted to send in the “plot bunnies” piece this year though.
I was on Facebook and noticed Chris Baty (founder of the National Novel Writing Month) changed his status to “Chris Baty needs a WrimoRadio producer so he doesn’t die in November.”
Podcast production is something I enjoy, I have the hardware investment and the previous experience. Should I ping him and offer? With everything else I am doing that would be one more reason I might not make 50,000 words. On the other hand I could put it on my resume – “podcast production for the National Novel Writing Month” – so it has its benefits too. Maybe I am oversimplifying what it would take … it wouldn’t be the first (or the last) time I’d done that!
Sep/080
Random bits
A couple of news stories on the English “Daily Telegraph” news site caught my eye. First one that said:
Legal bid to stop CERN atom smasher from ‘destroying the world’
The world’s biggest and most expensive scientific experiment has been hit by a last minute legal challenge, amid claims that the research could bring about the end of the world.
James Gillies, spokesman for CERN, insisted that despite the huge amounts of energy the Large Hadron Collider will produce, it posed no risk to the safety of the planet.
He said: “The case before the European Court of Human Rights contains the same arguments that we have seen before and we have answered these in extensive safety reports.
The Large Hadron Collider will not be producing anything that does not already happen routinely in nature due to cosmic rays. If they were dangerous we would know about it already.
“We are now concentrating on firing the first beams around the collider and then on fine tuning it until we can get collisions, when the science will start.”
A spokesman for the European Court of Human Rights confirmed the lawsuit had been lodged and the petition to obtain an emergency injunction against CERN was rejected. She said: “There will therefore be no bar to CERN carrying out these experiments but the applicants can continue with this case here at the ECHR.”
and then, another story
JK Rowling ‘delighted’ at decision to ban Harry Potter encyclopaedia written by a fan
JK Rowling has spoken of her “delight” at winning her copyright battle against a fan who planned to publish a Harry Potter encyclopaedia.
She had described the Harry Potter Lexicon as “wholesale theft” of her work.
In court papers, Mr Vander Ark, 50, said he was a teacher and school librarian in Byron Centre, Michigan, before recently moving to London to begin a career as a writer.
He said he joined an adult online discussion group devoted to the Harry Potter books in 1999 before launching his own website as a hobby a year later.
Since then, neither Rowling nor her publisher had ever complained about anything on it, he said.
In his court statement, Mr Vander Ark said the Lexicon “enhances the pleasure of readers of the Potter novels, and deepens their appreciation of Ms Rowling’s achievement”.
Rowling, who has earned £560 million through the Potter books, told the judge she had not brought the case for the money, but because the Lexicon was “atrocious” and “sloppy” with “very little research”.
The seven Potter books, which ended last year with the final book in the series, Harry Potter And The Deathly Hallows, have been published in 64 languages, sold more than 400 million copies and produced a film franchise that has pulled in 4.5 billion US dollars at the worldwide box office.
On the one hand Science and on the other Fiction. Totally me. Add to that the “geek” factor that I am running the new Google Chrome web browser (and loving it)!
I wonder, in the JK Rowling story, when it says “adult online discussion group devoted to the Harry Potter” if that means it was a group for grown ups, or whether the tone of the postings were “adult” in nature. If it’s the latter I can clearly see why Rowling would object – slashfic ought to have nothing to do with a kid’s genre book! Authors have a tenous (at best) relationship with fan fiction writers. Some encourage it (Rowling has said in the past that she was “flattered” that people wanted to write their own stories based on her characters), some tolerate it, others actively try to stamp it out (Anne Rice has consistently and aggressively prevented fan fiction based on any of her characters, as has Raymond E. Feist and Anne McCaffrey).
Aug/082
Einstein Quote
What a genius:
Make everything as simple as possible, but not simpler.— Albert Einstein
Apply it early and apply it often.
Jul/080
Send & receive email
Zawinski’s Law of Software Envelopment
Every program attempts to expand until it can read email. Those programs which cannot so expand are replaced by ones which can.
— Jamie Zawinski
