After installing Magento 2
sudo service apache2 restart
sudo chmod -R 777 var/
sudo chmod -R 777 pub/
sudo service apache2 restart
sudo chmod -R 777 /var/www/html/magento
sudo a2enmod rewrite
sudo service apache2 restart
Content deploy
php bin/magento setup:static-content:deploy "on root dir".
if it's not working yet
For Ubuntu edit the file /etc/apache2/apache2.conf
find
/var/www/
Change AllowOverride None
to AllowOverride All
under the following section:
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>