Page 1 of 1

Apache 1.3 httpd, config / PHP4

Posted: Thu Oct 03, 2002 4:00 pm
by mrrobotto
:? Win98SE
I am trying to get PHP4 to run in Apache 1.3.26 I have it where it will properly display the html page with no problem. However, when I call in the php page this is what I get
The following is the information that you submitted on your employment application.

Notice: Undefined variable: Name in c:\program files\apache group\apache\htdocs\robert\application2.php on line 16
Position applied for: Name=
Notice: Undefined variable: Firstname in c:\program files\apache group\apache\htdocs\robert\application2.php on line 18

Firstname =
Notice: Undefined variable: Lastname in c:\program files\apache group\apache\htdocs\robert\application2.php on line 19

Lastname =
Notice: Undefined variable: Middlename in c:\program files\apache group\apache\htdocs\robert\application2.php on line 20

Middlename =
Notice: Undefined variable: email in c:\program files\apache group\apache\htdocs\robert\application2.php on line 21

email =
I know that the code is working properly because it will display properly when I it run it on a server that I know is right. I have followed all the methods for installation and editing the server configuration file like so.

There are two ways to set up PHP to work with Apache 1.3.x on Windows. One is to use the CGI binary (php.exe), the other is to use the Apache module DLL. In either case you need to stop the Apache server, and edit your srm.conf or httpd.conf to configure Apache to work with PHP.
It is worth noting here that now the SAPI module has been made more stable under windows, we recommend it's use above the CGI binary, since it is more transparent and secure.
Although there can be a few variations of configuring PHP under Apache, these are simple enough to be used by the newcomer. Please consult the Apache Docs for further configuration directives.
If you unziped the PHP package to c:\php\ as described in the Manual Installation Steps section, you need to insert these lines to your Apache configuration file to set up the CGI binary:
· ScriptAlias /php/ "c:/php/"
· AddType application/x-httpd-php .php .phtml
· Action application/x-httpd-php "/php/php.exe"
Note that the second line in the list above can be found in the actual versions of httpd.conf, but it is commented out. Remember also to substitute the c:/php/ for your actual path to PHP.
Warning
By using the CGI setup, your server is open to several possible attacks. Please read our CGI security section to learn how to defend yourself from attacks.

I added the lines like it says I get no syntax errors when I run a test on the server as I stated above it displays the html properly but not the PHP. I was not sure where to insert the line Action application/x-httpd-php "/php/php.exe" so I placed it here in the configuration file near the bottom where it reads Action.

# Action lets you define media types that will execute a script whenever
# a matching file is called. This eliminates the need for repeated URL
# pathnames for oft-used CGI file processors.
# Format: Action media/type /cgi-script/location
# Format: Action handler-name /cgi-script/location
Action application/x-httpd-php "/php/php.exe"

If I put format in front of the line I get a syntax error.

When I downloaded PHP4 I downloaded the php4.2.3 Installer.exe that was suppose to install and auto configure Microsoft personal web serve. I couldn’t get it to work at all with pws so I download the Apache server and reinstalled PHP4 after the installation it stated that the code has not been written to auto configure Apache 1.3 that you have to configure it manually which is what I am trying to do but am having some problems getting Apache to run the php. Any help will be greatly appreciated. TIA

Posted: Thu Oct 03, 2002 4:53 pm
by infolock
Hey, thanks for the redo on the notes. nice and neat :D

now, let's get started. You are having some of the same problems I did. First of all, note everything I said in your other message.

I think what is going on here is 2 possible senarios...

1) you didn't install the files recommended if using windows 98se

2) you need to use the php module as SAPI ( a module inside apache ) instead of CGI ( as I had hell of a lot of problems trying to set that up LOL. using it as SAPI is a lot easier IMHO )...

To do so, there are like 3 lines it wants you to put in your http.conf file ( 1 LoadModule, and 2 AddModule statements ).

Make SURE to first stop your apache server.
Install the LoadModule lines in with the rest of the LoadModule declarations ( you'll see them, there is only about 30 of them lol .. )

Then, put your AddModule declarations in with the other AddModule Statements ( again, you will see a long list of them. )

Then, restart your server. I see that you are putting your files in the correct directory, but again, make SURE that you are only typing in the address of the location of your php file ( ie your case : http://localhost/robert/application2.php )

Posted: Thu Oct 03, 2002 5:50 pm
by mrrobotto
infolock wrote:Hey, thanks for the redo on the notes. nice and neat :D

now, let's get started. You are having some of the same problems I did. First of all, note everything I said in your other message.

I think what is going on here is 2 possible senarios...

1) you didn't install the files recommended if using windows 98se

2) you need to use the php module as SAPI ( a module inside apache ) instead of CGI ( as I had hell of a lot of problems trying to set that up LOL. using it as SAPI is a lot easier IMHO )...

To do so, there are like 3 lines it wants you to put in your http.conf file ( 1 LoadModule, and 2 AddModule statements ).

Make SURE to first stop your apache server.
Install the LoadModule lines in with the rest of the LoadModule declarations ( you'll see them, there is only about 30 of them lol .. )

Then, put your AddModule declarations in with the other AddModule Statements ( again, you will see a long list of them. )

Then, restart your server. I see that you are putting your files in the correct directory, but again, make SURE that you are only typing in the address of the location of your php file ( ie your case : http://localhost/robert/application2.php )

Posted: Thu Oct 03, 2002 5:59 pm
by mrrobotto
Sorry about the first post I was in a hurry and wasn't paying attention to detail. So I would say that it would be logical to uninstall the php that I am trying to get working and install the version you stated. Do you concur?

Posted: Thu Oct 03, 2002 6:32 pm
by infolock
I would suggest you do the following ( source :: Manual on php.net )

Download PHP/Apache... Then:


1) Extract the distribution file to a directory of your choice. c:\php\ is a good start. You probably do not want to use a path in which spaces are included (for example: c:\program files\php is not a good idea). Some web servers will crash if you do.

2) You need to ensure that the DLLs which PHP uses can be found. The precise DLLs involved depend on which web server you use and whether you want to run PHP as a CGI or as a server module. php4ts.dll is always used. If you are using a server module (e.g. ISAPI or Apache) then you will need the relevant DLL from the sapi folder. If you are using any PHP extension DLLs then you will need those as well. To make sure that the DLLs can be found, you can either copy them to the system directory (e.g. winnt/system32 or windows/system) or you can make sure that they live in the same directory as the main PHP executable or DLL your web server will use (e.g. php.exe, php4apache.dll).

3) The PHP binary, the SAPI modules, and some extensions rely on external DLLs for execution. Make sure that these DLLs in the distribution exist in a directory that is in the Windows PATH. The best bet to do it is to copy the files below into your system directory, which is typically:


c:\windows\system for Windows 9x/ME
c:\winnt\system32 for Windows NT/2000
c:\windows\system32 for Windows XP


4) The files to copy are:

php4ts.dll, if it already exists there, overwrite it
The files in your distribution's 'dlls' directory. If you have them already installed on your system, overwrite them only if something doesn't work correctly (Before overwriting them, it is a good idea to make a backup of them, or move them to another folder - just in case something goes wrong).


THIS IS THE ONE YOU NEED TO PAY ATTENTION TO:

5) Download the latest version of the Microsoft Data Access Components (MDAC) for your platform, especially if you use Microsoft Windows 9x/NT4. MDAC is available at http://www.microsoft.com/data/.

6)Copy your chosen ini file (see below) to your '%WINDOWS%' directory on Windows 9x/Me or to your '%SYSTEMROOT%' directory under Windows NT/2000/XP and rename it to php.ini. Your '%WINDOWS%' or '%SYSTEMROOT%' directory is typically:


c:\windows for Windows 9x/ME/XP
c:\winnt or c:\winnt40 for NT/2000 servers



7)There are two ini files distributed in the zip file, php.ini-dist and php.ini-optimized. We advise you to use php.ini-optimized, because we optimized the default settings in this file for performance, and security. The best is to study all the ini settings and set every element manually yourself. If you would like to achieve the best security, then this is the way for you, although PHP works fine with these default ini files.

**** Open the php.ini-recommended, and RENAME it to php.ini. Then, just follow these steps: ****

8)Edit your new php.ini file:


9)You will need to change the 'extension_dir' setting to point to your php-install-dir, or where you have placed your php_*.dll files. ex: c:\php\extensions

10)Set the 'doc_root' to point to your webservers document_root. For example: c:\apache\htdocs or c:\webroot


-------- IN APACHE'S HTTP.CONF FILE, EDIT AND ADD THE FOLLOWING ------
11)LoadModule php4_module c:/php/sapi/php4apache.dll

AddType application/x-httpd-php .php .phtml

AS STATED ABOVE, ADD THESE LINES IN THE APPROPRIATE COLUMS ( IE, LoadModule with the other LoadModules, and AddModule with the other Addmodule statements. Recommend you put them as the last declarations )

The main things you need to keep in mind are steps 5-11

Posted: Thu Oct 03, 2002 7:30 pm
by mrrobotto
Will check it out and see if I can get it to work using your suggestions. Thanks for the info.

Posted: Thu Oct 03, 2002 7:56 pm
by infolock
np man, good luck. and above all, don't give up! took me 1 week of pain to get mine up and going the first time... after that, i think i could do it with my eyes closed ;)

setting up is the hardest/easiest part...

understanding the largo of it all, heh, that's where the fun begins 8O

Posted: Fri Oct 04, 2002 4:28 am
by twigletmac
You don't need to reinstall just post the code you're trying to use and I'll show you how to avoid 'variable undefined' errors.

Mac

Posted: Fri Oct 04, 2002 2:56 pm
by mrrobotto
This is kind of simple but the reason I am doing it this way is because the class I'm in is full of people that are just begining. They are using Frontpage then editing the code to get the needed results so I figure if they see the way I'm doing it this way that it would be much easier and less confusing for them. However, it is new to me also but I am a lot more advanced then they are.

<html>
<head>
<title></title>
</head>
<body>
<h2>The following is the information that you submitted on your employment application.</h2>
</body><body bgcolor="38B0DE"></body>
</html>



<?php
//File application2.php
//echo"<br>The following is the Information that you submitted";
//echo"<br><p>Date of Application: Date=$Date";
echo"<br><p>Position applied for: Name=$Name";
//echo"<br><p>Salary Desired: Name=$name";
echo"<br><td>Firstname = $Firstname";
echo"<br><td>Lastname = $Lastname";
echo"<br><td>Middlename = $Middlename";
echo"<br><td>email = $email";

?>

Posted: Sat Oct 05, 2002 6:33 am
by twigletmac
This problem is related to this sticky:
viewtopic.php?t=511

What you need to do is change the code on the page which displays the submitted results to this:

Code: Select all

&lt;html&gt; 
&lt;head&gt; 
&lt;title&gt;&lt;/title&gt; 
&lt;/head&gt; 
&lt;body&gt; 
&lt;h2&gt;The following is the information that you submitted on your employment application.&lt;/h2&gt;

&lt;?php 
//File application2.php 
//echo '&lt;br&gt;The following is the Information that you submitted'; 
//echo '&lt;br&gt;&lt;p&gt;Date of Application: Date='.$_POST&#1111;'Date']; 
echo '&lt;br&gt;&lt;p&gt;Position applied for: Name='.$_POST&#1111;'Name']; 
//echo '&lt;br&gt;&lt;p&gt;Salary Desired: Name='.$_POST&#1111;'name']; 
echo '&lt;br&gt;&lt;td&gt;Firstname = '.$_POST&#1111;'Firstname']; 
echo '&lt;br&gt;&lt;td&gt;Lastname = '.$_POST&#1111;'Lastname']; 
echo '&lt;br&gt;&lt;td&gt;Middlename = '.$_POST&#1111;'Middlename']; 
echo '&lt;br&gt;&lt;td&gt;email = '.$_POST&#1111;'email']; 

?&gt;

&lt;/body&gt;
&lt;/html&gt;
Mac

Posted: Sat Oct 05, 2002 9:11 am
by mrrobotto
I see that you are calling it by an array I don’t have it set up as an array if I’m reading your code right. I was going to write it that way because I thought it would run a lot smoother running it like that but when I mentioned it to the instructor he told me that, that would be too confusing.

The way he is trying to show the rest of the students to do it is: he is having them use Frontpage 2002 to construct the form then going in and editing the code and trying to display by changing it around a little. I guess it would be better to show you a little piece to show what I am talking about here is a small sample.

<html>
<head>
<title>php Form Sample</title>
</head>
<body>
<hl>PHP Sample form</hl>
Please complete the following information:<br>
<form method="Post" action="php-results.php">
NAME:&nbsp; <input type="text" name="T2" size="20"></p>
<p>ADDRESS:&nbsp; <input type="text" name="T2" size="20'></P>
<P>CITY:&nbsp; <input type="text" name="T3" size="20">&nbsp; STATE:&nbsp;
<input type="text" name="T4" size="9">&nbsp; ZIP:&nbsp
<input type="text" name="T5" size="20"></p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p><input type="submit" value="Submit" name="B1"><input type="reset"
value="Reset" name="B2"></p>
</form>
</body></html>

<html>
<head>
<title>php Form Sample</title>
</head>
<body>
<h1>PHP Sample form<h1>
The following information is the data that you submitted.
<p>

NAME:
<?
echo "<font color=0000ff>" .$T1 . "</font>";
?>
<p>ADDRESS:&nbsp;<? echo "<font color=ff0000>" .$T2 . "</font>"; ?>
</p>
<p>CITY:&nbsp; <? echo "<font color=ff0000>" . $T3 . "</font>"; ?>
&nbsp; STATE:&nbsp;
<? echo "<font color=ff0000>" . $T4 . "</font>"; ?>
&nbsp;ZIP:&nbsp;
<? echo "<font color=ff0000>" . $T5 . "</font>"; ?></p>
<p>&nbsp;</p>
<p>&nbsp;</p>
</body></html>

So what he is doing is replacing to get it to display what you want it to display. However, he did tell me that I could do it any way I wanted to and he would accept it that I didn’t have to follow what the rest of them are doing because he thinks that the way he is showing them is the easiest way for them to understand it and do it.

I think doing it by an array is the easiest way but I was going along with his way because the rest of the students always look at my results and then want me to show them how to fix theirs. So don’t you think an array is the easiest way because I do. I think I am going to do it the way I think is best for me and not worry about the rest of them because the way that you are showing me is how I was going to do it in the first place. So am I reading you correctly by reading it as an array.
:)

Posted: Sat Oct 05, 2002 9:53 am
by twigletmac
By default all data from a posted form is put in the $_POST array, you don't have to do anything extra for this to happen. Using the $_POST array is best practise and makes your code easier to read and understand.

There is a setting in the PHP configuration file (php.ini) called register_globals, with this turned on you can access variables from forms just by putting in their names as variables, eg. $T1, however, register_globals is now off by default so you can't do that any more. Now you have to access the variables from the $_POST array, eg $_POST['T1']. Try adding this to the top of the example code on the page where you display the posted data:

Code: Select all

&lt;?php
/* This extracts all the variables from the $_POST array so you don't have to make any other changes to the code to use it */
extract($_POST);
?&gt;
You can then do

Code: Select all

&lt;?php echo $T1; ?&gt;
so your code won't look too different to everyone else's.

Mac

Posted: Sat Oct 05, 2002 9:55 am
by twigletmac
Oh, and read the sticky topic:
Before Post Read: Concerning Passing Variables in PHP 4.2+
it has loads of information on what all of this means.

Mac

Posted: Sat Oct 05, 2002 11:11 am
by mrrobotto
Ok, thanks for the input. Now if I can only get php to run in apache on my other project I will be ok. Will post back.