What is the web server that you used? Apache? nginx?
To solve your problem on the issue of index.php files not being served as the default file (aka the DirectoryIndex).
APACHE
To fix the issue with Apache web server, you will need to tell it that “index.php” files should be treated the same as “index.html” files. A quick fix is to create a .htaccess file with the following line:
#The DirectoryIndex is index.php
DirectoryIndex index.php index.html
However, using .htaccess files should be avoided if you happen to have access to Apache configuration files. A better approach is to modify the /etc/httpd/conf/httpd.conf file and add index.php after DirectoryIndex as per below:
#Find "DirectoryIndex" add "index.php" before index.html
DirectoryIndex index.php index.html
In the config snippet above, we tell Apache that index.php is the DirectoryIndex. We also specify that index.html should be used as the DirectoryIndex if a index.php file is not present inside the current directory.
After this, restart the Apache web server in order for your changes to be recognized. Do this by typing this:
sudo systemctl restart httpd
NGINX
If you are using PHP-FPM with nginx as the web server, then you will need to make sure that your sites-available configuration file has something similar to the following:
location / {
index index.php index.html index.htm;
try_files $uri $uri/ =404;
}
You only need to pay attention to the second line, as the rest of the configuration settings may be slightly different than what you are currently using. In the configuration snippet above, we have told our nginx web server that the index is “index.php”, “index.html” or “index.htm” – in that order of preference.
After this, restart the nginx web server in order for your changes to be recognized. Do this by typing this:
sudo systemctl restart nginx