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

Forum for you who has PHP installation issues

Moderators: egami, macek, gesf

Post Reply
larry29936
New php-forum User
New php-forum User
Posts: 18
Joined: Thu Mar 19, 2020 2:57 pm

Sat Mar 21, 2020 2:00 pm

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
If you don't know what you don't know, ask an expert.
User avatar
hyper
php-forum GURU
php-forum GURU
Posts: 1222
Joined: Mon Feb 22, 2016 5:52 pm

Sat Mar 21, 2020 5:08 pm

You need to have PHP installed.

Did you have PHP installed before you installed Apache 2 and phpMyAdmin?
larry29936
New php-forum User
New php-forum User
Posts: 18
Joined: Thu Mar 19, 2020 2:57 pm

Sun Mar 22, 2020 3:22 am

@hyper - This was an automated install of LAMP stack. Followed instructions to install and configure it at https://prognotes.net/2019/06/lamp-stac ... allation/ and https://prognotes.net/2019/06/configure ... -1-server/. Apache2, PHP 7.2, mySQL, and phpmyadmin are installed.
If you don't know what you don't know, ask an expert.
User avatar
hyper
php-forum GURU
php-forum GURU
Posts: 1222
Joined: Mon Feb 22, 2016 5:52 pm

Sun Mar 22, 2020 8:25 am

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.
larry29936
New php-forum User
New php-forum User
Posts: 18
Joined: Thu Mar 19, 2020 2:57 pm

Sun Mar 22, 2020 10:15 am

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: Select all

	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: Select all

 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.
If you don't know what you don't know, ask an expert.
User avatar
hyper
php-forum GURU
php-forum GURU
Posts: 1222
Joined: Mon Feb 22, 2016 5:52 pm

Sun Mar 22, 2020 4:28 pm

It still downloads if I right click and tell it to open the php file in the browser.
hyper wrote:
Sun Mar 22, 2020 8:25 am
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.
Post Reply