you need to give proper permission and Don't give 777 permission as it is not recommended
try the bellow commands
find var generated vendor pub/static pub/media app/etc -type f -exec chmod g+w {} +
find var generated vendor pub/static pub/media app/etc -type d -exec chmod g+ws {} +
sudo chown -R :<web server group> .
chmod u+x bin/magento