404 error after changing permalinks wordpress

Solution:

First put a .htaccess file in your /var/www/ folder and make it writable. Second, suppose your wordpress blog is in /var/www/blog folder then go to /etc/apache2/sites-available/ and make following changes in default file

<Directory /var/www/>
    Options +ExecCGI 
            Options Indexes FollowSymLinks MultiViews
            AllowOverride All
            Order allow,deny
            allow from all
</Directory>
<Directory /var/www/blog/>
            Options Indexes FollowSymLinks MultiViews
            AllowOverride All
            Order allow,deny
            allow from all
</Directory>

Now restart apache to make sure changes have taken effect. Hope it helps.