chmod 777 is evil

Well, chmod 666 is the true evil obviously, but people who use the chmod 777 trick really don’t want to bother with the different signification of x for files and folders, so they mark all files as executables. This makes ls in my terminal quite ugly, and is what motivated me to write yet another rant!

Traditionally, the web server runs with a special, underprivileged user. Now, this is totally fine — I’ll get back to that later. However, when a developer starts a project, he naturally does it with his own account. This is fine, too. When he wants to test it, he installs a web server (let’s say Apache and mod_php1), and tells the web server to use the project directory. However, the web server’s user can’t read, or at least can’t write in the directory. And here, our web developers asking for help gets recommended to “chmod 777”. Symfony even has a command for doing it, and it is a real shame.

It will work. It will also make an ugly git commit, and an ugly ls. Il will create files owned by the web server, and the developer is likely to use sudo before every command to work around the problems that will ensue, and it just gets insane.

Separation of privileges is what makes UNIX systems great. Let’s understand them and use them, please.

The obvious solution here is to run your development server under the development user. There is no need to separate when it’s for your own usage. There is a even better solution, embraced by almost every language but PHP: a way to start a web server on demand. I believe it was started by Ruby on Rails with WEBrick, and now every non-PHP framework has it. Python, by using WSGI makes it very easy. I simulated this feature for Symfony by writing symfttpd. It’s actually simpler for the developer as there is no configuration or installation at all.

Enough about developers; it’s not their job to setup daemons and manage UNIX systems. Let’s talk about the real accomplices of the Devil: system administrators.

Yes, there are system administrators that don’t use permissions properly. And they are legion. I’ve seen horrors, up to “sudo svn up” on the production server, because half the files ended being owned by root. And then “chmod 777” on millions of files.

There are many solutions there; group inheritance with the setgid bit, forcing the users to su as the web server user, or a deployment script (I’ve used the three of them for different situations).

Why is this important? Because it is often useful to separate users (one should not have access to the other’s projects in reading or writing), or to separate projects for security (one hacked project should not give access to the others).

I’ve seen it… done wrong:

  • safe_mode for PHP. It doesn’t work and will disappear in newer versions anyway.
  • Only allowing FTP access to users, who can still upload a PHP script which will have access to everything (if run through the web server). Oh, and FTP sucks. Same issue with SSH and chroot.
  • Add the users to the group the web server is running as. Allows SSH access. Nice, but the PHP script trick will, again, defeat it.

There is only one solution: use the “group” solution, but run a different PHP instance for each user. It is quite rarely used because the convenience of Apache and mod_php. But running PHP in the same process as the web server feels quite dangerous for me too. I think mod_php is an abomination.

I’ve done it for years with Lighttpd, PHP and FastCGI with a few alterations to Gentoo’s spawn-fgci init script (which is now able to handle multiple configurations without any alteration since a few months). My setup is very similar to that one.

Note that while I mention PHP, this issue is not strictly related to PHP, yet seems widespread in PHP communities.

  1. I don’t like much both of them, but more on that later []
This entry was posted in PHP, Symfony, Sysadmin. Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

3 Comments

  1. Florian
    Posted 2010-07-23 at 1441 | Permalink
    Google Chrome 6.0.435.0 Google Chrome 6.0.435.0 GNU/Linux GNU/Linux
    So true !

    Thanks for giving good alternasolutions.

  2. Posted 2010-07-23 at 1443 | Permalink
    Firefox 3.6.7 Firefox 3.6.7 GNU/Linux x64 GNU/Linux x64
    Good news: PHP 5.3.3 is out, and includes the FPM SAPI, which will make all this easier.
  3. Posted 2012-05-14 at 1359 | Permalink
    Firefox 12.0 Firefox 12.0 Windows 7 x64 Edition Windows 7 x64 Edition
    Before I started bloggin I had no idea what chmod 777 was. When I started blogging I chmoded 777 everything I found ;-) Than I gest hacked. Now I understand 777 is the real number of the beast !

Post a Comment

Your email is never published nor shared. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

*
*