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.

dialex
  • 2,706
  • 8
  • 44
  • 74
Stephen Younger
  • 163
  • 1
  • 4
  • 14
  • Can you be more specific as to what kind of error you are getting? – Farhan Ahmad May 15 '12 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: Filelinks but this is working: test
    – Stephen Younger May 15 '12 at 12:55

7 Answers7

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.

Nicolas BRERO
  • 505
  • 5
  • 6
5

It might help somebody. Changing the tags from

<?

to

<?php

did the trick for me on my WAMP server.

Spaceploit
  • 327
  • 3
  • 12
  • Wierd I didn't see that.Thanks never tought something like this could help. – Steve Moretz Sep 29 '19 at 18:27
  • 1
    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. – Saghachi Sep 08 '20 at 06:01
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

dialex
  • 2,706
  • 8
  • 44
  • 74
Pranav Hosangadi
  • 23,755
  • 7
  • 44
  • 70
  • Paying attention to details. Nice. –  May 15 '12 at 12:28
  • Actually you do not need http://localhost:8080. Check that the wamp icon in the system tray is yellow or green – Pranav Hosangadi May 15 '12 at 12:35
  • 1
    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 – Pranav Hosangadi May 15 '12 at 12:57
  • @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? – dialex Aug 27 '12 at 15:09
  • 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 – Pranav Hosangadi Aug 28 '12 at 13:59
  • I laughed at myself for an hour because of this. Well even the best make mistakes :) – mazen el zoor Feb 21 '17 at 18:25
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.

Ray
  • 40,256
  • 21
  • 101
  • 138
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...

Pogus
  • 451
  • 4
  • 6
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.

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.

sparsh singh
  • 11
  • 1
  • 2