Coco
Posts: 5
Joined: Sun Sep 11, 2016 11:03 pm
Location: CA, USA

Index.php doesn't auto launch with RPI/Apache

Sat Nov 17, 2018 3:14 am

I have setup an apache webserver on my RPI. On another computer, when I enter in the IP address of the RPI, I see Index of / and the html folder. Then when I click on this folder, it launches my index.php page.

I was wondering is there a way to configure a file on the RPI such that when I type in the IP address to my RPI, it automatically launches the index.php. I have been Googling for a couple of hours, haven't found a way so far. Any advice would be greatly appreciated.
indexof.PNG
indexof.PNG (9.92 KiB) Viewed 828 times
HW/SW info:
RPI 3 Model B Rev 1.2
RPI 9 Stretch OS
PHP V 5.6.38-0

User avatar
Paul Webster
Posts: 812
Joined: Sat Jul 30, 2011 4:49 am
Location: London, UK
Contact: Twitter

Re: Index.php doesn't auto launch with RPI/Apache

Sat Nov 17, 2018 7:28 am

In the Apache configuration, what have you set DocumentRoot to?

Coco
Posts: 5
Joined: Sun Sep 11, 2016 11:03 pm
Location: CA, USA

Re: Index.php doesn't auto launch with RPI/Apache

Sat Nov 17, 2018 3:38 pm

Thanks for the response. I found the DocumentRoot setting in the /etc/apache2/sites-available 000-default.conf folder. I saw it was set to: DocumentRoot /var/www/html Then I just changed it to: DocumentRoot /var/www/html/index.php and restarted the server. This did not change anything. It still doesn't launch the index.php file when I type in the address. I thought it should/would? But maybe this is the expected behavior? I will continue experimenting. Any other ideas/suggestions would be much appreciated.

Thanks.

Peter Ryan
Posts: 39
Joined: Sat Mar 03, 2012 12:44 am
Location: UK

Re: Index.php doesn't auto launch with RPI/Apache

Sat Nov 17, 2018 3:55 pm

DocumentRoot should point to a directory and not a file, so you should probably put it back to what it was (or another directory). And then add a "DirectoryIndex" line which tells it to look first for "index.html" and if that's not found, use "index.php":

Code: Select all

DocumentRoot /var/www/html
DirectoryIndex index.html index.php
I'll ignore the fact you seem to be running an older version of PHP than is usual with Raspbian Stretch because if I mention that, it'll probably open a can of worms! :D

Coco
Posts: 5
Joined: Sun Sep 11, 2016 11:03 pm
Location: CA, USA

Re: Index.php doesn't auto launch with RPI/Apache

Sat Nov 17, 2018 9:16 pm

Thanks for additional information. I ended up doing a search for DocumentRoot and found there was another configuration file that was DocumentRoot /var/www. Then I updated that configuration file, and everything worked as expected. I am using PHP 7 now.

Thanks!

Return to “Troubleshooting”