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!

5
  • 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 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. Commented May 24, 2017 at 23:57
  • 1
    Can you try adding 'AddType application/x-httpd-php .php .html' in your https.conf file in your apache Commented May 25, 2017 at 0: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? Commented May 25, 2017 at 0: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 Commented May 25, 2017 at 0:15
  • This is the Q&A that would have most likely solved this stackoverflow.com/questions/13640109/… - where "prevent browser cache" would have shown you that result in Google. Commented May 25, 2017 at 0:17

1 Answer 1

4

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

Sign up to request clarification or add additional context in comments.

3 Comments

Ah that did it! Oof. Thanks!
Yeah @FrostedCookies but then you'd have to do that each time including others visiting your site should it go live. I don't think this is a concrete solution.
Ha ha, this took me a while. Damned cache!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.