Linux - NetworkingThis forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I know a reasonable amount about Apache, but am no expert. Have a question for you. My Apache server is running on linux. All of my pages on my site are .html extensions (except for a few .php pages. Recently, I started learning php. One thing I tried was to put php code INTO html. When I did this and tried to view the site, the php code would actually show up ON the site in the browser. I have been told that:
Quote:
"PHP has to be in pages that end with the .php extension, unless your server is set up to run .html pages through the parser. Most shared hosting is set up to only process php scripting in .php, .php3 and .php4 pages."
I'll look into it, but what exactly does that mean, and what do I have to do in httpd.conf to allow php code to run in html? Thanks!
gee i didn't think u had to do anything, unlike perl.
So does php work at all, do pages with .php extentions work.
if so inline php should work as well.
but u cannot just start coding u have to encapsulate it eg
<?php echo "Hello World<P>"; ?>
Thanks for the replies, guys. I DO see pages ending in .php, and I know php is installed and working correctly. What's NOT working is when I have an html page with php code IN the html code. When that happens, the php code is displayed on the page itself. The only advice I've been able to find is what I quoted in my original post.
What I mean is this:
Quote:
show? i.e create a html file and put the above code in it. then name the file index.php and stick it in your apache root.
I have that already. The php install automatically generated it. BUT, if I create a HTML extension file and place all that php code into it, then that WON'T work. The files are identical, except one ends in .php and one ends in .html. The .php works, the .html (with php code IN it) doesn't.
If I do that, it shows all the code in the browser itself. I attached a screenshot for you to see. If I then change the filename to "test.php", though, it displays only "Hello World" as it should.
In addition, I've been reading up on this. I already added:
Code:
AddType application/x-httpd-php .php .html
to my httpd.conf file. I believe that this should allow php code INSIDE html files. I have also read that I have to add "ScriptAlias" something or other to the httpd.conf file. For instance, I had to add:
Code:
ScriptAlias /cgi-bin/ "/blah/blah/blah/cgi-bin/"
to allow for cgi files. The problem with that is that php files are not all in one directory as cgi files are! How can I add this ScriptAlias line to the httpd.conf with more than one directory accessible? Should I just make the directory my DocumentRoot directory with a trailing "/"?
You could have a html file ending in .php and if no php code was in it then the file would be ouputed as is. if the html file had <?php ?> then what ever is in those brackets will be passed to the php pasher where the code would be interupted.
Originally posted by GraemeK You could have a html file ending in .php and if no php code was in it then the file would be ouputed as is. if the html file had <?php ?> then what ever is in those brackets will be passed to the php pasher where the code would be interupted.
Huh? Sorry, I don't understand what you're saying. All I want to do is allow php code inside .html files. There seems to be some setting in Apache's httpd.conf file I have to change, but I don't know what it is. Something to do with a parser...?
Originally posted by GraemeK as far as i know any html file that contains php data has to end in .php in order to be pased to the php parser and outputed.
getting php code outputed correctly and still retaining the .html extension isnt possible i didnt think.
It is possible. Actually, I just figured it out! You have to add the above-mentioned lines to httpd.conf as well as:
Code:
AddHandler php-script .php .html
Now, you can add php code to html files and have it execute as if it were a regular php file. Cool!
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.