Please stop suggesting using 777. You make your file writable to everyone, which pretty much means that you will lose all the security for which the permission system was created. If you suggest this, consider the consequences that might have on a poorly configured web server: it would be incredibly easy to βhackβ a website by overwriting files. So, no need.
Michael: There is a good reason why your script cannot create a directory, a user working with PHP (which may be different from Apache) simply does not have sufficient rights to do this. Instead of changing permissions, I think you should solve the main problem, that is, your files have the wrong owner, or Apache or PHP are working under the wrong user.
Now it looks like you have your own server installed. You can determine which user runs PHP by running a simple script that calls the whoami program installed on most linux:
<?php echo `whoami`;
If everything is correct, you should see that the PHP username is working under. Depending on your OS, this may be www-data, nobody, http, or any other option. If your website is the only website, this is easy to change by modifying your custom Apache. If you have Debian, as I'm used to, you can edit the / etc / apache 2 / envvars file (with root privileges) and change the value for APACHE_RUN_USER. Depending on your OS, this variable may be set in another configuration file, so if you cannot find it in / etc / apache 2 / envvars, try to find the variable declaration using:
$ grep -R "APACHE_RUN_USER=" .
From the directory are all the apache-config files.
If you are not the only one on the server, you may need to create user accounts for each website and use something like Apache2-MPM-ITK to change RUN_USER depending on which website is being called. Also, make sure that the user with the PHP process is the owner of the files and directories. You can do this using chown:
% chown theuser:theuser -R /var/www/website/
If PHP works with its own user and is the owner of the files and directories to which it should be written, 700 permissions will be sufficient. I usually use 750 for most files, although as a rule I have several users in this group and they may have read permissions. Thus, you can change the permissions:
% chmod 0750 -R /var/www/website/
It should be like that. If you have any problems, let us know, and please never resort to tips that essentially tell you: if security bothers you, remove security.