php - intricacies of adding php5_module to an apache server -
i have lot of questions regarding differences between php files on server , perl files (or other matter). i'm going try , start off simple , work up.
first clean installed osx yosemite on mac. apache2 comes pre-installed os. changed nothing in httpd.conf , files located here:
documentroot "/library/webserver/documents"
i have 3 files welcome.pl, welcome.php , welcome.txt same content.
$name="matt"; $email="foo@bar.com"; print "<!doctype html>\n"; print "<html>\n<body>\n\nwelcome " . $name . "<br>\nyour email address is: " . $email . "\n\n</body>\n</html>";
except welcome.pl replaces
$email="foo@bar.com";
with
$email="foo\@bar.com";
since perl scripts escape @ sign other difference extension.
if start apache server , open 3 browser windows , go respective pages same:
(reproduced in safari , chrome)
likewise if open 3 browser windows , go respective file system resource same:
(reproduced in safari , chrome)
however, if enable php uncommenting:
#loadmodule php5_module libexec/apache2/libphp5.so
in httpd.conf file, restart server , open 3 browser windows , go respective pages welcome.php changes to:
(reproduced in safari , chrome)
however, again if go respective file system resource same. why server parse things differently php file?
now lets change welcome.php to
<?php $name="matt"; $email="foo@bar.com"; print "<!doctype html>\n"; print "<html>\n<body>\n\nwelcome " . $name . "<br>\nyour email address is: " . $email . "\n\n</body>\n</html>"; ?>
if save file , restart server get:
(reproduced in safari , chrome)
which makes sense, if change welcome.pl to:
#!/usr/bin/perl print "content-type: text/html\n\n"; $name="matt"; $email="foo\@bar.com"; print "<!doctype html>\n"; print "<html>\n<body>\n\nwelcome " . $name . "<br>\nyour email address is: " . $email . "\n\n</body>\n</html>";
i still get:
(reproduced in safari , chrome)
however, if uncomment:
#loadmodule cgi_module libexec/apache2/mod_cgi.so
in modules section, replace
options followsymlinks multiviews
with:
options followsymlinks multiviews execcgi
in "library/webserver/documents" directory directive , add
addhandler cgi-script .cgi .pl
in "library/webserver/documents" directory directive if restart server get:
(reproduced in safari , chrome)
but if replace
addhandler cgi-script .cgi .pl addhandler cgi-script .cgi .pl php
restart server , go localhost/welcome.php
then internal server error (reproduced in safari , chrome)
but if replace
<?php $name="matt"; $email="foo@bar.com"; print "<!doctype html>\n"; print "<html>\n<body>\n\nwelcome " . $name . "<br>\nyour email address is: " . $email . "\n\n</body>\n</html>"; ?>
with
#!/usr/bin/php <?php print "content-type: text/html\n\n"; $name="matt"; $email="foo@bar.com"; print "<!doctype html>\n"; print "<html>\n<body>\n\nwelcome " . $name . "<br>\nyour email address is: " . $email . "\n\n</body>\n</html>"; ?>
then it's fine again (reproduced in safari , chrome). guess point there seems 2 types of compilation of php on server. 1 compiling text files php extensions , running php scripts , returning output client.
i know why is. difference in server? pass php file in command line input php compiler , similar results or server doing intermediate work i'm not seeing?
it seems me have installed both php cgi, , apache module (mod_php5
).
in both cases need php open tag <?php
file "work"; error different in 2 cases though, cgi giving internal server error , module displaying file contents html.
you reproduce similar dual behaviour perl files installing mod_perl
.
Comments
Post a Comment