1

Here's the thing.. I have a file named first.php containing the following code:

<html>
    <title>trial</title>
    <head>welcome</head>
    <body>
    <br>
    <?php
    echo "hello world";
    ?>
    </body>
</html>

However when I execute it, the php code is not interpreted. The short open tag also seems to be on. I'm using wampserver. what have I missed?

7
  • 3
    <head>welcome</head> What is this supposed to do? Commented Apr 29, 2013 at 20:53
  • What directory is your file in? Commented Apr 29, 2013 at 20:53
  • its inside c:/wamp/www/ Commented Apr 29, 2013 at 21:08
  • I believe you need to move it into your c:/wamp/www/htdocs folder. Then in your browser you should be able to go to localhost/yourfile.php Commented Apr 29, 2013 at 21:14
  • 1
    @SamHuckaby That is not correct Sam. It is however a good idea to create subfolders under the www folder for your projects, eg www/project1, www.project2 etc. Do not use the www folder, it belongs to wamp Commented Apr 29, 2013 at 21:25

5 Answers 5

2

It seems your server is misconfigured. Your apache server must recognize .php files as a php application and evaluate the code.

AddHandler application/x-httpd-php .php

See if you find the line above in your http.conf file.

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

2 Comments

is it httpd.conf or http.conf?
i have two files named like that. in which one should i add it? where should i add it? should it be preceded by #?
1
  1. make sure you place the .php file(s) under a directory say "myfirst" under /wamp/www
  2. make sure the wamp server is online (shows green icon)
  3. Enable short tags click on wamp icon > PHP > PHP Settings > short open tags. Make sure it is checked.
  4. run the code in browser as localhost/myfirst/first.php

hopefully it works

Comments

0
<html>
  <head>    
    <title>trial</title>
  </head>
  <body>
    <?php echo "hello world"; ?>
  </body>
</html>

Try it with the title wrapped inside the head like it should be. The welcome was just floating around in no mans land, may have broken your code. Also, use a doctype tag - < !html> without the space is HTML5.

Update Add this to a blank php file in your localhost folder.

<?php
// Show all information, defaults to INFO_ALL
phpinfo();
?>

If you don't get a report back, it's a server config problem.

Also make sure your putting it in htdocs or whatever your "public" folder is.

2 Comments

Also, make sure your address is http://localhost/yourfolder/yourfile.php, not just opening the file from the file system.
Oops,my bad. you were right. I was just opening it from the file system. Now it worked. Ha.. Thanks a lot..
0

Make the changes suggested by @kcdwayne.

Now run the code from your browser, DONT doubleclick on your php file from explorer, it has to run through a browser.

Comments

0

The Tag must be inside the Tag

<head> 
   <title>trial</title>
</head>
<body>
 <?php echo "hello world"; ?>
</body>

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.