1

I just installed Ubuntu 17.04 and set up my LAMP server w/ PHP7 and the PHP modules enabled for Apache2.

When I go to http://localhost/ it defaults to the index.html that is present in /var/www/html and not the index.php that is there. When I go to http://localhost/index.php the php file loads just fine and the php script executes.

In looking at other posts ( index.php not loading by default ) I saw that the preferred solution is to edit the /etc/apache2/mods-enabled/dir.conf file to move the index.php before the index.html in the DirectoryIndex entry.

<IfModule mod_dir.c>
    DirectoryIndex index.php index.html index.cgi index.pl index.xhtml index.htm
</IfModule>

So I did this and saved the file as sudo, restarted the apache service as well as tried restarting the computer and it still serves the index.html first. Any idea? Should I use the .htaccess file solution instead? Thanks!

FrostedCookies
  • 2,253
  • 2
  • 13
  • 15
  • 2
    Why do you have both an `index.html` and a `index.php` file? Can't you just delete `index.html`, which would cause localhost to load `index.php` by default? Also, you need to specify `DirectoryIndex` for **each** file that you wish to load. See https://stackoverflow.com/a/26700170/2341603. In fact, if you just specify the PHP file as a directory index, having the `.html` file won't matter, as Apache will load the PHP file anyway. – Obsidian Age May 24 '17 at 23:57
  • 1
    Can you try adding 'AddType application/x-httpd-php .php .html' in your https.conf file in your apache – manian May 25 '17 at 00:03
  • Hey @ObsidianAge thanks for the reply. I think it was a caching issue as mentioned below because now it's working fine. The DirectoryIndex line was like that out of the box and a help area mentioned which to load. The only reason I can imagine deleting it altogether being an issue is if I have multiple directories and if I have some that are plain old `index.html` in the subdirectories won't they not load by default if I eliminate it altogether? – FrostedCookies May 25 '17 at 00:13
  • you should change your title; I can see that using a "y" instead of a "t" for *"index.php not loading by default"* in your title prevented you from using that. One changed to a more descriptive title. What you have now, won't help in any search; be it Stack or Google – Funk Forty Niner May 25 '17 at 00:15
  • This is the Q&A that would have most likely solved this https://stackoverflow.com/questions/13640109/how-to-prevent-browser-cache-for-php-site - where "prevent browser cache" would have shown you that result in Google. – Funk Forty Niner May 25 '17 at 00:17

1 Answers1

4

This is likely a caching issue in your browser when you go to http://localhost/ try pressing Ctrl + F5

Jpsh
  • 1,697
  • 12
  • 17