Although it might work temporarily in development, you should not use 777 permissions. Magento will write new files with a different set of permissions next time it runs.
We recommend 770/660 permissions with ownership split between a local user and the web server user.
Best Answer
You should use below code: