tags:

views:

66

answers:

5

I installed PHP recently but when I try to create code in notepad and save it, my browser cant read it (the page comes up blank). Do I have to save the file in a specific directory to make it work? Please help! Thank you

+1  A: 

You must host the PHP script with a PHP-enabled web server and accesses the page through the server (The web server executes the PHP). Are you doing that?

The web address might be something like:

http://localhost/your-script.php

if you're URL looks like

file://home/your-script.php

Then you're not using a web server.

You could also see if PHP is working by running the script via the CLI (command line):

php ./your-script.php
mmattax
A: 

You have to add a server capable of handling PHP e.g. apache this could help

Redlab
+4  A: 

Press Ctrl+U in your browser or click View->Source or right click -> View Source. If the window contains the php source code, your web server is not executing php code.

Common pitfalls:

  • Are you accessing the page via a web server? Check that the URL in the browser starts with http:// or https://. Don't double-click the file, that will load the file directly (the URL will begin with file://). Since browsers do not execute php code, that won't work.
  • Is your server configured to execute php scripts in this directory? Tell us which one (Apache, IIS, ..) you're using, and we might help with that.
  • Does the filename end with .php?
  • Does your script start with <?php? Starting with just <? is deprecated.
phihag
thanks for the help! One more question how do I know what directory local host refers to?
@user374343 http://localhost/ doesn't have to refer to a directory, but often does. You configure which directory to use at your web server's configuration (Apache: DocumentRoot)
phihag
A: 

PHP can work if installed alone, although you probably want the other way.

You should install a web server. Apache is good, and IIS is also good.

Choices:

  • Install Apache, then install PHP and in the installation tell it to configure Apache
  • Install XAMP, WAMP, or other packs containing all that's needed to run a site.
  • Install Microsoft Web Platform Installer. From it you can install IIS, PHP, and even install a site, without you having to perform any additional configuring.
Alexander
A: 

Chances are pretty good that there is an error in your code and that errors are not being displayed.

Put this at the top of your page, and my guess is that an error message will show up:

ini_set('display_errors', 1);
error_reporting(E_ALL);
Joseph