brick-wall_375

Oh, my aching head!

| Faithful readers — there are maybe one or two — may recall that I am converting one of my websites from static html pages to, at least in part, pages generated dynamically from a database. Take this website, for example: it's all static pages. Once I've written one of these articles, it's never going to change (unless I go back to correct a typo or add a picture). Each article is one page of html code.

But sometimes you have information that changes frequently or consists of lots of different pieces that you would like to mix-and-match at will. A site for real-estate offerings is a good example. If every house for sale was a separate page, the site wouldn't be very useful. What you really want to be able to do is get specific information from the site: I want to see.... All the houses for sale in Amityville; All the 3-bedroom houses in either Amityville, Podunk, or Looneyburg. For that you need to have all the house information in a database and be able to pull out just the pieces the user wants. That means using scripts to do the grunt work of getting the info and putting it into a custom html page for the server to send.

I had long ago figured out the database design and how to get the information into it. I even had working prototypes of the scripts needed to get the info from the database and generate the html pages. What I hadn't figured out was the user access system. You see, this site has parts that are "members only," and it has a lot of information that can only be maintained by making it possible for users to edit the information they know about. That means fine control over who can see and edit what.

Last week I began work on the access system. As the week went on it became more and more complex, until by the end of the week I had worked my brain into such a lather that it mostly just wanted to shut down. But not to worry: after relaxing with the Brunch Bunch on Sunday and drinking a fair amount of champagne, I woke up with a start during Sunday night knowing exactly how it should be done. And Monday, I was able to start over from scratch and do in half a day what I had been working on for over a week.

This week trouble reared its ugly head on Wednesday when I discovered that the screen on my development laptop was black except for the ominous words: Unable to find an operating system. It had tried to install updates overnight and its brain was completely scrambled — not unlike mine at the end of last week. Thankfully I was able to get it restarted in "safe mode" so I could dump all my files. And by rolling it back to an earlier date, I got it to come back to life.

But this was bloody ominous. What if the same thing were to happen again? (As it turns out, the same thing did happen again two days later!) I decided to move all my development to a back-up machine that I set up some weeks ago. But here was the kicker: it would not process any of the pages with php scripting. Instead, the browser would say, Do you want to download this file or open it? No! None of the above!

What made it even more strange was that it worked just fine if I put the actual filename into the browser:

addressbars_425
It should work either way, and it did on my development laptop

Here's where the brick wall comes into the story. I went Googling to find out why the Apache web server would not parse php files: "apache will not parse php" found "2,570,000 results." Obviously, I was not alone. Somebody should have figured this out, right? There ought to be a sticky post on an Ubuntu forum with the solution, right?

Wrong! I must have gone through 500 of these search results. The responses to question-askers fell into the usual general categories: "What's wrong with you, don't you know how to ask a proper question?" "Post your code." "Reinstall everything." "You have to enable/install libapache2-mod-php5" (wrong, it's already installed and enabled!). "Increase memory allocated to PHP" (wrong, Apache and PHP can run with very little memory!). "Restart your server" (just how many dozens of times is one expected to do this with the same result?)

The threads dealing with this question ran on, and on, and on, and on. Even the ones marked "resolved" didn't fix the problem. How many days must I waste on this fruitless quest? And why isn't there a simple answer to what has got to be a really simple problem? After all, millions of websites run happily with the LAMP stack of software (Linux, Apache, MySQL, and PHP). Surely someone knows the answer!

The simple answer had to be that something was missing in the Apache configuation to tell it to process the PHP files. But how and where to tell it? Late this afternoon I finally read a post from someone who had fixed it by adding a couple of lines to the VirtualHost configuation for the website:

    <Directory /home/.../.../.../public_html/ >
	    ...
	    AddHandler php5-script php
	    DirectoryIndex index.php index.html index.htm
    </Directory>

Duh! So simple: "If Apache is not properly parsing your index.php file, tell Apache that you've got index.php files in your site. And here's where and how you do it..."

Last updated on Jun 4, 2016

Chronicles

Archives

Recent Articles