View Full Version : conbining html and php
wjudy
16th September 2004, 09:33 PM
Hi, I stay here for whole day, need help!!
Env: Fedora 2 full installed. php-4.3.4 with Apache 2.0
Problem: can not run a php page with html code embedded or a html page with php code embedded. Shown up a white page without error msg in Mozilla. But no problem running pure html or pure php (phpinfo page/hello world)
Fedora2 put libphp4.so in http module dir, but it's name is not mod_XXXX and there is no LoadModule item in httpd.conf. I think php is built in Fedora2. So don't care LoadModule ....
exp: ?? it doesn't work
<?php
.......
?>
<HTML>
<HEAD> ....
</HEAD>
<BODY>
<?php print "hello world!" ?>
</BODY>
</HTML>
Help me getting out here.
fjleal
17th September 2004, 12:02 AM
I'm not sure I understood your problem, but your php pages need to have the ".php" extension. This way, they're handled by the php parser. No need to mess up with any modules at all.
Finalzone
17th September 2004, 12:35 AM
I reproduced the scenario above and noted the problem when writing a php embedded in html. It may be a possible bug in the httpd.conf from Apache for Fedora so you submit that problem to the developer. Hower I have no problem running html embedded in php page. I will post a solution if I find one.
Chas.H
17th September 2004, 12:49 AM
I agree with fjleal...
I write quite a bit of php and I always put them in *.php files. Embedding php in html code is fine as long as the filename is *.php. You could actually write all html( with no php code ) in a *.php file and it would work fine as long as php is running on the server. Without the php extension, the php parser doesn't see it.
superbnerd
17th September 2004, 01:02 AM
php embeded in html will not get parsed unless you tell apahce to parse it. you need to tell apache to handle the .html extention as it were php. this is not a bug. you can tell apache to do this by editing you .htaccess files in you document root or you can edit your httpd.conf
add this to you .htaccess or httpd.conf file Addhandler php-script .php .html .htm
Note: I am assuming you know how to edit these files because you and where to find them. If you don't tell us and we will guide you through it.
Finalzone
17th September 2004, 01:08 AM
Thanks, superbnerd. I forgot about that one. :o
kosmosik
17th September 2004, 01:37 AM
.html files are meant to serve static pages that is why they got .html extension. to tell the server that this page is static* and to tell the server to not use php interpreter on static page (waste of resources) - if you want to have any .html page parsed via php interpreter you can chage Apache settings - but this will be not so clever to do so (unless you are certainly certain that *every* html page is php page and needs to be interpreted)...
___
* this is not a limitation - but it is kind of de facto standard. usualy we deal with such stuff (serving dynamic (interpreted) and static (f.e. html pages, images) content by setting up two servers on different domains - f.e. static.mydomain.tld serves only images and so on using software that is light (stripped version of Apache, or thttpd or boa) and domain.tld serving full blown (but limited to what it have to do and nothing else) Apache with php and so no, probably behind accelerator/cache...
resources aren't cheap think of them before you have problem with them...
superbnerd
17th September 2004, 01:49 AM
or what you could do is make it so every page that ends with .html is static and every page that end with .php or .htm is parsed as php. to do that just add this to you .htaccess Addhandler php-script .php .htm that way all .html pages are left to the default setting.
its best to use .htacces settings instead of changing httpd.conf becasue the changes take affect immediately without restart and your settings only affect a certain directory.
wjudy
20th September 2004, 03:59 AM
yes! Thanks! My problem is solved.
wjudy
21st September 2004, 02:57 AM
Hi: I have a new problem & not sure where caused.
env: FC2's php & httpd with their default httpd.conf & php.ini
docRoot: /var/www/html
For working in the directory : /home/wjudy/a/w/html, I create link to my working dir & from docRoot.And setting option for following link in httpd.conf. It is simple & works well. :)
1).But it seems something wrong when I insert an img with the src="../img/pic.gif". The mozilla doesn't show the pic. where is the problem comes from? from mozilla? or Server doesnot find the file pic.gif?
2) I never use .htaccess, superbnerd gave a good concept. who give me a good ref for how .
Chas.H
21st September 2004, 04:54 AM
1).But it seems something wrong when I insert an img with the src="../img/pic.gif". The mozilla doesn't show the pic. where is the problem comes from? from mozilla? or Server doesnot find the file pic.gif?
Show us the php or html code around this so we can help better.
acrors
22nd September 2004, 04:06 AM
i'm new in linux, pls tell me where is the .htaccess file. I can not find this file.
superbnerd
22nd September 2004, 04:20 AM
there may be a .htaccess file in every directory under you documentroot. you don't have to have one, and if it doesn't exist just create it. they ususally only affect the directory they're in.
acrors
22nd September 2004, 05:38 AM
My test.php file is so simple:
two plus two is <?php echo(2+2); ?>
And I've applied all the thing you talk but the php still doesn't work.
Help
Ps. I did followings:
rpm -qa php
up2date php
yum install httpd php
insert a "LoadModule php4_module modules/libphp4.so" line into "/etc/httpd/conf/httpd.conf"
and create ".htaccess" file which contains the line "Addhandler php-script .php .htm" in "/var/www/html" directory
superbnerd
22nd September 2004, 05:51 AM
and what happens when you view the page in your browser? did you start apahce? /usr/sbin/apachectl start do you get any error message? does apache andjust html work?
acrors
23rd September 2004, 05:05 AM
you are right ...
the problem is that the php files in my cd doesn't work well, so after i delete all php modules and download new ones, it's ok ...
thank you
wjudy
23rd September 2004, 11:19 PM
In my "index.html" - create 3 frames (banner,content,main)
in the banner.html:
<html> <header> <title>...</title></header>
<body> <p><img src="../img/pic.gif" alt="img gif file" >
</body> </html>
1)mozilla shows the img well from the location: file:///home/wjudy/..../html/banner.html
2)but not shows the img from http://localhost/wjudyDir/index.html.
only shows a broken icon with the alt words. :(
fjleal
23rd September 2004, 11:37 PM
Using "file://...", mozilla can reach any file on your filesystem; using "http://...", you're asking Apache (or any webserver you may have listening on TCP port 80) to get the file and give it to the browser. Your Apache server may be configured not to allow paths that start with "..", or it may be an invalid path.
BTW, your "<header>" tag should be "<head>", and either you have and extra "<p>" before the "img" tag or you're missing a "</p>" after it.
wjudy
1st October 2004, 09:16 PM
The problem was solved. It comes the link. Even I still feel confused, but server works like this way.
document root dir(droot)=/var/www. Httpd can display the index.htm page from droot/html/index.htm BY "http://localhost/". That menas httpd auto serch sub dir of document root directory. But if a link ,named "mypage" , links to /home/judy. I place the page in /home/judy/html/index.htm. And httpd can not auto search sub dir by "http://localhost/mypage/". Only " http://localhost/mypage/html/index.html " makes working well.
Today, I have a new question about InnoDB. Are there anybody making InnoDB work with Fedora2 default env MySQL 3.23.58 ? I read the manual, this version should support InnoDB. Maybe my "my.cnf" has problem?
----------------------------------------------------------
my.cnf :
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
[mysql.server]
user=mysql
basedir=/var/lib
have_innodb=yes
innodb_data_home_dir=/home/judy/innoDB/data
innodb_log_group_home_dir=/home/judy/innoDB/log
innodb_data_file_path=ibdatal:10M:autoextend
[safe_mysqld]
err-log=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
----------------------------------------------------------------------
mysql error log file shows:
041001 15:04:30 mysqld started
Cannot initialize InnoDB as 'innodb_data_file_path' is not set.
If you do not want to use transactional InnoDB tables, add a line
skip-innodb
to the [mysqld] section of init parameters in your my.cnf
or my.ini. If you want to use InnoDB tables, add to the [mysqld]
section, for example,
innodb_data_file_path = ibdata1:10M:autoextend
But to get good performance you should adjust for your hardware
the InnoDB startup options listed in section 2 at
http://www.innodb.com/ibman.html
/usr/libexec/mysqld: ready for connections
-------------------------------------------------------------
I check the innodb varibles are not being set. It seems not calling the file my.cnf.
but I check "ps", it shows "safe_mysqld --defaults-file=/etc/my.cnf" :confused:
what is mysql version in Fedora3 ?????????
vBulletin® v3.8.7, Copyright ©2000-2013, vBulletin Solutions, Inc.