I am a beginner and I am trying to program a secure website to improve my skills and knowledge. I am under Linux and I am using LAMP with php. My website is similar to a social network so people will have their profiles, look at the others, upload files and so on. I have implemented SSL with a self-made certificate and I am using SSL on all pages.

I think my PHP scripts can be divided in 3 categories:

  1. Creating/deleting user's informations or anything that change data in the databases

  2. Normal navigation scripts, like scripts that build the pages dynamically. These scripts only read from the databases

  3. FTP (upload pictures, create new folders for pictures)

So far to the .php files I gave permissions 644, while to the images I gave 744. The folders have all permission 755. I have to say I haven't implemented FTP yet. All my scripts are being executed by the default user they are installed with and here come the problems. I think each of the 3 categories above should have their own user, where point 2 should be the least privileged and point 3 the most privileged because it will have to create a folder if not already present and then write data to it. My idea is: when a user signs up a folder with a unique id is created and all the user's pictures will go there once uploaded. Is it a good way to handle the pictures?

Am I doing good so far?

Now, once I have created the 3 users how can I make sure that each PHP script is executed by the right user? Who should be the members of each of the 3 users? What about MYSQL, what privileges should have its user? This is the first time I am dealing with permissions and administration so any guide or idea would be very helpful and appreciated.



Browse other questions tagged or ask your own question.