-1

Firefox is not interpreting PHP code at all.

I have already tried activating PHP via terminal (I am on a mac). I have tried a total of 5 different browsers. Chrome, Brave, and Opera simply downloads the PHP file, Safari is weird about FTP and Firefox has the problem explained below. I have tried replacing all instances of ">" with >. All files have a .php extension and are in the same folder.

Viewing a simple PHP file on an FTP server, Firefox either displays a blank page with PHP code such as:

<?php
echo "Hello World!";
?>

or stops at the greater than sign (>) in code such as:

<?php
echo "<P>Hello World!</P>";
?>

In the above instance, the browser displays, in plain text:

Hello World!

"; ?> 

This is not the code I am using, obviously, but my more complex code is having the same problem - namely not working at all or stopping at the greater than sign.

Any help would be greatly appreciated. Full Disclosure: I am very much a beginner at this.

  • Do you have a web server (Apache/Nginx/etc.) installed on your machine? Web browser does not execute PHP file, it's the job of the web server. – catcon Aug 01 '19 at 02:41

1 Answers1

0

The fact is that your web server is not properly configured. What you see is a text and your browser tries to show to you as a plain HTML (or even download it as a file). Your web server "believes" that this file is a plain text and you get it as is without any modification by PHP.

You should configure your web server (usually, PHP + Apache/Nginx) to execute .php files. I also highly recommend you play with <?php phpinfo(); instead of <?php echo 'Hello World'; to understand that PHP is able to launch .php files.

More detailed answer about the server configuration can be found in the Google by the search request "Mac LAMP" or "Mac LEMP" depends on your desired web server (A = Apache, E = nginx).

user1597430
  • 1,138
  • 1
  • 7
  • 14
  • Thank you for your responses. I have activated apache via mac terminal. localhost tells me "it works!" but still no progress. I will also take your advice and use the phpinfo to check this. I used an http:// host for an old php file I made and it worked directly on the browser. Does the ftp:// address have anything to do with it? – RyanPHPConfusion Aug 01 '19 at 03:21
  • @RyanPHPConfusion, `ftp://` protocol is not for web browsing. Short answer is - try XAMPP or similar product which preconfigure web-server for you in a few clicks. Long answer - find a proper documentation for your OS with all steps from php/apache/mysql installation to apache configuration. It's hard to tell what's wrong with your server mainly because no one know what you've done and which steps skipped. – user1597430 Aug 01 '19 at 04:18