Saturday, June 20, 2009

Setting up xampp for multi site serving on XP

The locations of the files you will need to edit.

[driveletter:]\xampp\apache\conf\httpd.conf (only if there is a permissions issue)
[driveletter:]\xampp\apache\conf\extra\httpd-vhosts.conf
C:\WINNT\system32\drivers\etc\hosts

See this for the official apache virtual host documentation if you get lost. I say that because every tutorial on the web told me to do that. I didn't in fact find it insightful specifically for this xampp setup.

Okay. On with the steps.

Create a new folder for your virtual hosts.

I created a new site folder under \xampp\1sites\ called newdevsite. I figure I'll access that folder quite a bit, so I added the '1' in front of it so it will float to the top of the folder listing.

Edit your hosts file to point your new virtual host to your local IP address.

Simply make a new line underneath the existing entry in the same format with your new development site.

I entered:

127.0.0.1 newdevsite

Edit httpd-vhosts.conf

Uncomment 'NameVirtualHost *:80' in httpd-vhosts.conf. Get rid of the "##".

I created the following two entries. From what I read, it's recommended to use forward slashes. It worked that way for me. If you want to continue using your existing site in xampp, you will need to add that as a virtual host as well.
<VirtualHost *:80>
DocumentRoot "c:/xampp/htdocs"
ServerName localhost
ServerAlias localhost
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "c:/xampp/1sites/newdevsite/public_html"
ServerName newdevsite
ServerAlias newdevsite
</VirtualHost>
Restart apache and test

If you get a 403 permissions error on the new virtual host

Once I got the VirtualHost directives correct, I was getting 403 permission errors on the newdevsite. (I don't know enough about apache administration, so to be safe I would footnote that I would not do the following on a live Apache installation).

The edit proposed by Preast in the following link straighted out the rest of my woes.
http://www.php-editors.com/forums/apache-help/2205-virtual-hosts-error-403-a.html (Copied text from that post below).

Did I mention I have no idea if this is a bad idea on a production server? The following is an edit to the httpd.conf file.

<directory>
Options FollowSymLinks
AllowOverride None
Order deny,allow
Allow from all ## Changed this from "Deny from all" ##
Satisfy all
</directory>

Hijacking the live url of sites that use explicit URLs to themselves

If you are editing a site that is already live you could override http://thelivesite.com to point to your development location at 127.0.0.1 at every request.

Simply make an entry in the hosts file with 127.0.0.1 www.thelivesite.com

With this type of development environment set up and assuming you will be working with at least a few copies of live web sites, I would highly recommend getting notepad++ and leaving a copy of your hosts file open in it so you can tweak it on the fly.

Saturday, May 30, 2009

Elusive PHP syntax errors - a strange fix.

I found a variety of syntax errors when debugging a PHP script lately. Since the PHP parser isn't the clearest when it comes to debugging (and these were terribly elusive) here are are some methods that I found to solve the problem.

The line numbers associated with the errors were no help at all - the error just wasn't found on line 1. And then when the line number changed, it was not found on line 34 either.

These errors included both "Unexpected $end" and "Unexpected [T_variable]" errors.

As this script was a mixture of PHP and HTML, the page was fairly long and daunting. I looked for missing brackets, tick marks, quotes, and reserved words.

I reviewed every line of code for semicolons and matching parentheses and brackets. No luck. I tweaked variable names in the lines above where the reported error was. Still no luck. Since from what I've read about debugging PHP syntax errors said the line number is 'around' or typically a line or two above the reported line number, I sat there staring at each place the bad formatting of code should have been. Nothing!

One method I came up with that I didn't find online was to separate the script into chunks. As it was a syntax error (how things were formatted), I simply segmented the script as I could, added a little HTML 'hello world' to the page (to make sure I wasn't just seeing the PHP white screen of death), and previewed different sections of the code up on the server.

I copied each logical segment of code to a new file and ran it. No errors. Eventually I copied the entire contents. Still no error in the new file. At that point I was about to pop in frustration.

I was methodical and the fact that the errors changed when I tweaked code in the original file (which seemed formatted correctly to me to begin with), was annoying to say the least.

It could be that there was a small part of the file which was corrupted while I had it open in notepad++ or maybe up on the server. Strangely enough, copying the entire contents of the script to a new file and then saving it over the old one did the trick.

It ran beautifully after that.

So, a few PHP syntax debugging tips for myself to remember in the future. Especially if they become elusive and persistent like this last time.

1.) Use something like Notepad++ to help highlight matching brackets, reserved words, quotes, and semicolons.
2.) See the PHP Syntax error wiki.
3.) If it's a long script and the syntax errors jump to different line numbers after tweaks, first copy the entire contents to another file then take segments of the code and paste it into a new file.

Sunday, May 03, 2009

Quick Searches. Possibly the end of my temporary keyword mania.

When I started this blog a week or so ago, I didn't think the first few would be dedicated to Firefox features but I have to mention Quick Searches before letting go of the keywords tips.

I was talking to Matt (Drupal enthusiast extraordinaire) about how I'd found what I thought was a more convenient way to search. I was both surprised and happy to be wrong again when he explained searching Google was as easy as creating a new tab, then pressing the tab key to get to the Google search native to Firefox.

Pressing control-t to open a new tab, then hit tab. You're ready to search Google.

Neat. Good on'ya Matt. I was using this religiously.

Then complimentary to my keywords kick (see last blog), I started reading into Firefox's Quick Searches.

My biggest sigh of relief has been using the Quick Searches for SourceForge.net. The intro page loads too slowly. Now all I do is hit control-L (or control-T if I want it in a new tab) to get to the address bar and type: sf image map

.... and I get a list of matches for image map software from SoureForge's projects. Even neater.

The sweet part about it is that it works for any site with search. Simply right-click in any single search field and you are prompted to create the shortcut. Enter your keyword (a short one like 'g'!) and save your bookmark.

I save mine to my own Quick Searches folder. From what I've read it's supposed to be there already, but I must have deleted mine thinking it was nothing but clutter.

Lifehacker's article on using Firefox Quick Searches is better than what I would put together this evening. I highly recommend checking it out if you are interested in the keyword shortcuts.

The pages I need fastest.

I tried using FastDial for FireFox but it didn't do everything for me that I needed.

Having each of my most used pages ready to click whenever I opened a new tab was hip but unfortunately it wasn't fast enough for me. An intuitive-type person might like FastDial. You're presented with boxes where small representations or icons are displayed for you to click on.

That's too many steps for me. When I'm looking for a link to page when I already know what that page is, I don't want to look through eight or ten images to figure out which one it is.

I took advantage of keywords instead. They are only available in Firefox. Internet Explorer allows you to assign shortcut keys, but not keywords.

A few links to help get you acquainted:
Firefox keywords
Lifehacker article on Firefox keywords - with some good links in the article.

What I've set up at my daytime job is a series of keywords to the pages that I use most frequently. Since there are a lot of different tasks I need to perform when an incoming call comes in or a form is submitted, I need to get to a variety of different web pages without too much thinking.

What I've done is take the most common pages and bookmarked them, while adding a keyword - specifically a keyword associated with the task.

When someone calls in to change their payment type on their account, I type 'pay' in the address bar (or hit control-l to get to the address bar and then type 'pay' and then hit enter).

I do this for a few others as well.
whois - Network Solution's whois check
signup - account creation form internal to my company
(webservername) - direct access to an web-admin interface of a server.
mon - a monitoring utility
st - staff pages internal to our company
kb - the company knowledge base
modems - a link directly the reference for DSL modems that we use at work

I'd imagine this would be especially useful with frequently used Google Documents - and I may be making more web pages specifically with this use in mind.

At home I've been thinking a few would be helpful
fb - facebook.com
bank - self explanatory, no?
ms - myspace
tw - twitter
bl - my blogger account
e - my webmail account.

I might even go further and open multiple tabs with a single keyword if I find the need for it. That might come in handy for web development projects.

Saturday, May 02, 2009

A fresh start for my tech blog.

As I've found a new focus for the site, I'm going to be sharing the answers to the questions that have befuddled me during the course of my knowledge and technology work.

All of the old blog posts have been deleted (they were largely useless anyway), and I'll be posting as regularly as I can with the answers I come up with about working in technical support and knowledge-work.

I define knowledge work for myself basically as managing my incoming responsibilities and how I handle them until completion. Being headstrong, there many frustrations in the office environment that I run into.

This is the best place I can think of to share the answers I come up with to combat or work around those frustrations.

Also, if you're someone who works with any sort of technology I'm sure you run into the problem of unresolved questions. No amount of training can completely prepare you for what goals are going to be thrown at you as a worker.

Meeting and resolving the challenges that arise in the office, obstacles in web development, and combating my own bad habits with office-work are primarily the focus of this blog.

If you're in a similar boat, I hope you find these things useful (including the many forehead smacks about the painfully-obvious). Those aren't usually fun for me, but they might be entertaining for you.