Question

Apache 2.4 on Ubuntu 14 refuses to load index.php even though PHP loads.

My apache won’t load a index.php one one of my vhosts not even if I type in example.com/index.php. I have two and one works fine.

The second vhost is my issue.

Any help would be appreciated, idk what changed between apache and php version but I am missing something. Any help would be appreciated.

I am posting both vhosts below exact copies.

First one: <VirtualHost *:80> ServerAdmin webmaster@localhost ServerName domain1.com ServerAlias www.domain1.com DocumentRoot /var/www/domain1.com/htdocs DirectoryIndex index.php <Directory /> AllowOverride All </Directory> <Directory /var/www/domain1.com/htdocs> Options Indexes FollowSymLinks MultiViews AllowOverride all Require all granted </Directory> ErrorLog /var/log/apache2/domain1.com-error.log LogLevel error CustomLog /var/log/apache2/domain1.com-access.log combined

<IfModule security2_module> SecRuleEngine Off </IfModule>

phpMyAdmin default Apache configuration

Alias /ms /usr/share/phpmyadmin

<Directory /usr/share/phpmyadmin> Options FollowSymLinks DirectoryIndex index.php

<IfModule mod_php5.c> AddType application/x-httpd-php .php

php_flag magic_quotes_gpc Off php_flag track_vars On php_flag register_globals Off php_admin_flag allow_url_fopen Off php_value include_path . php_admin_value upload_tmp_dir /var/lib/phpmyadmin/tmp php_admin_value open_basedir /usr/share/phpmyadmin/:/etc/phpmyadmin/:/var/lib/phpmyadmin/:/usr/share/php/php-gettext/:/usr/share/javascript/ </IfModule>

</Directory>

Authorize for setup

<Directory /usr/share/phpmyadmin/setup> <IfModule mod_authn_file.c> AuthType Basic AuthName “phpMyAdmin Setup” AuthUserFile /etc/phpmyadmin/htpasswd.setup </IfModule> Require valid-user </Directory>

Disallow web access to directories that don’t need it

<Directory /usr/share/phpmyadmin/libraries> Order Deny,Allow Deny from All </Directory> <Directory /usr/share/phpmyadmin/setup/lib> Order Deny,Allow Deny from All </Directory>

</VirtualHost>

Second one:

<VirtualHost *:80> ServerAdmin webmaster@localhost ServerName domain2.com ServerAlias www.domain2.com DocumentRoot /var/www/domain2.com <IfModule dir_module> DirectoryIndex index.html DirectoryIndex index.php </IfModule> <Directory /> AllowOverride All </Directory> <Directory /var/www/domain2.com> Options Indexes FollowSymLinks MultiViews DirectoryIndex index.php AllowOverride all Require all granted </Directory> ErrorLog /var/log/apache2/domain2.com-error.log LogLevel debug CustomLog /var/log/apache2/domain2.com-access.log combined </VirtualHost>


Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

@GrowShall

The primary difference between the two VirtualHost configurations is in your second one:

<IfModule dir_module>
DirectoryIndex index.html
DirectoryIndex index.php
</IfModule>

Your locking the DirectoryIndex definition inside an IfModule wrapper, whereas in the first VH, you’ve defined the DirectoryIndex just below your DocumentRoot definition.

If the dir_module is not enabled, then in the second VirtualHost, the DirectoryIndex will never be defined.

Ideally, if your website is powered by PHP, then define index.php first and index.html second and remove the IfModule wrapper.