You would have to be sure that the user Apache (or the php instance) is running as is the owner of the said folder.
There's nothing wrong with making the folder 777 if it's not reachable from the web (e.g. you're putting it outside the webroot). For example...
CakePHP is set up in a way that you can have your Apache virtual host set up so that "/var/www/httpdocs" is your document root for your website. But CakePHP requires that you use /var/www/httpdocs/app/webroot as your webroot, so it has 2 .htaccess files which automatically push you forward to app/webroot if you're not there. So anything in app/plugins, app/vendors, app/models, app/controllers is not "seen" or visible by anyone browsing the web; however, your script(s) can use those files. So creating a folder in app with permissions of 777 would be relatively safe.