Magento: Access forbidden! You don't have permission to access the requested object

Magento: Access forbidden! You don't have permission to access the requested object

September 12, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Magento: Access forbidden! You don't have permission to access the requested object

Solving Magento Access Forbidden Errors on Ubuntu

Installing Magento locally can be a complex process that often results in “Access forbidden” errors. This post will guide you through resolving this issue step-by-step.

Understanding the Error

The error message “Access forbidden! You don’t have permission to access /var/www/html/index.php on this server.” indicates a permissions problem with your Magento installation directory. The web server (Apache or Nginx) doesn’t have the necessary read and execute permissions for the files in the /var/www/html/ directory.

This is particularly common when installing Magento on Ubuntu, as the default user permissions are quite restrictive.

Checking Current Permissions

First, let’s verify the current file permissions:

ls -l /var/www/html/

You should see output similar to this:

drwxr-xr-x 2 www-data www-data 4096 Mar 18 03:17 app
-rwxr--r-- 1 root    root       0 Mar 18 03:17 .htaccess
-rw-r--r-- 1 root    root      51 Mar 18 03:17 index.php
drwxr-xr-x 2 www-data www-data 4096 Mar 17 22:33 lib

Notice that index.php is only readable by the owner (root), which is why Apache can’t access it.

Fixing File Permissions

To fix this, we need to change the ownership of the Magento directory from root to the web server user (www-data). Here’s how:

  1. Switch to the www-data user:
sudo su -s /bin/bash www-data
  1. Change the ownership and permissions of the Magento directory:
chown -R www-data:www-data /var/www/html/
chmod 755 /var/www/html/
chmod 644 /var/www/html/index.php
  1. Exit out of the www-data user:
exit

Refreshing Magento Cache

After changing permissions, you’ll need to refresh your cache for the changes to take effect:

php bin/magento cache:flush

This command clears all cache files in the var/cache/ and generated/code/ directories.

Restarting Apache/Nginx

Finally, restart your web server to apply the permissions changes:

For Apache:

sudo systemctl restart apache2

For Nginx:

sudo systemctl restart nginx

Conclusion

The “Access forbidden” error usually occurs due to incorrect file permissions when installing Magento. By following this guide, you should now have successfully resolved this issue on your Ubuntu machine.

Remember to always keep your Magento instance up-to-date and follow best security practices provided by Magento Company.

If you continue experiencing issues or need further help with your Magento installation, feel free to explore our comprehensive guides at Laravel Company for in-depth solutions.

Security API Errors

Our network