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:

http://localhost/welcome.php

(reproduced in safari , chrome)

likewise if open 3 browser windows , go respective file system resource same:

same output 3 file system files

(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:

generic server php enabled

(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:

welcome php file php tag

(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:

welcome perl file perl interpreter comment

(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:

welcome perl file execcgi enabled , perl cgi handle

(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

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -