Although, it’s ideal to save cache outside the document root/web root directory, often you are forced to use a directory within document root. In such a case use the following method to safeguard the folder.
Find the apache user:
ps axo user,group,comm | grep httpd
Make this user to own cache or any other folder to which PHP has to write.
chown -R apache:apache cache/
Set permissions to 700 or 755 never a 777!
chmod 700 cache/