Whenever i flush cache i have to give permission to the folder. what is the permanent solution for this issue.
Magento provides a more flexible way for you to set file ownership and permissions.
Instead of setting permissions explicitly, you only need to make sure files and directories are writable for installation.
We provide different suggestions for doing this, depending on whether you access your Magento server with one user account (typical of shared hosting) or two user accounts (typical of private hosting or having your own server).
After installation, to further restrict access to files and directories, you can optionally create a file named magento_umask in your Magento root directory. By default, the umask is 002, which means that directories have 775 permissions and files have 664 permissions.
For more details, see Magento file system ownership and permissions.