Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I am writing a large PHP application (with setup) for the first time and am wondering about the security precautions I should take for permissions.

setup.php uses uses fopen/fwrite to generate a config.php based on POST data that comes from setup.php. This works, but it seems that I cannot write to config.php unless I set permissions of it to 777.

Config.php will essentially contain the database credentials in PHP variables (to be include()'ed), is this a good to leave as 777?

I am wondering if that is alright or I should instruct the user to change permissions back to something such as 655 (I am not sure).

share|improve this question

2 Answers 2

up vote 2 down vote accepted

You should have the file permissions set to those that are needed to do the job in hand. This may be 777 for installation and 644 for running the application.

Every time your application runs you should check that the permissions (on critical files and paths) are what you want and then issue an error message and stop the application running if they are not.

share|improve this answer
    
I liked this answer, the thought of checking permissions on run time is something I shall most definitely add. –  John D. Sep 7 '10 at 10:41

A lot PHP applications require you to set config.php to 777 wile the product is being installed. I think this is perfectly acceptable, but the user should be warned that the file should be set back to 644 when setup is complete.

Another solution is to make the user hard-code the config.php with database settings. This does however complicate things for some new users.

share|improve this answer
    
+1 That seems to be the most common way it's done. Many PHP applications also refuse to run normally until the permissions are correctly set, going to a warning screen instead. –  John Gardeniers Sep 7 '10 at 7:38

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.