GoDaddy’s php.ini and .htaccess for parsing .xml files

The title says it all, doesn’t it? I’ve read plenty of web articles on this, and they’re all variants of the same thing. In a nutshell, you need to create a local php.ini file and a .htaccess file. The specific file names and their respective entries will vary slightly depending on what version of PHP your hosting account is using. (There are more than 2; Some accounts use both 4 and 5.)

My hosting account runs PHP5, primarily. My .htaccess file has the entry below. Note that it doesn’t have the -cgi (as in: AddHandler x-httpd-php5-cgi) suffix.
AddHandler x-httpd-php5 .xml

My php.ini, php4.ini, and php5.ini files (yes, I have all 3) include this single line:
short_open_tag = “0″

Now files with the .xml extension will be parsed by the PHP interpreter. You’ll need to remember to manually set the content-type header of your files if they’re not HTML. In my case, I had to set the content type header to text/xml.

I had a lot of files to add the line to, plus I wanted to gzip them, so the following command came in handy: (It should all be on one line.)

find *.pdf.xml -type f -exec sed -i '1i <?php  /*Some PHP Stuff*/ ?>' {} \;

Automate FTP with Bash (on Mac OS X)

Save the code below in a file with a .sh extension, as in ftp.sh. From the command line, remember to chmod +x it so that it’s executable. Set the file to open with terminal.app. Finally, configure terminal.app to automatically close windows after a script has run. Once those steps are complete, you should be able to just double-click your file and have it FTP your stuff “automatically”.

#!/bin/bash

ftp -inv ftp.yoursite.com<<ENDFTP
user username password
cd xml
bin
lcd ~/Desktop
put "somefile.txt"
bye
ENDFTP

#Trash it
cd ~/Desktop
mv somefile.txt ~/.trash

Automating a Process – Part 1: Sudo Operations

This series picks up where my Batch post left off. We’re going to look at a few tools, one by one, and move toward a comprehensive solution to automate a process. We’ll use batch, perl, bash, and more.

OK, let’s get started.

Whether a system is remote or not is, of course, not our primary concern, but the technique used here can be leveraged in client-server network operations like SSH. Here is the situation: we need to perform basic *nix shell (bash) commands in an environment that requires sudo.

Imagine you have a private user area on a corporate hosting box. And imagine that you can’t perform any operations outside of your user area – like copying edited files into directories that are controlled by the server – without using sudo. Wow, major efficiency killer. That means every time you want to edit your print.css file, for example, you have issue a sudo command to either copy one into your hosting root or to open an editor.

Here is how you use perl to issue a sudo command without having to manually enter a password

#!/usr/bin/perl

#SUDO PASSWORD
$pass = 'YOUR_PASSWORD';

#LS the files in the DEPLOY directory
$cmd  = "echo '$pass' | sudo -S ls -l ";
$cmdStdout = `$cmd`;

print $cmdStdout;

exit;

The magic is in the echo $pass | (“echo pass pipe”), which is followed by whatever sudo command you were going to enter. The first two variables, $pass and $cmd, are just strings. $cmd will interpolate $pass so that the full string inside of $cmd is equal to:

$cmd  = "echo YOUR_PASSWORD | sudo -S ls -l ";

The final variable captures the output of the command. The back ticks tell perl to use the string $cmd as a command and run it.

Perl works nicely on *nix boxes. You can accomplish the same with shell scripting, but by bringing perl into the mix, we acquire its huge array of other capabilities.