Actually, everyone here is incorrect, 755 for a file is very wrong.
This means, read/write/execute by the owner.
read/execute by the group and everyone else.
Directories should be 755 as the execute bit on a directory means that the user can list its contents, as you obviously cant execute a directory.
Execute does not make sense for webhosting scripts as the execute bit is only interpreted by the shell, not php.
In short, directories should be at the most, 755, (rwx,rx,rx), files should be 644 (rw,r,r).
Your files can be stolen in a shared hosting environment very easily if they have global read access to your files.
There are three ways the webhost can be configured with PHP
- As an apache module (all scripts run as the same user regardless)
- As a CGI binary in a jail/chroot (may run as the same user, but the files are jailed from the rest of the filesystem, so others cant access them, and you cant access theirs)
- Using SuExec or suPHP (php is run as the owner of the website)
If your host is running as a module (1), then your files must be 664 and directories 755, and are readable by everyone on the server.
If your host is running in a jail/chroot (2), then your files probably have to be 664 and directories 755, but they are protected.
If your host is using suExec or suPHP then your php files should be 640 and directories 750, otherwise others can access your scripts. You may even be able to restrict it further to 600, and 700, but apache still needs to read the plain files (not scripts), so you need to take this one step further and make sure the files are owned by you, but in the group the web-server is running as.