I have /var/www/html/moodle as my website directory. When in mysite.conf the settings are as follows:

DocumentRoot /var/www/html
DirectoryIndex "index.php"

mysite.com gives an Index of/ page since there is only apache's index.html in the default location as index file. How can I make mysite.com load /var/www/html/moodle/index.php?

I tried giving in /etc/apache2/sites-available/mysite.conf

DirectoryIndex "/moodle/index.php"

With this mysite.com loads the moodle homepage, but otherindex pages inside moodle are not loading.

How to solve this?

Update (Solution)

I had to make a change in /etc/apache2/sites-available/mysite.conf as

DirectoryIndex index.php /moodle/index.php
  • 1
    Either update your DocumentRoot, to point at the moodle directory, or add a redirect at the root root to redirect everything to /moodle/
    – Zoredache
    Apr 22 '20 at 23:17
  • Tried updating DocumentRoot in the .conf file from apache2/sites-available. It didn't work. How to add redirect at the root root?
    – Praveen
    Apr 23 '20 at 3:49

The root of your site is /var/www/html and entering your URL in your browser as the root, for example http://example.com will display the root contents. http://example.com/moodle should display your index.php if it exists.

I'm an Nginx kind of guy and am not an expert on Apache but I believe this "mod_dir" is important. Make certain it has been enabled through one of the included module files. Chances are it is enabled by default.

The link for mod_dir (https://httpd.apache.org/docs/2.4/mod/mod_dir.html contains some good examples.

If you want you http root to load from moodle then move the root to /var/www/html/moodle or move the moodle files to the root.

After making changes to the Apache config you should reload the Apache service, I think it's called httpd or similar.

  • I changed DirectoryIndex index.php /moodle/index.php in /etc/apache2/sites-available/mysite.conf file. It works now, thanks.
    – Praveen
    Apr 23 '20 at 4:13
  • Glad you got it working. :) Apr 23 '20 at 9:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.