0

My problem started when I was working with the .htaccess file to a directory trying to get php to run inside of html files. I tried ALOT of combinations of AddTypes and AddHandlers. I took them out and now my php files are being downloaded by the broswer instead of running. There are a few other questions on here that I have studied up and down, but they are not exactly my problem.

I'm fairly lost now, I've tried just about every combination of AddType and AddHandler. I've since decided to use mod_rewrite and just have all my files end in .php but I can't get them to run.

This is what I'm using to test:

    <!DOCTYPE html>

    <body>
    <?php
      echo("php working");  
    ?>
    </body>

    </html> 

Am I missing something? Luckily I made all my changes at a separate directory than the root so that the site still runs, but none of the php files in that folder can be viewed in broswer. What can I do? Any help is appreciated.

EDIT: Just to make it clear, I was originally trying to be able to put php in my html files so I was messing around with handlers and addtypes. My server does have php. If I call a php script from a .html file, it runs. I just can't get a php file like the example I included above to open in brower ANYMORE, it used to open in browser. My fear is that I have messed something up by trying all the different handlers in .htaccess. I have since cleared my .htaccess file in hopes that would at least get me to square one, but it hasn't.

SECOND EDIT: I went to the root directory and made a php file and it ran just fine so its definitely something I changed in the .htaccess for the particular directory. Is there anyway I can reset that directory?

6
  • AddType application/x-httpd-php5 .php ? Commented Feb 21, 2013 at 0:12
  • 1
    are you able to run PHP are your sure you are accessing the right url by localhost ? Commented Feb 21, 2013 at 0:12
  • I have tried that so many times, both with and without AddHandler afterwards. I'm going to try one more time. Commented Feb 21, 2013 at 0:13
  • Was that working before? Could you put the content of .htaccess file here? Commented Feb 21, 2013 at 0:17
  • You should show show relevant Apache configurations and .htaccess file. Your test page does us no good. Commented Feb 21, 2013 at 0:18

2 Answers 2

1

have you made sure to install php correctly within apache?

if you are using php as a module, you need the following:

LoadModule php5_module "c:/php/php5apache2.dll"
AddType application/x-httpd-php .php

# configure the path to php.ini
PHPIniDir "C:/php"

or as a CGI binary

ScriptAlias /php/ "c:/php/"
AddType application/x-httpd-php .php

# For PHP 4
Action application/x-httpd-php "/php/php.exe"

# For PHP 5
Action application/x-httpd-php "/php/php-cgi.exe"

other things to consider, are the permissions set correctly on the php binaries, is the php.ini present and correct, have you restarted apache since installing php into apache?

lastly, php doesnt run within html files, you would need to set the following as pretty much the last thing in the apache config

AddType application/x-httpd-php .html .htm
Sign up to request clarification or add additional context in comments.

3 Comments

I'm on a shared hosting plan. I didn't install php, it was always there. I don't think I have direct access to php.ini.
i would suggest posting the htaccess file in full if possible to give an idea of what it is you could have altered.
its blank now, it was blank when I started so I recleared it. I can tell you that what has happened between has been alot of combinations of AddType application/x-httpd-php .html .htm and AddHandler x-httpd-php .html .htm
1

Do you see the line like this in your htaccess file? php_flag engine off

If yes, delete it. One more thing that may help you understand what happened The following piece of htaccess would make Php from being executed but rather downloaded as a text file

<VirtualHost *>
    ServerName sourcecode.testserver.me
    DocumentRoot /var/www/example
    AddType text/plain php
</VirtualHost>

One more thing I'm guessing that this topic was addressed once here-> htaccess downloading file instead of loading

1 Comment

htaccess for the directory is blank

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.