Setting Permissions For Windows XP
Windows XP is quite straight-forward.
Start->Run->"explorer"->(Navigate to Folder)->(Right Click On Folder)->Sharing & Security->(Check) Share this folder on the network->(Check) Allow network users to change my files.
Besides granting PHP write access, if you are on a network computer, this will allow other network users access to your files. (If anyone has found a better way email me through my P2P profile page with the answer).
Setting Permissions For Linux
(A compilation of previous replies made by Nik and I)
First the easiest and simpliest method:
To make a CHMOD command via FTP:
Download an FTP program that supports changing the CHMOD setting natively. One is WS FTP, a GUI-based tool that supports making simple shell commands like chmod. Its free to download and use, highlight the directory in the viewer and select CHMOD (Unix) from the right click menu.
To make a CHMOD command via telnet/terminal command line:
Open your favorite telnet program (Start->Run->'telnet'). Type in your website's domain name (website must support telnet for this to work). If your webserver is your home computer, or if you have a telnet or ssh program on your home computer, then it's easy to just log into your linux web server using the account username and password that you use to write/upload your PHP files. If logging in remotely you should see the welcome message, etc, and then the command line. Now think of the command line in terms of file path hierarchy. You should be now in the same folder as you would be in if you logged in by FTP. You can navigate into the folder heirarchy by typing in CD directory_name. Navigate to the folder you want to change permissions on. And then make the CHMOD command.
Each number used in the CHMOD command is added to get the permission level:
4 = (r)ead
2 = (w)rite
1 = e(x)ecute
For example, at the command line, type:
chmod 750 *.php
This sets your permissions to:
|||| +-> Group execute
|||+---> Group read
||+----> User execute
|+-----> User write
+------> User read
There are three groups for which you set permissions for.
Owner / Owner's Group / World at Large
So in short:
chmod 333: -wx-wx-wx
chmod 664: rw-rw-r--
chmod 444: r--r--r--
chmod 222: -w--w--w-
The PHP function chmod
Okay, when you run chmod() from within PHP, then the user that PHP is running under is the user that's trying to change the permissions level of the file. If the PHP user doesn't have access to open or read the file to begin with, odds are it won't be able to grant itself access to do so. If that were the case, what good would having permissions be in the first place?
The Best Method:
Go to the directory that your PHP scripts are located (cd command).
chmod 750 *.php (explained above)
This means that any users in the user-group the file belongs to can read and execute your PHP scripts, but cannot modify or delete them. This also means that no other user on the system can read, write, or execute your PHP files.
Now, the only thing left to do is to change the group of your PHP files. Typically, this is "www" or "nobody" on linux systems.
chown <your_username>:nobody *.php
This keeps you as the file owner, and sets the group to be "nobody". That allows the webserver, via it's group access, to read and execute your php files.
The last thing you need to do is allow the webserver to create new files in your directory. You need to set additional permissions on the directory, similar to how we did for your PHP scripts. Type:
This sets full (Read/Write/eXecute) permissions for both you, the user, and the group. We still need to make sure that the webserver has this access via the group. Type:
That sets the directory's group to be "nobody".
Now, PHP (via the web-server's group), can read and execute existing files in your directory and create new ones.
Alternative method For ISP-based/third-party Hosting:
If you are unable to run chown commands because it is blocked by your ISP, a chmod 777 on the destination directory may be necessary to give the PHP script proper write permissions. This of course means, read, write and execute permission for all three groups. Be warned however that chmod 777 gives read write and execute permission to anyone who wants to! This is a security hole created. Any user on the server can write to your directory. You might well be better off to paste the above instructions to a message to your ISP's technical support, politely asking them to make the command for you.