-1

I am trying to execute a simple php file called tester:

<!DOCTYPE html>

<body>

<?php 
echo '<p>Hello World</p>'

?>

</body>

However, whenever I activate the localhost, the file is downloaded onto my computer instead of executed. I do not know why this is. I have PHP version 5.6.30. I am running Apache on XAMPP as an administrator. My htaccess file has just this single line: AddType application/x-httpd-php .php.

Things that I tried and did not work:

  • I tried uninstalling and reinstalling XAMPP
  • I tried changing AddType application/x-httpd-php .php to AddType application/x-httpd-php5 .php and AddHandler application/x-httpd-php52 .php respectively
  • I tried moving the htaccess file from the root of the folder into the views, where the html is, as seen below: Before:
folder
  |----views
  |      |
  |    main.html       
.htacces  

After:

folder
  |
  |-views
       |
     main.html
     .htaccess           

How can I solve this problem?

halfer
  • 19,824
  • 17
  • 99
  • 186
  • We prefer questions without edits being added to include commentary or advice about voting (either to encourage upvotes, or complain about or question downvotes, or to insist that the question is not a duplicate). These messages do not have any effect, and moreover they are not interesting to readers who do not sign in - folks mostly just want to read questions and answers without any fluff. – halfer Sep 15 '20 at 21:37
  • You received one downvote on this question, which is hardly worth noting - if you received five that is a pattern and likely indicates that you have a low-quality question. One is hardly a pattern and could just because someone thought this was an obvious duplicate. In short, don't worry about it. My own feedback is that if you write succinct, technical questions, you will get upvotes in the end (I thought the writing here was a little bit fluffy and deferential, and I think that can attract downvotes, as some people think it is excessively ingratiating). – halfer Sep 15 '20 at 21:39

1 Answers1

-1

The .htaccess file should not be required for allowing Apache to understand PHP files if accessing the files via direct link.

Do you literally have a file called “tester”? (no extension?) XAMPP works correctly out of the box for .php files so that could be the problem. Also, please use latest versions (php7.4) if not providing backwards compatible updates, which I’m guessing you’re not.

Vali D
  • 114
  • 1
  • 3