Forum Moderators: phranque

Message Too Old, No Replies

Parse php in .html files (follow up)

Bridging the gap between php4 and apache2

         

steep5

12:34 am on Nov 9, 2004 (gmt 0)

10+ Year Member



This is a folowup on an old post. Unfortunately, that post was closed right where I need this one to open.

We're running Fedora Core 2, Apache2, and PHP4. Everything was working fine, but now the time has come for me to teach Apache to parse php in .html files. It's really not that complicated, whether you use .htaccess files or direct server configuration.

At least that's what I thought.

I edited php.conf to say AddType application/x-httpd-php .php .html, but then I get blank pages -- even when I have a plain html page with no php.

I tried a dozen variations I've seen on the net. RemoveHandler .html. AddHandler, ForceType, etc.

Then I came across this post. [webmasterworld.com] On the third page, the fourth post by coopster, to be more specific. I do have access to the server, and am willing to give it a shot.

So read that post, and you'll see where I am.

ogletree

12:47 am on Nov 9, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



You are way over complicating this. All you have to do is put a line in your .htaccess file.

AddType application/x-httpd-php .html

nakulgoyal

5:06 am on Nov 9, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



thanks ogletree, I spent over 30 minutes searching for this, you won't believe I was not able to find this...!

coopster

1:05 pm on Nov 9, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld, steep5.


I edited php.conf to say AddType application/x-httpd-php .php .html

I hope you mean that you are adding that directive to your Apache

httpd.conf
file, not your
php.ini
file. This directive belongs in Apache, not php. Or in a per-directory override file (.htaccess) as mentioned.

steep5

6:37 pm on Nov 9, 2004 (gmt 0)

10+ Year Member



Putting it in the .htaccess file is a method of overriding settings in httpd.conf. I would rather edit httpd.conf because this is something I want to happen throughout the whole site, not just a few directories.

Oh, and before it happens, don't make this a post about webserver speed. Each of the pages in this site will load the same modules via php includes. I.e., it is okay for every page to be parsed. They need it.

Okay, back to ogletree's philosophy: I already tried that. I guess I didn't write that specifically in my post, so you must have missed it somewhere. Or maybe you didn't know that if the server is configured correctly, what you put in your .htaccess file overrides certain commands in your httpd.conf file.

Coop, apache 2 is compiled a bit differently. Instead of loading libphp4.so from the httpd.conf file, it is loaded from a seperate file called php.conf. This is not php.ini, but rather a snippet of code that you would normally see in httpd.conf. I get the same effect (blank html pages) whether I use the .htaccess file (not an option), edit httpd.conf (no longer even MENTIONS php), or edit php.conf.

So in short (too late for that), no, I wouldn't try to configure apache in php.ini. *wink*

coopster

6:47 pm on Nov 9, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member




no, I wouldn't try to configure apache in php.ini. *wink*

hehe, please understand that I had to ask.

Since you are using additional configuration file(s), did you remember to add them using the Include [httpd.apache.org] directive? Also, changes to the main configuration files are only recognized by Apache when it is started or restarted (I have to make sure I add that, too *wink*).

And on a side note, have you tried parsing a simple php file, using a .php extension, just to make sure php is indeed being invoked?

steep5

1:23 pm on Nov 10, 2004 (gmt 0)

10+ Year Member



I totally understand; it's easy to forget the small things.

As far as including the php.conf file, it must be compiled in somewhere. The reason I say this is because php works just fine. I've already redone a good portion of the site in php with no problems.

I do restart apache after every change. Remember how I said that there was no mention of php in httpd.conf? I found out by actually loading the module libphp4.so. It tells me that "it's already been loaded" or something to the effect. That and some googling is how I found php.conf.

So, since php works just fine when I'm not trying to parse it in .html files, I would assume that means that it is included. Also, if I remove php.conf from it's directory, it stops working.

Oh, and php.conf is the file that actually has the line AddType application/x-httpd-php .php, so naturally I tried adding .html to that as well, but to no avail.

I think all of this is being caused by the computer case. It's blue. I really wanted purple, but we ended up with blue. :P

steep5

1:24 pm on Nov 10, 2004 (gmt 0)

10+ Year Member



Oh, and btw . . . I appreciate your time. A lot.

coopster

4:15 pm on Nov 10, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Well, something is out of whack and it's beyond me. Have you tried reinstalling Apache and PHP?

steep5

4:26 pm on Nov 10, 2004 (gmt 0)

10+ Year Member



Yep, with yum.

Oh well, it was worth a try! Thanks!

jatar_k

6:20 pm on Nov 10, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



well I didn't know that it loaded like that with apache 2, interesting.

so in httpd.conf you will have something like so
Include conf.d/*.conf

It will load every conf file in there, that's great. This brings to mind one major drawback what if you have addtype lines for html in 2 places? You used to be able to spin through one file to find the conflicts, now you have to check a bunch.

The one that often happened was SSI and PHP both enabled for .html, that usually caused a nice mess.

Take a look and see if .html is double parsed.

steep5

5:44 pm on Nov 12, 2004 (gmt 0)

10+ Year Member



Check it out.

It will work just fine, as long as I do not add the following line to the beginning of my pages.

<?xml version="1.0" encoding="iso-8859-1"?>

I'm not sure where the problem comes from. I'd like to keep the line. I can remember when I started using php on this server before that the line would break php, too.

I ended up starting the files with:

<?php echo "<?xml version=\"1.0\" encoding=\"iso-8859-1\"?> "?>

So, now I'm googling for this. If you can save me the time, I'd greatly appreciate it.
Jesse

jatar_k

5:52 pm on Nov 12, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



what about

<?php echo '<?xml version="1.0" encoding="iso-8859-1"?> '?>

the single quotes should work

coopster

6:01 pm on Nov 12, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Yes, single quotes should work. That double-quoted string you have there looks incorrect though, steep5. If you are going to double-quote it
<?php echo "<?xml version=\"1.0\" encoding=\"iso-8859-1\"?".">";?>

steep5

6:03 pm on Nov 12, 2004 (gmt 0)

10+ Year Member



Finally.

It's funny because of prior conversation, but I actually DID have to manipulate the php.ini file.

I had to set short tags to off.

Everything works just fine now! Thanks for all your help!

Jesse

coopster

6:07 pm on Nov 12, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



BTW, the <? is short form (<? ?>) of PHP's open tag. The short_open_tag [php.net] configuration directive can be modified. You could turn them off if you aren't using them and then your xml declarations wouldn't have to be printed/echoed in this manner.

<added>
Ah, you are aware of the directive!
</added>