Modifying Linux/Unix file permissions
To solve write permission errors, you neeed to modify the permissions on the file/directory so that it can be writable by the web server process that is running Drupal. More information about why you have to do this can be found in Brief intro to Unix file permissions.
To change file/directory permissions, log in to the system, browse to the file/directory in question and change permissions. The exact method to do so depends on how the system is accessed:
From command line:
To GRANT write access:
- Browse to the parent directory using
cd [path]
- Change permissions using
chmod a+w [file-or-folder]
To REMOVE write access:
- Browse to the parent directory using
cd [path]
- Change permissions using
chmod a-w [file-or-folder]
Example:
To make Drupal's sites/default folder writeable...
cd /home/exampleuser/www.example.com/sites
chmod a+w default
And to make Drupal's sites/default folder no longer writeable...
cd /home/exampleuser/www.example.com/sites
chmod a-w default
Through an FTP client:
After connecting to the server and browsing to the parent directory, you usually need to right-click the file/directory and use some sort of "change permissions" option, depending on the exact application you're using. Some FTP software will only let you use a numeric shorthand for file permissions and in that case you should, when adding write permissions, change the permissions to '777' for folders, and '666' for files.
Using the FileZilla client:
When adding write permission:
- After logging in to the server, navigate to the the directory or file that needs its permissions changed.
- Right-click on the directory/file.
- In the resulting menu, click on "File Attributes".
- Check all of the "Write" check boxes.
To remove write permissions:
- After logging in to the server, navigate to the the directory or file that needs its permissions changed.
- Right-click on the directory/file.
- In the resulting menu, click on "File Attributes".
- Uncheck all of the "Write" checkboxes.
FTP uploads and file permissions using Transmit
There are also other ways, such us simply using the desktop GUI on a test install, if available.
In Ubuntu (7.04) via GUI
For files:
- right-click on a file and click on properties
- then go to the permissions tab and there, you can change "Access:" to "Read and write" for Owner, Group, and Others.
To remove write privileges, just change the Owner, Group, and Others permissions to "Read-only".
For folders:
- right-click on a folder and click on properties
- then go to the permissions tab and there, change folder access to "Create and delete" for Owner, Group, and Others.
To remove write privileges to a folder, just change the Owner, Group, and Others permissions to "Access files".
Explanation
Each file/directory has it's owner. If you created the file yourself, you're the owner, and you can do virtually anything to the file, including change of permissions. Drupal, in the other hand, is an automated script acting on the system as "apache", "webserver" or some different identity, which is not the same as yours. So to allow Drupal to write, you need to grant write permissions to everyone, which can't be done by Drupal automatically.
When you don't own the file
The same also works the other way: Any files created by Drupal (such as settings.php, or any uploaded and/or temporary files) are owned by the webserver process, and you may be unable to change/remove them if Drupal didn't give the permission. Sometimes it helps to manipulate the parent directory, but mostly in such a case you need to remove the files as root user, if you have access to that, you might want to use some helper PHP scripts to execute the operation through PHP, which runs under the webserver process who owns the file. To avoid security risks, don't forget to remove any such helper scripts immediately after use!