Need help - when I click on .php file it downloads instead of opening

A

Anonymous

Guest
Since I installed apache2 and phpmyadmin, when I click on a .php file it downloads instead of opening in a web browser. It didn't do this prior to the install, so I suspect it's a config error. Can someone help me on this?

Thanks in advance,
Larry
 
You need to have PHP installed.

Did you have PHP installed before you installed Apache 2 and phpMyAdmin?
 
Remember that your question makes sense to you, but things like
It didn't do this prior to the install
makes me start thinking along different lines to what's going on, looking for what has changed to break it.

Which Linux system are you running?

How did you try to execute your .php file?

Did you try to execute the file by:
1) entering the address 'http://localhost/my.php' in your browser (changing the filename)
or
2) right clicked on the file in Files to open in your browser?

If 1, you have not stored the file in your server root, something along the lines of '/var/www/html'

If 2, your browser doesn't realise you want Apache 2 to process the file, you need to enter the address in the browser address bar using something like 'http://localhost/my.php' so that it uses the hypertext protocol (http) and asks Apache 2 to process it.
 
Running Linux Mint 19.3, a derivative of Ubuntu 18.04.
If I right click on index.php it and select open in browser, it downloads.
If I enter http://localhost/index.php I get a 404 file not found error. The same if I enter http://127.0.1.1/index.php

Extract of my /etc/apache2/site_available/foxclone.conf file follows:
Code:
	ServerName foxclone.com

	ServerAdmin webmaster@localhost
    DocumentRoot /home/larry/web/foxclone/public_html/
    <Directory /home/larry/web/foxclone/public_html>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        Require all granted
    </Directory>

After restarting Apache, results remain the same.
Code:
 sudo service apache2 status
 
apache2.service - The Apache HTTP Server
   Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled)
  Drop-In: /lib/systemd/system/apache2.service.d
           └─apache2-systemd.conf
   Active: active (running) since Sun 2020-03-22 13:56:13 EDT; 10min ago
  Process: 26859 ExecStop=/usr/sbin/apachectl stop (code=exited, status=0/SUCCESS)
  Process: 26865 ExecStart=/usr/sbin/apachectl start (code=exited, status=0/SUCCESS)
 Main PID: 26869 (apache2)
    Tasks: 7 (limit: 4915)
   CGroup: /system.slice/apache2.service
           ├─26869 /usr/sbin/apache2 -k start
           ├─26870 /usr/sbin/apache2 -k start
           ├─26871 /usr/sbin/apache2 -k start
           ├─26872 /usr/sbin/apache2 -k start
           ├─26874 /usr/sbin/apache2 -k start
           ├─26875 /usr/sbin/apache2 -k start
           └─26928 /usr/sbin/apache2 -k start

Mar 22 13:56:13 larry-dev2 systemd[1]: Starting The Apache HTTP Server...
Mar 22 13:56:13 larry-dev2 apachectl[26865]: AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1. Set the 'ServerNa>
Mar 22 13:56:13 larry-dev2 systemd[1]: Started The Apache HTTP Server.

EDIT: I changed the ServerName to localhost and it now works if I input http://localhost in the browser. It still downloads if I right click and tell it to open the php file in the browser.
 
It still downloads if I right click and tell it to open the php file in the browser.
hyper said:
Your browser doesn't realise you want Apache 2 to process the file, you need to enter the address in the browser address bar using something like 'http://localhost/my.php' so that it uses the hypertext protocol (http) and asks Apache 2 to process it.
 
Back
Top