3
votes

I cannot believe it(last red box): https://www.codeigniter.com/user_guide/general/caching.html

Note: Before the cache files can be written you must set the file permissions on your application/cache folder such that it is writable.

in welcome page:

$this->output->cache(60);

CodeIgniter requires us to set permission of a folder to 777 I tested and 775 or 755 did not work. only 777 did work. It means that everybody can read the content of folder, upload php file and execute it. Why does codeigniter suggest such insecure way?


updated:

These permissions do not work:

ll
    drwxr-xr-x  2 besime besime 4096 Aug 20 17:46 cache/
ll
    drwxr-xr-x 15 besime besime 4096 Jun 14 11:11 application/
ll
    drwxr-xr-x  4 besime besime 4096 Aug  3 12:08 CodeIgniter/

until I change cache to:

drwxrwxrwx  2 besime besime 4096 Aug 20 17:46 cache/

Then I can see the file b082457291d5cfcb6fb76fda5b43f60a created in cache folder after opening the welcome page.

5
I didn't read nothing about 777 in docs. You have the correct ownership? - daniel__
@loops updated the question. what else permission should work for it? - besime

5 Answers

3
votes

If you dont want the world to be writeable, Change the owner to the user which php runs as. Unless you are running with per user permissions, the PHP thread wont have write access with the current set up

chown www:www cache

then you should be able to have 700 or 775 which would work

you can check which user is running with

echo exec('whoami');
1
votes

I have solved the issues of codeigniter cache exception error by this command

chmod -R 755 /path/to/codeigniter/writable
chown -R daemon /path/to/codeigniter/writable
0
votes

You should use the chown command to create the correct ownership of the cache folder instead of making it writable/readable to all users with chmod.

If you'd like multiple users to have access to the folder, you could use a group and add the users to it, and then giving the group the correct permissions.

For example, like this:

sudo groupadd www
sudo useradd -g <your username> www
sudo chown -R :www /var/www
sudo chmod -R g+rwX /var/www

This will give the group "www" read and write access to the /var/www folder.

So in your case, use it on the cache folder instead.

0
votes

writable folder and child folders must be owned by web server process, in my case in my Linux Centos is apache

chown -R apache /var/www/project_name/writable
0
votes

The immediate solution is to give the directory 777 permission

chmod -R 755 /var/www/project-folder-name/writable