I am trying to set up PHP with Apache, and I can not get the installation to work properly.

When I execute php files from the root using http://localhost/phpinfo.php, they seem to work well, but when I run a php file from a html file, it gives me a download dialog for the php file. If I choose “open” the dialog box goes away, and the php file does nothing.

I have uninstalled and re-installed both Apache and PHP several times, using different installation parameters, all with the same results.

I am using the latest version of Apache 2.2, and PHP version 5.2.1, on Windows XP-SP2, set up as a local host only to be used for working on the html/php code.

Any ideas hoe to get this to work?

    If you are trying to open a php file by going to File -> Open File in your browser it won't work.

    Only using http://localhost/filename.php will work because it needs to be parsed by the server.

      Running the php file from the local host is not the problem, it ti when I try to run it from within the html file. I am new to this, so please bear with me.

      I am using an html form page, to call a php script, but instead of executing the script, it prompts me to download the file. If I download the file, I gat the entire php script file, exactly as it is.

      I have installed php manually, after Apache (see previous post) and modified the Apache configuration file as shown in several places on this website. However, Apache does not seem to recognize the php script.

      Please help

      The example from the book I am learing with is as follows:

      HTML code ------------------------

      <html>
      <head>
      <title>A simple HTML form</title>
      </head>
      <body>
      <form action="send_simpleform.php" method="POST">
      <p><strong>Name:</strong><br/>
      <input type="text" name="user"></p>
      <p><strong>Message:</strong><br/>
      <textarea name="message" rows="5" cols="40"/></textarea></p>
      <p><input type="submit" value="send"/></p>
      </form>
      </body>
      </html>

      PHP File -------------------------

      <?php
      echo "<p>Welcome <b>".$POST["user"]."</b>!</p>";
      echo "<p>Your message is:<br/><b>".$
      POST["message"]."</b></p>";
      ?>

        It may be that you are not putting the files in the right directory.

        Make sure they are being stored in either the 'htdocs' or the 'www' directories within the Apache directory.

        If this is not the problem then post again and I'll try helping a little more.

          Apache is in directory C:\Apache\, the files are loacted in C:\Apache\htdocs. This is the directory Apache created upon installation.

          When setting up I changed the default directory, and edited the php.ini file to include: doc_root = C:\apache\htdocs

          Again, the php files located in that directory work fine when run by themselves as http://localhost/php_filename.php, but do not work when called from within an html file.

            Hey! You must be using the same book as me: Sams PHP, MySQL and Apache. he, he. Anywho...I had trouble getting set up right too. I think the book misses some stuff.

            I remember someone told me enable a security setting...

            Ugh...no time...I have to go...let me think about this.

              I remember seeing something like this maybe a week ago. The quick solution that was suggested then was to rename the first file to something.php and don't use htm or html as file type.

                Forgive my ignorance with this, as I am new to working with PHP. I did rename the html file "simpleform.html" to "simpleform.php" and it does seem to work.

                Do I have to name all html files that use php script with the php extension?

                Is there a way to have the php interprete recognise a .html, or .htm file?

                The files I am working with were examples from a book. The file "simpleform.html" is the input form for the "send_simpleform.php" file.

                Thank you for your help

                  I consider that workaround and not really a solution. It works if you build a new site, but not if you add some pages with PHP code to an existing site. Unfortunatley I don't know a real solution to that problem.

                    I have tried editing the Apache httpd.conf file, and am having some strange results. if I add ".html" to the “AddType application/x-httpd-php .php .html” as shown, then it runs the html files with php calls with no problem, however, the "index.html" file will no longer run when I access it through http://localhost/ or http://localhost/index.html

                    It runs some other file another file that I think may be generated from something els – in any case, I can not find it anywhere on my computer.!!??

                    But if I do not have the “.html” section in the AddType line, the html files will not access the php files - strange?

                    Any ideas?

                      Write a Reply...