7

My php code is not executed when I access the root directory with

http://localhost:8080/sample.html

The code I want to run is:

<?php phpinfo(); ?>

and I tried also the following:

  • Restarted all services several times including putting Wamp Server online
  • Changing the listening port in httpd.conf to 8080 and configuring Skype to accept 80 and 443 ports

Could it be that some firefox extensions are blocking php-execution?

All I get is the php code exactly like I wrote it.

2
  • Can you be more specific as to what kind of error you are getting? Commented May 15, 2012 at 12:25
  • I am not really sure what it means but I found out that my php-code is not working if it should be executed in a textarea. This will not work: <tr> <td width="30%">Filelinks</td> <td width="70%"><textarea style="width: 257px; height: 56px;" rows="2" cols="30"><?php echo "Hello World"; ?></textarea></td> </tr> but this is working: <tr> <td>test</td> <td><?php echo "Hello World"; ?><br> </td> </tr> Commented May 15, 2012 at 12:55

7 Answers 7

5

You're trying to execute PHP in an ".html" file. You have to edit the PHP handler in the apache config to make it process whatever file extension you want it to. Look for "AddType application/x-httpd-php .php" in your Apache configuration file (somewhere like 'wamp/apache/conf/httpd.conf') then just add " .html" after ".php". The line should look like this now:

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

PHP should now execute any code it finds in files with ".php" and ".html" extensions.

Edit: Or as someone suggested above, just rename your file "sample.php" and it'll be processed.

Sign up to request clarification or add additional context in comments.

2 Comments

In this case, are you sure you're using long open tags and not short ones? ("<?" instead of "<?php")
I use exactly this: <?php phpinfo(); ?>
5

It might help somebody. Changing the tags from

<?

to

<?php

did the trick for me on my WAMP server.

2 Comments

Wierd I didn't see that.Thanks never tought something like this could help.
or simply enable the setting once on the WampServer icon, choose PHP -> PHP settings -> short open tag. Wait for a second, then WampServer will automatically restart your PHP and also its web service.
4

No extensions can interfere with execution of php because it is executed at the server end, not the client end.

The php code is not executed because your file's extension is html and the WAMP server does not process .html files.

Change the extension to sample.php and then it will work

6 Comments

Paying attention to details. Nice.
Actually you do not need localhost:8080. Check that the wamp icon in the system tray is yellow or green
All I can say is: reinstall wamp with all default options. If Skype is interfering on port 80, there is a very simple fix: make Skype offline, then start the apache service in wamp, and then go online in Skype
@PranavHosangadi But is it possible to configure WAMP server to execute php code inside html files? If servers do it, why can't WAMP also do it?
Well, servers execute code inside of .php files, which are .html files but with php code in them. This differentiates them from plain html files. If you configure the server to execute html files too, then it defeats the purpose of having a separate extension for the executable files
|
1

If you're seeing literally the string

<?php phpinfo(); ?>

Open the httpd.conf file and uncomment the line

LoadModule php5_module "C:/PROGRA~1/BITNAM~1/php/php5apache2_2.dll"

Also, make sure the filename ends with .php exactly. If windows adds a .txt or other crap when you save the file to the end, apache will not know to have php process it.

4 Comments

I can't find mod_php in httpd.conf
@StephenYounger Also, in windows, my mistake it should be: LoadModule php5_module "C:/PROGRA~1/BITNAM~1/php/php5apache2_2.dll" and not mod_php
Ok what you are saying is the following line: LoadModule php5_module "c:/wamp/bin/php/php5.3.10/php5apache2_2.dll" should end with .php and not .dll ?
Yes my former html-file ends with php now.
1

I got here by google for the same symtoms.

In my case, it was just the Windows Explorer wich was hiding file extensions.

A good trap for casual users of Windows, like me.

So instead of having my file named index.php, I had actually index.php.txt.

I fixed the extension display by using this procedure : http://kb.winzip.com/kb/entry/26/

The clue was : I had no IDE icon on my php file.

I don't know if my answer really helps, 5 years after the initial question...

Comments

0

restart all services and make sure that WAMP server icon is green if it is not then restart wamp server or re-installed it.Then check for localhost.

Comments

0

Yeah, I too faced the same problem. I solved it by changing the file extensions generally, we save the file with ".php" extension but the computer may get stored in the ".php.txt" extension. So change it by clicking on "view" which is present at the top toolbar of file manager and then mark select to the checkbox "File New Extension", by doing this it will show different extensions to your stored files and accordingly change the extension.

hope, it might solved your problem.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.