My First Try - Can't get PHP to execute

Problems with the Windows version of XAMPP, questions, comments, and anything related.

My First Try - Can't get PHP to execute

Postby jnc » 04. January 2008 01:59

1) I successfully installed xampp using the installer
2) I added passwords to MySQL and XAMPP Dir -- not sure if I need to change the ini file
3) I have both Apache and MySQL Running in Control Panel
4) I get the Welcome page when I click on Admin
5) I saved the following code as test.pdf file in htdocs
<html>
<body>
My first try at PHP
<?php
print "hello, world";
phpinfo();
?>
</body>
</html>
6) I tried executing the code via IE7 as follows:
http://localhost/test.php
7) I change the name of the file to test.html and it displays "My first try at PHP
8) not sure what needs to be done to get it to work--any help would be appreciated--Thanks
carrillo
jnc
 
Posts: 5
Joined: 04. January 2008 01:07
Location: Virginia

Postby Izzy » 04. January 2008 02:13

5) I saved the following code as test.pdf file in htdocs

Try changing the name to test.php then call it from your browser:
http://localhost/test.php

Any file that contains php code should be named with a php extension for the server to recognize the php code.
Izzy
 
Posts: 3344
Joined: 25. April 2006 17:06

Postby jnc » 04. January 2008 02:34

Thanks! I wasn't able to execute the code with the php extension--so I'm not sure what else to try. The status in the control panel says the PHP is activated.
carrillo
jnc
 
Posts: 5
Joined: 04. January 2008 01:07
Location: Virginia

Postby Izzy » 04. January 2008 02:40

Try by removing the html code and just leave the php code and continue to name it test.php


BTW clear your browser's cache from time to time when working at localhost level - when developing it can be your worst enemy.
Izzy
 
Posts: 3344
Joined: 25. April 2006 17:06

Postby jnc » 04. January 2008 02:53

Still won't work. I save the file as test.php in the htdocs directory, but it looks like it is saved as a txt file--is this correct? I'm using Notepad.
carrillo
jnc
 
Posts: 5
Joined: 04. January 2008 01:07
Location: Virginia

Postby Izzy » 04. January 2008 02:59

Rename the file to test.php

Notepad - hmm

What happens when you drag the php file into notepad and then just click on Save from the File menu.

You may have to associate .php files with Notepad so they will be recognized as php files and not text files.

Right click on the php file and select Open with... or simply double click on the file and tick the box to always open this with Notepad - this associating with Notepad will not affect the server parsing the php content.
Izzy
 
Posts: 3344
Joined: 25. April 2006 17:06

Postby jnc » 04. January 2008 03:18

I wasn't able to rename it. I've been using Notepad for building my markup. Am I supposed to build my php files at some place other than Notepad (since Notepad doesn't seem to recognize the php extension)?
carrillo
jnc
 
Posts: 5
Joined: 04. January 2008 01:07
Location: Virginia

Postby Izzy » 04. January 2008 03:59

This link has an alternative method of opening a file using the start menu on the Task Bar then browse to the file in the Run.. box then Select the program (Notepad) from a list:
http://community.apachefriends.org/f/viewtopi ... 976#112976

Also you have to select to always use this program to open php files.

Same as right clicking on the php file and selecting to open it by using Notepad and follow the prompt windows.

If you are on Vista you may have to right click on the file and select to open it as an administrator.

I have never had any issues by simply dragging a file of unknown content into my text editor then just clicking on Save from the File menu to have it saved using it's original extension.

This is very much basic Windows file manipulation techniques and should be in the Windows Help files.

Until you master this technique you will have more problems down the track trying to edit non standard files in XAMPP like the conf and ini files etc.
Izzy
 
Posts: 3344
Joined: 25. April 2006 17:06

Postby jnc » 04. January 2008 04:21

Thank you! I was able to get it to work after renaming the file as mytest.php--it must have something to do with cache as you mentioned earlier.

My next task is to try and execute the php in my html file. I'm going to try and save my html files in htdocs...
carrillo
jnc
 
Posts: 5
Joined: 04. January 2008 01:07
Location: Virginia

Postby Izzy » 04. January 2008 04:23

Remember that if you include PHP code inside HTML code then the file must have a php extension not a html extension.
Good luck.
Izzy
 
Posts: 3344
Joined: 25. April 2006 17:06

Postby KallistaAEnvarou » 04. January 2008 11:23

If you want to use the .html extension, you can write, in your .htaccess folder

Code: Select all
RewriteEngine On
RewriteRule (.*?).html $1.php


Alternatively, according to the Google search I did, you can write in there:
Code: Select all
AddType application/x-httpd-php .html
AddHandler x-httpd-php .html


to use PHP direction in .html files.

If you have problems with the .html files not showing PHP, remember to view the source first (with View: Source).
KallistaAEnvarou
 
Posts: 126
Joined: 02. December 2007 17:33
Location: Cold Cold California


Return to XAMPP for Windows

Who is online

Users browsing this forum: No registered users and 51 guests