PDA

View Full Version : Trouble Parsing PHP in .htm Files



dougmcc1
04-15-2004, 08:04 PM
I have found it very difficult to get PHP to run on pages using .htm file extensions.

I was told to do one of two things:

1. creating an .htaccess file and adding the following:
AddType application/x-httpd-php .htm

2. adding the .htm or .html to the following line in the httpd.conf file:
<IfModule mod_php4.c>
AddType application/x-httpd-php .php .php4 .php3 .phtml .htm

The first one doesn't work because when I upload a .htaccess file I get prompted to download a file when I go to my site (as if the .htaccess file isn't being recognized by the server).

The second one doesn't work because after I modify the httpd.conf file I have to restart Apache. There is two ways to do this and niether way works. The first way to restart Apache is through the Site Manager. The problem with that is after I modify the httpd.conf file, the site goes down so I can't access the Site Manager to restart Apache. The other way to restart Apache is with PuTTY. This doesn't work either due to the following errors:

[cook-county-il][~]$ apachectl restart
/usr/local/apache/bin/apachectl restart: httpd not running, trying to start
Cannot resolve host name %%IP%% --- exiting!
/usr/local/apache/bin/apachectl restart: httpd could not be started

-Or-

/usr/local/apache/bin/apachectl restart: httpd not running, trying to start
Syntax error on line 475 of /etc/httpd/conf/httpd.conf:
Invalid command '<Directory>', perhaps mis-spelled or defined by a module not included in the server configuration
/usr/local/apache/bin/apachectl restart: httpd could not be started

Does anyone have any suggestions? I need to be able to get this working because I plan on starting a lot more sites but I obviously can't move ahead when all my current sites are down and WestHost doesn't provide tech support for this issue.

Thanks.

wildjokerdesign
04-15-2004, 09:03 PM
What where you typeing at the command line? I think you should only have to type

restart

What is at line 475 in the httpd.conf file? The error doesn't seem to have anything to do with the modification for the php issue. Have made any other changes to it in the past.

dougmcc1
04-15-2004, 09:19 PM
One of the reps told me the command was apachectl restart.

<Directory> is on line 475

wildjokerdesign
04-15-2004, 09:34 PM
It should be this
<Directory />

It sounds like maybe something got messed up in your httpd.conf file. If that section is wrong there may be other things.

You should upload your backup of the original and try simply using restart at the command line. That well work it is an alias in the .bashrc file that well restart things and is pretty much the same as using the restart in the VPS. I think what the rep gave simply restarts apache and not the other processes that run on the server. Think really either would work.

The first error seems to be complaining about what ServerName is set to that would be just a little above where the <Directory /> should be. It should be your domain with the preceding www.

dougmcc1
04-17-2004, 10:38 PM
"It should be this
<Directory /> "

My httpd.conf file has </Directory> tags and since I never changed this tag it shouldn't be part of the problem. I could understand if there were no </Directory> tags just like you would use <br /> or <img /> for XHTML compliancy because they have no ending tags. But like I said, since there are </Directory> tags and since I didnt change this part of the file, it should be ok.

"It sounds like maybe something got messed up in your httpd.conf file"

All I did was add .htm to the end of the following line as their email instructed:
<IfModule mod_php4.c>
AddType application/x-httpd-php .php .php4 .php3 .phtml .htm

"You should upload your backup of the original and try simply using restart "

I already replaced the messed up httpd.conf file with the original. That's why I find it puzzling that I'm getting a syntax error for the <Directory> tag. The command "restart" just restarts MySQL (which was successful btw but does no good). I need to restart Apache, not MySQL.

Thanks for the help so far. Feel free to post any more ideas or suggestions as my sites are still down.

wildjokerdesign
04-18-2004, 06:40 AM
That is strange. I did look again and at line 475 + 3 lines in my file I have this
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>

That is why I mentioned it. Looking more at the file I reason that the "/" is setting this option to the root directory. That's my own logic since I am not familiar with this. :)

I did take a look at the /usr/local/apache/bin/apachectl file to try and figure out the error but really didn't get help me much. Could be you might see something there. It does list the files it is looking at.

So do you still get both the errors or is it just one of the errors now or a new one? I have been looking at the files on one of my IP based accounts. Is your account IP or namebase. Maybe that could be a diffrence and I should be looking at one of my namebase accounts to compare things. I wonder if the first error that you listed was the overall problem that then caused the other error but can't quite figure where it was looking for "host name %%IP%% " or why it would not be able to resolve that.

dougmcc1
04-18-2004, 09:41 AM
They are name-based accounts.

The only error I get now is the <Directory> syntax error. Are all of your <Directory> tags like that or just that one?

%%IP%% is a string that is suppose to get replaced with the IP address for the domain. There is also %%DOMAIN%% which is suppose to get replaced with your domain name. I dont know why these strings didn't get replaced in my httpd.conf.orig_ file but I still got the <Directory> syntax error after I went through and changed all the %% strings to what they should have been replaced with. Just so you know, I did this by opening up my regular httpd.conf file and copy/pasting the correct info for each %% string.

wildjokerdesign
04-18-2004, 10:38 AM
Yes any <Directory> opening tag has the directory it is refering to. The one we are talking about is refering to the root directory which is why it has the "/". I did check one of my namebased accounts and it is the same. Also if it refers to anouther directory like the public www it looks like this:

<Directory "/var/www/html">
The options for that directory are then listed or configured and then the </Directory> end/close tag closes it out. Not sure if that is the correct termanology but is how I have begun to think of it.

So your editing the file on your local PC and then uploading the changes or are you editing via SSH? If uploading I think you would need to do it in ASCII/text mode.

I just noticed that on my namebase account that is new I have the httpd.conf.org_(string of numbers) . That file has the %%IP%% %%DOMAIN%% so I assume that is a template used by some part of the system and not a real config file. If you used this as your back up I noticed that there are other such things within the file that also need to be replaced like %%USERNAME%% %%GROUPNAME%% may be some others I missed seeing.


I also have a back up version of it on the server and the actual httpd.conf that should be the one that is used. Think maybe the back up version was when I made some changes via my Site Manager. If you have a httpd.conf.bak on the server you could try renameing it to httpd.conf and see if that gets you anywhere.

Support should be able to get your httpd.conf file restored to a default one I think. You could try to call in and see if they could do that although on the weekends sometimes the dept heads are not in and it might be something that one of them would have to do and not a phone tech. Might be worth a try to at least get your site back up.