Wednesday, October 20, 2010

PHP to Remote Database Error: "Can't connect to MySQL server on..."

On a new server migration project I am working on I have separate web and database servers. So, I use a private network to connect them. It took me a day to get working, so I am putting up a post to help others in similar situations.

First, just to clarify, I knew it was a web server problem (and not a network or db permissions issue), because I could connect to the MySQL server just fine from the MySQL command line on the web server. But, when I pinged the PHP web page from my browser I'd get this error:

Can't connect to MySQL server on '10.1.1.1' (13)

The problem was SELinux, which was installed and crackin' down on Apache rights.

One simple fix:
setsebool -P httpd_can_network_connect=1

More information can be found in this nice article:
http://www.ehow.com/how_2090983_connect-remote-database-under-selinux.html

SELinux would allow me to connect from the command line just fine. I could even execute the PHP script from the command line and connect fine. But SELinux did not like it when Apache tried to connect to a computer on the network. Hence the policy update, as stated above.

If you have other issues or it appears that your db server is having issues, here are some other MySQL debug tips as well.

Monday, October 18, 2010

Add Text to an Existing PDF Using PHP

I am finishing up on a project right now that fills out a PDF application for a merchant account. The software helps the user through the application process by asking more targeted questions and filling in fields that are known. In order to do this I had found two PHP libraries that work quite well.

The first is FPDF. It is a free PHP library that allows you to create PDFs. It is not a module or binary code, just a straight up PHP script library. Color me impressed. You can download it at http://www.fpdf.org/

The second bit of code you need is called FPDI. This will import a PDF as a template and allow you to overlay text. It worked quite well for my project as I was taking an existing PDF and filling in fields on top of it. Just like FPDF, it is super easy to install because all it is is a collection of PHP script files. You can download it at http://www.setasign.de/products/pdf-php-solutions/fpdi/

Here is a quick demo by FPDI on how to use these two modules together.

To make it all work I created a flat, PDF version of the template PDF. I removed all of the form fields using Adobe Acrobat. The first run I got an error: "probably uses a compression technique which is not supported". This was easily fixed by saving the PDF as PDF/A using Adobe Acrobat. (Update below.)

If you have any questions, please let me know. I'd be glad to share more of what I learned.

Update (10/22/10): I've learned that saving the PDf as a PDF/A doesn't always solve the error I explained above. What has worked, however, is running Adobe Pre-Flight on the document. If you go to "Advanced" > "Print Production" > "Preflight" and then click on "Analyze and fix", Adobe will work some magic on the document and make it work with FPDI.

Update (1/27/11): FPDI, the free version of the PDF parser, requires the PDF to be version 1.4 or below. To save a PDF in this format, open the document in Adobe Acrobat, click "Save As" and then select the type "PDF, Optimized" then click the "Settings" button and select "Adobe Acrobat 5.0". This will save the PDF in version 1.4, which was last used in Adobe Acrobat 5.0!

Tuesday, October 5, 2010

Removing WordPress LINK: NEXT and PREV

In WordPress, in the HTML HEAD, there are two <link> lines that are present. One is rel="next" and the other is rel="prev". Now, if you have some pages that you don't want just anyone to find (and the private and password-protect features are not appropriate), this little feautre may reveal them to the public.

To remove the LINK data from the HEAD:
  1. First, pull up your template editor by going to Appearance >> Editor.
  2. On the right side is a list of files. Click on "Theme Functions" or "functions.php" to edit it.
  3. At the top, just after "<?php" add these lines of code:
    1. remove_action('wp_head', 'parent_post_rel_link', 10, 0);
    2. remove_action('wp_head', 'start_post_rel_link', 10, 0);
    3. remove_action('wp_head', 'adjacent_posts_rel_link_wp_head', 10, 0);
  4. Click "update file" at the bottom

All done! The link, rel="next" and rel="prev", as well as "start" and "parent", should be all gone from your template.

Friday, October 1, 2010

iPod Touch Battery Life Issue

I love my iPod touch. But it had a problem. After upgrading to the latest and greatest software (iOS 3), the battery life was awful, to say the least. I charged it, set it on the kitchen table in the evening and by morning it was completely dead. Something was very wrong.

The first thing I tried was to disable all push notifications and alerts. And, after charging it up, I left it plugged in for a few extra hours (just in case). Unfortunately, I saw no change in performance. The iPod would die, again, within 24 hours, even if I had not used it. This was getting ridiculous.

I found a blog post that suggested performing a restore. So, I gave this a try. I plugged in the iPod to my laptop, and clicked the restore button in iTunes. After a few warnings and some waiting, the iPod was back to its squeaky-clean state. And I can say that now, after 3 days, that the restore worked and the battery life is back to normal. I haven't charged it in days and it is still going strong.

Bottom line, if your iPod touch's battery life was cut dramatically short after upgrading to iOS 3, try a full restore. Worked for me.

Leave a comment if you've had similar experiences. I'd be interested to hear if it worked for others as well.

Saturday, September 25, 2010

Innovation

I've been thinking a lot about innovation lately.

There are lots of areas where innovation is strong and advancing. I think of cellular phones, as one great example. Companies like Apple lead the pack, forcing the entire industry to innovate. And it seems like it is a good thing for all of us. I also think of Google and the area of internet services, with major innovation in how we use email and how we search the web. There is also, and this has traditionally been the case, a lot of innovation in the area of art and fashion. You can always get art and fashion that is not innovative, but it is not hard to find people who are pushing new boundaries and forging new styles in these areas.

There are also a lot of sectors where innovation is stagnate or happening at a slow pace. I think of the American automobile industry. There has not been much great innovation in a while and when there is any it is in response to foreign innovation. I also think of telecommunication companies and their service offerings. For instance, home telephone service has had little innovation in quite a while. Plain old telephone is plain old telephone and doesn't look like it is going to change any time soon (which is probably why so many younger people are willing to go without it, now).

So, what areas need innovation? This is my question. And, how can I contribute to these areas, not being a CEO of a major company? How can I use my talent and drive to affect change in these areas that desperately need innovation? These are the questions I've been exploring, lately...

Thursday, September 2, 2010

A Better Browser

This is my PSA to help the world rid itself of bad browsers:

So I just wrapped up major development on a 3-month project and I am stoked to be done. But, I am also more and more convinced of Internet Explorer's ... deficiency.

Now there are the normal "quirks" with IE that every web designer runs into (e.g., version 7's inline-block problem). These "features" are annoying and I have to deal with them often, but at least there are a number of known work-arounds to help me.

There is one major thing that I've come to see about IE in these past 3 months for which there are no work-arounds. It is dreadfully slow and clunky. Things that will run smoothly and look great on Chrome, Safari and Firefox, will look awful slow on IE. This last project uses a lot of DHTML and it has a really high level of user interaction, so naturally there are a lot of animations and fading of images, etc. IE just cannot handle it and I've had to remove a lot of animations for people who are visiting the site with IE.

So, now that the browser Google Chrome is celebrating its second birthday, I thought I'd share my thoughts about browsers once again. Use Chrome if you want a fast, responsive, useful browser. I particularly enjoy the streamlined UI. Switch between Chrome and IE and you'll notice MAJOR speed enhancements. I love Chrome and you will, too.

Tuesday, July 20, 2010

Installing Intermediate CA with cPanel

When I saw that the VeriSign EV SSL / TLS certificates required an intermediate CA to be installed, I was worried it was going to be a long and painful process. Well, turns out it is super easy to install.

It seems that some of the modern browsers have no problem when the intermediate CA is not installed, but older ones, on the other hand, don't like it. So, here is how you make your cert work on most browsers.

First, copy the appropriate intermediate CA root bundle from VeriSign. I had a standard EV SSL, so I used the first cert on this page.

Now, log in to cPanel and click on "SSL/TLS Manager" > "Activate SSL on Your Web Site (HTTPS)". Use the drop-down box to select your domain and the domain's certificate should show up (the one you installed at an earlier time, or google "install SSL certificate with cPanel"). Then, you'll see an extra text box at the bottom called "Ca Bundle (CABUNDLE)." Just paste the intermediate CA there and click "Install." Yep, it's that easy.