User avatar
rpdom
Posts: 11971
Joined: Sun May 06, 2012 5:17 am
Location: Essex, UK

Re: PHP Fiies Won't Open, How to Fix?

Tue Dec 27, 2016 6:09 pm

php wrote:I either open the file in the Terminal or open it directly in the - /var/www/html - with the browser.
Neither of those methods will work as you are just reading the source file. It won't be executed by php.
Even if I navigate to the files using http://localhost it does the same thing. Just downloads them to the Downloads folder.
That method, however, should work, if PHP is enabled in the server.

php
Posts: 37
Joined: Mon Jul 18, 2016 1:22 am

Re: PHP Fiies Won't Open, How to Fix?

Tue Dec 27, 2016 6:16 pm

rpdom wrote:
php wrote:I either open the file in the Terminal or open it directly in the - /var/www/html - with the browser.
Neither of those methods will work as you are just reading the source file. It won't be executed by php.
How can I enable the .php files to load from these folders? It worked in the /var/www/html folder before.
rpdom wrote:
php wrote:Even if I navigate to the files using http://localhost it does the same thing. Just downloads them to the Downloads folder.
That method, however, should work, if PHP is enabled in the server.
If I do that I get a "The requested URL - /var/www/html/processorder.php - was not found on this server."

PHP is not working? How do I make sure it's working on my RPi?

mfa298
Posts: 1027
Joined: Tue Apr 22, 2014 11:18 am

Re: PHP Fiies Won't Open, How to Fix?

Wed Dec 28, 2016 12:15 am

php wrote:
rpdom wrote:
php wrote:I either open the file in the Terminal or open it directly in the - /var/www/html - with the browser.
Neither of those methods will work as you are just reading the source file. It won't be executed by php.
How can I enable the .php files to load from these folders? It worked in the /var/www/html folder before.
Unless (in your terminal) you run something like "php /var/www/html/index.php" then they won't normally be run through the php engine. You may be able to get a similar effect if you have a "#!/usr/bin/php" as the first line, but they they probably won't be usable via apache.

Loading that path in your browser won't (and never will have worked).

There is a reason that several people said use http://localhost/index.php, as that will use the network socket that goes via apache rather than talking direct to the filesystem.
php wrote:
rpdom wrote:
php wrote:Even if I navigate to the files using http://localhost it does the same thing. Just downloads them to the Downloads folder.
That method, however, should work, if PHP is enabled in the server.
If I do that I get a "The requested URL - /var/www/html/processorder.php - was not found on this server."

PHP is not working? How do I make sure it's working on my RPi?
When you use that method what's the contents of the downloaded file, make sure you're actually looking at the contents of the file you just downloaded (not the file in /var/www/html or something you downloaded yesterday.

Also when you do that what does a tail on the apache logs show. Normally you should see an entry in the access.log when you request the file via http://localhost/

php
Posts: 37
Joined: Mon Jul 18, 2016 1:22 am

Re: PHP Fiies Won't Open, How to Fix?

Wed Dec 28, 2016 1:36 am

mfa298 wrote:Also when you do that what does a tail on the apache logs show. Normally you should see an entry in the access.log when you request the file via http://localhost/
Here is the log.

Code: Select all

==> /var/log/apache2/access.log <==
::1 - - [28/Dec/2016:01:33:48 +0000] "GET /index.php HTTP/1.1" 200 22668 "-" "Mozilla/5.0 (X11; Linux armv7l; rv:45.0) Gecko/20100101 Firefox/45.0"

mfa298
Posts: 1027
Joined: Tue Apr 22, 2014 11:18 am

Re: PHP Fiies Won't Open, How to Fix?

Wed Dec 28, 2016 9:09 am

php wrote:
mfa298 wrote:Also when you do that what does a tail on the apache logs show. Normally you should see an entry in the access.log when you request the file via http://localhost/
Here is the log.

Code: Select all

==> /var/log/apache2/access.log <==
::1 - - [28/Dec/2016:01:33:48 +0000] "GET /index.php HTTP/1.1" 200 22668 "-" "Mozilla/5.0 (X11; Linux armv7l; rv:45.0) Gecko/20100101 Firefox/45.0"
That might suggest that the php side of things is working, It looks like it's generating a 22k html page. If you opened the contents of what's been downloaded you'll probably see a lot of html rather than the phpinfo command (assuming that's what's in your index.php)

Rather than a browser you can also use curl in the command line (curl http://localhost/index.php) which should show the resulting html on standard out.

This would suggest that apache isn't telling the browser it's html code so as the browser doesn't know how to deal with it you get a file to download. This is probably an issue with the mime headers, I'm not sure off hand what config you have to change for that.

php
Posts: 37
Joined: Mon Jul 18, 2016 1:22 am

Re: PHP Fiies Won't Open, How to Fix?

Wed Dec 28, 2016 5:17 pm

mfa298 wrote:Rather than a browser you can also use curl in the command line (curl http://localhost/index.php) which should show the resulting html on standard out.
Yes, it outputs a whole lot of HTML.
mfa298 wrote:This would suggest that apache isn't telling the browser it's html code so as the browser doesn't know how to deal with it you get a file to download. This is probably an issue with the mime headers, I'm not sure off hand what config you have to change for that.
I need to put a doctype header in the .php files and .html files to get them to work?

php
Posts: 37
Joined: Mon Jul 18, 2016 1:22 am

Re: PHP Fiies Won't Open, How to Fix?

Wed Dec 28, 2016 7:10 pm

Tried to use different HTML doctypes in .php files. Still didn't load.

php
Posts: 37
Joined: Mon Jul 18, 2016 1:22 am

Re: PHP Fiies Won't Open, How to Fix?

Thu Dec 29, 2016 6:25 pm

How do I check/fix the mime headers? Anywhere on this forum I should specifically ask?

User avatar
DougieLawson
Posts: 30842
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website

Re: PHP Fiies Won't Open, How to Fix?

Thu Dec 29, 2016 6:58 pm

Grab a fresh SDCard, get a copy of Raspbian installed. Then run
sudo apt-get install apache2 php5 php5-cli libapache2-mod-php5
Add /var/www/html/index.php with sudo nano

Code: Select all

<?php
phpinfo(); 
?>
restart the webserver then point your browser at http://192.168.3.14/ (or http://pi.local/)

There's got to be something you've missed or messed up on your current system, so starting from a clean install is more likely to get sensible results.
Microprocessor, Raspberry Pi & Arduino Hacker
Mainframe database troubleshooter
MQTT Evangelist
Twitter: @DougieLawson

Since 2012: 1B*5, 2B*2, B+, A+, Zero*2, 3B*3

Please post ALL technical questions on the forum. Do not send private messages.

php
Posts: 37
Joined: Mon Jul 18, 2016 1:22 am

Re: PHP Fiies Won't Open, How to Fix?

Sat Dec 31, 2016 12:06 pm

DougieLawson wrote:Grab a fresh SDCard, get a copy of Raspbian installed. Then run
sudo apt-get install apache2 php5 php5-cli libapache2-mod-php5
Add /var/www/html/index.php with sudo nano

Code: Select all

<?php
phpinfo(); 
?>
restart the webserver then point your browser at http://192.168.3.14/ (or http://pi.local/)

There's got to be something you've missed or messed up on your current system, so starting from a clean install is more likely to get sensible results.
A fresh SD Card is necessary?

User avatar
Michiel O.
Posts: 85
Joined: Mon Dec 12, 2016 12:06 pm

Re: PHP Fiies Won't Open, How to Fix?

Sat Dec 31, 2016 1:24 pm

You can also use a used SD card and erase it first.

mfa298
Posts: 1027
Joined: Tue Apr 22, 2014 11:18 am

Re: PHP Fiies Won't Open, How to Fix?

Sat Dec 31, 2016 1:54 pm

php wrote:
DougieLawson wrote:Grab a fresh SDCard, get a copy of Raspbian installed. Then run
sudo apt-get install apache2 php5 php5-cli libapache2-mod-php5
Add /var/www/html/index.php with sudo nano

Code: Select all

<?php
phpinfo(); 
?>
restart the webserver then point your browser at http://192.168.3.14/ (or http://pi.local/)

There's got to be something you've missed or messed up on your current system, so starting from a clean install is more likely to get sensible results.
A fresh SD Card is necessary?
It seems like you've changed something else in the config which means the ouptput from your php isn't being treated as html by the browser, rather than spending hours of time trying to find what bit of config you've changed from the default it's probably easier to start from scratch.

When starting from scratch you may want to keep a backup of the files you change, that way if something breaks you can (more) easily find the bit that changed to break it.

php
Posts: 37
Joined: Mon Jul 18, 2016 1:22 am

Re: PHP Fiies Won't Open, How to Fix?

Sat Dec 31, 2016 4:58 pm

mfa298 wrote:It seems like you've changed something else in the config which means the ouptput from your php isn't being treated as html by the browser, rather than spending hours of time trying to find what bit of config you've changed from the default it's probably easier to start from scratch.

When starting from scratch you may want to keep a backup of the files you change, that way if something breaks you can (more) easily find the bit that changed to break it.
Any change in the config wasn't something I did.

I'm going to try Ubuntu Mate. Raspbian seems to be too much of a PIA just for a LAMP stack. I typically don't have issues with Linux Mint or Ubuntu derivatives.

User avatar
DougieLawson
Posts: 30842
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website

Re: PHP Fiies Won't Open, How to Fix?

Sat Dec 31, 2016 6:11 pm

mfa298 wrote:
php wrote:
DougieLawson wrote:Grab a fresh SDCard, get a copy of Raspbian installed. Then run
sudo apt-get install apache2 php5 php5-cli libapache2-mod-php5
Add /var/www/html/index.php with sudo nano

Code: Select all

<?php
phpinfo(); 
?>
restart the webserver then point your browser at http://192.168.3.14/ (or http://pi.local/)

There's got to be something you've missed or messed up on your current system, so starting from a clean install is more likely to get sensible results.
A fresh SD Card is necessary?
It seems like you've changed something else in the config which means the ouptput from your php isn't being treated as html by the browser, rather than spending hours of time trying to find what bit of config you've changed from the default it's probably easier to start from scratch.

When starting from scratch you may want to keep a backup of the files you change, that way if something breaks you can (more) easily find the bit that changed to break it.
+1

This is exactly the way I was thinking.
Microprocessor, Raspberry Pi & Arduino Hacker
Mainframe database troubleshooter
MQTT Evangelist
Twitter: @DougieLawson

Since 2012: 1B*5, 2B*2, B+, A+, Zero*2, 3B*3

Please post ALL technical questions on the forum. Do not send private messages.

mfa298
Posts: 1027
Joined: Tue Apr 22, 2014 11:18 am

Re: PHP Fiies Won't Open, How to Fix?

Sun Jan 01, 2017 11:44 am

php wrote:
mfa298 wrote:It seems like you've changed something else in the config which means the ouptput from your php isn't being treated as html by the browser, rather than spending hours of time trying to find what bit of config you've changed from the default it's probably easier to start from scratch.

When starting from scratch you may want to keep a backup of the files you change, that way if something breaks you can (more) easily find the bit that changed to break it.
Any change in the config wasn't something I did.

I'm going to try Ubuntu Mate. Raspbian seems to be too much of a PIA just for a LAMP stack. I typically don't have issues with Linux Mint or Ubuntu derivatives.
I suspect very much that it is something you've done. Most people seem to setup a LAMP stack fairly easily. The Ubuntu packages are going to be very similar (potentially the only difference being branding) as the Raspbian ones as they both use Debian as their base.

php
Posts: 37
Joined: Mon Jul 18, 2016 1:22 am

Re: PHP Fiies Won't Open, How to Fix?

Sun Jan 01, 2017 7:33 pm

  1. Wiped the SD card
  2. Reformatted to FAT32
  3. Installed Ubuntu Mate for RPi2 on SD card
  4. Installed new OS, rebooted
  5. Run terminal commands @DougieLawson suggestedp
  6. Didn't say php5 was available, but php 7.0 is, installed php 7.0
  7. Checked Apache works by going to localhost
  8. Checked Apache was running using - service apache2 status - it was
  9. Put .php files into /var/www/html/ as admin
  10. Still won't load files, tries to donwload
  11. WTF?
I have not installed MySQL.

User avatar
rpdom
Posts: 11971
Joined: Sun May 06, 2012 5:17 am
Location: Essex, UK

Re: PHP Fiies Won't Open, How to Fix?

Sun Jan 01, 2017 8:03 pm

Did you install libapache2-mod-php? You need that for Apache to recognise and execute PHP files.

FWIW, I find it very simple to set up a working LAMP stack on Raspbian, Debian and Ubuntu.

User avatar
DougieLawson
Posts: 30842
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website

Re: PHP Fiies Won't Open, How to Fix?

Sun Jan 01, 2017 9:39 pm

rpdom wrote:Did you install libapache2-mod-php? You need that for Apache to recognise and execute PHP files.

FWIW, I find it very simple to set up a working LAMP stack on Raspbian, Debian and Ubuntu.
I usually use phpmyadmin (even though it's horribly insecure without some extra effort) to pull in all the dependencies.

sudo apt-get install apache2 mariadb-client phpmyadmin php5-cli
Microprocessor, Raspberry Pi & Arduino Hacker
Mainframe database troubleshooter
MQTT Evangelist
Twitter: @DougieLawson

Since 2012: 1B*5, 2B*2, B+, A+, Zero*2, 3B*3

Please post ALL technical questions on the forum. Do not send private messages.

php
Posts: 37
Joined: Mon Jul 18, 2016 1:22 am

Re: PHP Fiies Won't Open, How to Fix?

Sun Jan 01, 2017 11:48 pm

rpdom wrote:Did you install libapache2-mod-php? You need that for Apache to recognise and execute PHP files.
Installed it, still gave me a "page not found" in Firefox. Any other suggestions?

mfa298
Posts: 1027
Joined: Tue Apr 22, 2014 11:18 am

Re: PHP Fiies Won't Open, How to Fix?

Sun Jan 01, 2017 11:51 pm

php wrote:
  • Still won't load files, tries to donwload
php wrote:
rpdom wrote:Did you install libapache2-mod-php? You need that for Apache to recognise and execute PHP files.
Installed it, still gave me a "page not found" in Firefox. Any other suggestions?
"Page not found" and getting a file to download are not the same error. One indicates apache can't find the html/php file the other suggests a misconfiguration of apache.

php
Posts: 37
Joined: Mon Jul 18, 2016 1:22 am

Re: PHP Fiies Won't Open, How to Fix?

Mon Jan 02, 2017 12:02 am

mfa298 wrote:
php wrote:"Page not found" and getting a file to download are not the same error. One indicates apache can't find the html/php file the other suggests a misconfiguration of apache.
When I try to open it with Firefox it gives a File:/// path and keep giving me an "Opening processorder.php" page.

I then replaced that with localhost which gives me "Not found - The request URL ____ was not found on the server". Localhost is the correct path?

User avatar
rpdom
Posts: 11971
Joined: Sun May 06, 2012 5:17 am
Location: Essex, UK

Re: PHP Fiies Won't Open, How to Fix?

Mon Jan 02, 2017 5:27 am

Using a file:///... path for a PHP file in a browser won't work. It is getting the file directly and just displaying it, not getting it from the web server which will process it first.

Where is the file on your file system?

What URL(s) are you trying to use to access that file?

php
Posts: 37
Joined: Mon Jul 18, 2016 1:22 am

Re: PHP Fiies Won't Open, How to Fix?

Mon Jan 02, 2017 5:34 am

rpdom wrote:Using a file:///... path for a PHP file in a browser won't work. It is getting the file directly and just displaying it, not getting it from the web server which will process it first.

Where is the file on your file system?

What URL(s) are you trying to use to access that file?
That's just the way Ubuntu Mate automatically processess it.

Files are in /var/www/html, I use http://localhost/var/www/html/whatever.php.

User avatar
rpdom
Posts: 11971
Joined: Sun May 06, 2012 5:17 am
Location: Essex, UK

Re: PHP Fiies Won't Open, How to Fix?

Mon Jan 02, 2017 5:48 am

php wrote:That's just the way Ubuntu Mate automatically processess it.

Files are in /var/www/html, I use http://localhost/var/www/html/whatever.php.
If /var/www/html is the document root for your webserver, you should be trying http://localhost/whatever.php or http://127.0.0.1/whatever.php

You don't put the full local file path in the URL.

php
Posts: 37
Joined: Mon Jul 18, 2016 1:22 am

Re: PHP Fiies Won't Open, How to Fix?

Mon Jan 02, 2017 5:56 pm

rpdom wrote:
php wrote:That's just the way Ubuntu Mate automatically processess it.

Files are in /var/www/html, I use http://localhost/var/www/html/whatever.php.
If /var/www/html is the document root for your webserver, you should be trying http://localhost/whatever.php or http://127.0.0.1/whatever.php

You don't put the full local file path in the URL.
Thanks, that worked! :)

In the book I have it shows the path to the folder where the file is in the browser. Can I do this on Ubuntu? Should I just put them into - /var/www/html - and then use localhost?

Return to “Beginners”

Who is online

Users browsing this forum: No registered users and 40 guests