Suso Logo suso
Support Site
main site     webmail    

Why Can't My PHP Programs Create Files? What is Safe Mode?

PHP is not run like a CGI program is. Although you can do this. PHP runs instead as a module under the Apache webserver. This gives PHP the advantage of being able to run faster and makes things like session variables possible. But the major downside of PHP running as an Apache module is that it runs as the web server's user id instead of as your own user id. This means that when it tries to read or write a file on the filesystem, it does so as user and group apache instead of user username and group [groupname]. Since shared user servers like are shared by many other users, it is important that other users are not able to view your own files and vice versa. This is where the PHP safe_mode option comes in. Safe mode acts as a safe guard by not allowing your own scripts to read or write any file that is not owned by you. This essentially means that you can only read files and directories in your home directory and below.

Some people however need to run PHP programs that let you upload files, such as a web photo gallery. In order to get allow this kind of functionality when safe_mode is enabled, you must unfortunately change the permissions on the file or directory to be writable by the 'other' class. You can do this by running this command:

chmod o+w

The future

Since the release of Apache 2.0 in 2000, the apache team and another team of programmers have been working on an extension to Apache that would allow modules like mod_php to run as the user that owns the program instead of as the webserver. Unfortunately, the development of these entensions (called the perchild MPM and the Metux MPM) have been quite slow due to their complex nature and design. Hopefully by 2006 we will have this ability available to us and then we can do away with these problems under PHP.