b2evolution b2evolution

  • Sign in
  • Sign up
  • About
  • Downloads
  • Hosting
  • Docs
  • Support
  • Sign in
  • Sign up
  • Manuals Home
  • Latest Updates
 
  1. b2evolution CMS User Manual
  2. Operations Reference
  3. Security
  4. File Permissions
  5. Optimal File Permissions

Optimal File Permissions

On your system you typically want to restrict your file permissions to the maximum for best security, but not as much as b2evolution will not be able to save uploaded or cached files any more.

Optimal file permissions are basically a tradeoff between security and flexibility.

Now if you list ( ls -la ) the files from your blog directory, you will see something like this:


drwxr-xr-x  12 fplanque  staff    408  5 mar 03:44 cache
drwxr-xr-x  18 fplanque  staff    612  6 mar 00:31 conf
drwxr-xr-x   8 fplanque  staff    272  1 mar 01:48 cron
-rw-r--r--   1 fplanque  staff   1406 12 déc  2011 favicon.ico
drwxr-xr-x  22 fplanque  staff    748  6 mar 00:31 htsrv
drwxr-xr-x  45 fplanque  staff   1530  1 mar 01:48 inc
-rw-r--r--   1 fplanque  staff   2022  1 mar 01:48 index.php
drwxr-xr-x  14 fplanque  staff    476  1 mar 01:48 install
drwxr-xr-x  16 fplanque  staff    544  6 mar 00:31 locales
drwxr-xr-x   8 fplanque  staff    272  5 mar 03:44 media

if you look at the cache or the media folder for example, you will see the following info:

  • The owner of those directories is "fplanque" and he has permissions "rwx" (read write execute)
  • The group of those directories is "staff" and members of that group have permissions "r-x" (read & execute but not write – note that execute is necessary to be able to open the directory)
  • The other users of the system have permissions "r-x" (read & execute but not write)

Now, will b2evolution be able to write the files it needs into /cache or /media ?

Well, it depends under which UNIX user account b2evolution is running!

In order to determine this, look at system status page in b2evolution. You will see something like this:

Optimal File Permissions

In this case, all is fine. PHP is running as "fplanque" and "fplanque" has write permissions to the cache and media directories.

Now, this is a development machine, so it was easy, but let’s suppose we now run on a server an PHP runs as user "www-data". "www-data" has only permissions "r-x", because "www-data" would be considered and an "other" user here. However, we don’t want to give write permissions to all other users, so what we may do is first change the group of the files, for example like this:

chgrp -R www-data /path/to/blogs

Now we would have this:


drwxr-xr-x  12 fplanque  www-data    408  5 mar 03:44 cache
drwxr-xr-x  18 fplanque  www-data    612  6 mar 00:31 conf
drwxr-xr-x   8 fplanque  www-data    272  1 mar 01:48 cron
-rw-r--r--   1 fplanque  www-data   1406 12 déc  2011 favicon.ico
drwxr-xr-x  22 fplanque  www-data    748  6 mar 00:31 htsrv
drwxr-xr-x  45 fplanque  www-data   1530  1 mar 01:48 inc
-rw-r--r--   1 fplanque  www-data   2022  1 mar 01:48 index.php
drwxr-xr-x  14 fplanque  www-data    476  1 mar 01:48 install
drwxr-xr-x  16 fplanque  www-data    544  6 mar 00:31 locales
drwxr-xr-x   8 fplanque  www-data    272  5 mar 03:44 media

But that is not enough, because now "www-data" is the group but the group still only has the permissions "r-x".

So we now need to give write permission to the group on the desired directories (and their subdirectories):


chmod -R g+w /path/to/blogs/cache
chmod -R g+w /path/to/blogs/media

Now we have:


drwxrwxr-x  12 fplanque  www-data    408  5 mar 03:44 cache
drwxr-xr-x  18 fplanque  www-data    612  6 mar 00:31 conf
drwxr-xr-x   8 fplanque  www-data    272  1 mar 01:48 cron
-rw-r--r--   1 fplanque  www-data   1406 12 déc  2011 favicon.ico
drwxr-xr-x  22 fplanque  www-data    748  6 mar 00:31 htsrv
drwxr-xr-x  45 fplanque  www-data   1530  1 mar 01:48 inc
-rw-r--r--   1 fplanque  www-data   2022  1 mar 01:48 index.php
drwxr-xr-x  14 fplanque  www-data    476  1 mar 01:48 install
drwxr-xr-x  16 fplanque  www-data    544  6 mar 00:31 locales
drwxrwxr-x   8 fplanque  www-data    272  5 mar 03:44 media

"www-data" has now "rwx" access to the cache and media folders which means PHP/b2evolution will be able to write files there.

Note: we only gave "www-data" permission on these 2 directories. If we wanted to enable b2evolution to upgrade itself we would need to enable write access for all files and directories. But as long as we don’t use the Auto Upgrade feature it’s best to keep permissions tight.

Speaking of tight permissions: why did we not change the owner of the files to "www-data" so that we don’t need to change permissions for the group? Because if we did that then we would no longer we able to update our files via FTP which is not what we want either ;) (Note: we could always add "fplanque" to the "www-data" group but that would open additional security issues, so we don’t want to do that.)

Created by fplanque • Last edit by fplanque on 2020-06-09 00:25 • •

No feedback yet

Search the Manual

Content Hierarchy

  • b2evolution CMS User Manual
  • User's Guide
  • Installation / Upgrade
  • Front-office Reference
  • Back-office Reference
  • Developer Reference
  • Operations Reference
    • Security
      • File Permissions
        • UNIX Directory and File Permissions
        • Media File & evocache Permission Errors
        • Optimal File Permissions
      • Using SSL
      • Exposing PHP Errors to Visitors
      • Crumbs (nonces)
      • mod_security
      • .htaccess Files
      • Brute force password attacks
      • How to change the location of admin.php
    • Fighting Spam
    • Performance
    • Using Multiple Domains
    • Intranet setup
    • LDAP Integration
    • Troubleshooting
    • Bundled Plugins
  • Advanced Topics
  • Glossary
  • Archives
Web Site Engine

This online manual is powered by b2evolution CMS – A complete engine for your website.

About b2evolution

  • What is it?
  • Features
  • Getting Started
  • Screenshots
  • Online demo
  • Testimonials
  • Design philosophy
  • Free & open source
  • Terms of service

Downloads

  • Latest releases
  • Skins
  • Plugins
  • Language packs

About us

  • About us
  • Contact

Webhosting Guide

  • Web hosting blog
  • Best web hosting
  • Cheap web hosting
  • Green web hosting
  • Hosting with SSH
  • VPS hosting
  • Dedicated servers
  • Reseller hosting
  • Int'l: UK / France

Docs & Support

  • Online manual
  • Forums
  • Hire a pro !

Other

  • Adsense
  • Press room
  • Privacy policy

Stay in touch

  • GitHub
  • Twitter
  • Facebook
  • LinkedIn
  • News blog
  • RSS feed
  • Atom feed

Founded & Maintained by François Planque