0

I have been learning some basic PHP via codeacademy.com recently, and am currently attempting to run it on my PC. I am using jEdit to write the code, and xampp/Apache as a server. The actual code looks like:

<html>
    <body>
        <?php
            echo "<p> I know how to run a PHP Program in XAMPP! <\p>";
        ?>
    </body>
</html>

Running this code by typing

http://localhost/[my directory]

into the URL bar of my browser returns Error 403 - access to the directory is forbidden on this server.

I've done some searching around, and I understand that I need an index.html or index.htm file, but I don't know what these are - my knowledge of html is extremely limited.

If someone could offer any help on how I'd bypass the forbidden access message, or if there's another way to run PHP code, I'd be extremely thankful.

7
  • 1
    Unless XAMPP is configured to run .html file endings as PHP, you really need that in index.php. Commented Jun 18, 2017 at 0:32
  • Make a search for "htdocs" directory on your computer. There have to open a index.php file. In this file you have to copy your code. After that try to type that address (without directory). But depends how your server was configured Commented Jun 18, 2017 at 0:34
  • I would also investigate running a Php7 + Apache Docker container with a separate docker container for MySQL. Commented Jun 18, 2017 at 0:37
  • @JaredFarrish Ok, how would I create an index.php and what would I do with it? Sorry, as I said I'm very new at this Commented Jun 18, 2017 at 0:37
  • Right click in the htdocs folder, New > Text Document, rename it index.php and copy/paste/save. Commented Jun 18, 2017 at 0:39

1 Answer 1

1

Name the file with your code in it: "index.php". Make sure this file is in your "xampp/htdocs/" directory.

Additionally you might want to put this file within its own folder in that directory for the sake of keeping all of your files specific to one project together.

You can then access index.php with "http://localhost:port#/folder_name/"

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

3 Comments

Ok, I'll try. If I've understood correctly though, does this mean I can only have one PHP file at any time, because it has to be called index.php?
Nope, you may have as many php files as you need. The purpose of 'index.php' is so the server knows what page to serve on default. For example, when you visit a website, the first page that loads typically starts with "index" or "default" followed by whatever file extension. This is used so the server knows what page to show when the user first enters the website.
... although it is common to have something called a Front Controller, where everything passes through it. Keep that in your back pocket. For now, just remember .php in a web directory will let that file be run as Php. @kyle

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.