21

All the tutorials tell me to edit the: /etc/apache2/sites-available/default but this file doesn't exist for me. Within this file I would have to edit the:

<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
#AllowOverride All
#AllowOverride AuthConfig FileInfo Indexes Limit Options=All, MultiViews        
Order allow,deny
allow from all </Directory>

What should the file look like and should I create it myself?

Aslo I do have a 000-default.conf file but the above 'code' isn't in there either.

69

For apache version 2.4 and later, you have to go to

/etc/apache2/apache2.conf

You have to edit that file (you should have root permission). Change directory text like this;

<Directory /var/www/>
    Options Indexes FollowSymLinks
    AllowOverride All
    Require all granted
</Directory>

Now restart apache.

service apache2 restart

Hope it works.

4
  • Can you please explain what this does? How does this tie in with the .htaccess? My .htaccess in not getting read at all. – chx101 Apr 16 '17 at 10:04
  • 3
    The important line here is AllowOverride All, this means all settings can be set (overridden) in .htaccess files. See docs: httpd.apache.org/docs/2.4/mod/core.html#allowoverride – jacwah Nov 27 '18 at 15:59
  • If it is still not working try sudo a2enmod rewrite and then sudo service apache2 restart, this worked for me. – Omar Abbas Aug 11 '20 at 6:02
  • This is bad advice for an accepted and highly voted answer. You are changing the main config file, so each time you upgrade your system you have to manually fix the diff. It's better to override the config elsewhere. Also, as of Apache 2.4, the DocumentRoot is /var/www/html not /var/www. – Dan Feb 5 at 15:07
25

As of Ubuntu 14.04 (and Apache 2.4), the default DocumentRoot was changed from /var/www to /var/www/html.

Firstly enable a2enmod and restart Apache.

sudo a2enmod rewrite 

Then edit the 000-default.conf file

sudo nano /etc/apache2/sites-enabled/000-default.conf

and add these lines at the end

<Directory /var/www/html>
    AllowOverride All
</Directory>

Finally, restart Apache for the configuration to take effect.

sudo service apache2 restart
3
  • 2
    This solution works for me because, I need to enable mod_rewrite first. Thanks a lot. – kishor10d Sep 29 '17 at 18:16
  • 1
    This really worked for apache 2.4. Saved my day. Even after editing maing apache2.conf .htaccess didn't work but doing this way it worked. – Faisal Sarfraz Sep 7 '18 at 7:51
  • 1
    This worked for me, instead, using Ubuntu 20.04 – Precious Tom Apr 27 '20 at 9:28
9

If you don't want to repeat the same configurtion at each upgrade / update

The best way is :

Edit or create a config file

/etc/apache2/conf-available/httpd.conf

Add

<Directory /var/www/> Options Indexes FollowSymLinks AllowOverride All Require all granted </Directory>

Enable the config file

sudo a2enconf httpd

Restart or reload Apache

sudo service apache2 restart

or

sudo service apache2 reload

It's done!

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