Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PDO CHMOD 0777 #27

Closed
saiful opened this issue Jun 26, 2013 · 17 comments
Closed

PDO CHMOD 0777 #27

saiful opened this issue Jun 26, 2013 · 17 comments
Assignees

Comments

@saiful
Copy link
Contributor

saiful commented Jun 26, 2013

Hallo
I have a issued about pdo cache.

I created a modul for cron job, in cron job need to create a folder
cache/f011sdfasddsd8efed7as420323c793/ exampled. In these folder will be consist two files they are :
pdo.caching and config.41065cf4fd8asdf 7d52bedfda24a32adf75b1fe0.cache.ini

And I am considering for chmod it 0777 or Writable permission, I am afraid if some body can download these file via browser. I have test and it can be downloaded.

Other modul I set automatically, other module created cache APC, so I look cron job module and others moduls have created different cache, they are still in one application.

How to set chmod not to 0777 but still created pdo cache.

Thanks

@khoaofgod
Copy link
Member

hi saiful,

Normally, when php run under CGI, FCGI or suPHP , they don't need CHMOD 0777 because PHP have permission on owner account files & folder.

If PHP is running as MOD of Apache, then you have to chmod 0777.

The chmod 0777 for cache folder only required for: auto, pdo, and files:

  • Auto: have to detect the best cache for server, and write the config to .ini
  • PDO: require writable permission because cache store files in 1 single FILE.
  • FIles: require wrtable permission because cache store files and folder in multiple directories.

When you set $storage = "memcache" or some memory cache, you don't have to chmod 0777 for cache folder under "PHP5 MOD".

The PDO can be download so easy. To make more security, you can try 1 of these way:

  1. Put .htaccess in cache folder or your class folder. Set DENY FROM ALL <-- so no access from outside to your php files and cache files over httpd request.
  2. Set phpFastCache::$path = "/PATH/OUT_OF_HTML_PUBLIC_FOLDER/CACHE";
    Example: /home/yourusername/public_html/
    You can set $path = "/home/yourusername/cache/";

I will add .htaccess automatic on next revision for phpfastcache, your question is a good suggestion for me.

@saiful
Copy link
Contributor Author

saiful commented Jun 26, 2013

Thank you...

In this case, I must create and set CHMOD these folder manually, not by phpFastCache, I think it will be better if these folder created automatically according phpFastCache parameter if exists if not auto create, so cronjob will be run automatically without as us to create these folder.

I set it globally for module frontend/backend and cronjob module

phpFastCache::$storage = "auto";
phpFastCache::$autosize = 50;
phpFastCache::$path = WEB_ROOT.CACHE;
phpFastCache::$securityKey = md5("cache.storage.34342svasdfassdfaadfasd8bH");
phpFastCache::$server = array(
                       array("localhost",11211,30),
                       array("localhost",11211,70)
                   ); 

Thank you very much, I am waiting for next version..

@khoaofgod
Copy link
Member

That because you are running PHP as module under Apache.
90% Web Hosting for security, they are running PHP as suPHP, and phpFastCache will automatic create folder.

However, PHP can't do it automatic as Apache Module because of security problem. So, you can switch to suPHP and your folder will be create automatic without any problem. The function "auto create if not exist" is embedded already from the beginning. If you can't switch from Mod-PHP to other CGI / suPHP, then you can set the $path = "/tmp/" ; I believe MOD-php have full permission on /tmp folder , and it will automatic.

include("php_fast_cache.php");
phpFastCache::$path = ini_get('upload_tmp_dir');

As your suggestion, I will make next version use /tmp folder automatic for Mod-PHP , so that user don't need create and chmod 0777 themself. Also, will add .htaccess DENY FROM ALL to cache folder for suPHP / CGI user for more security.

Next Revision with these 2 functions will be updated for you on tomorrow.

@saiful
Copy link
Contributor Author

saiful commented Jun 26, 2013

Awesome! With these 2 function very interested, phpFastCache will be more reliable and safe.

Thank you very much,

@khoaofgod
Copy link
Member

I'm working on it. Will publish it soon after I have a meeting with some php guys tonight.

@khoaofgod
Copy link
Member

@saiful
It have been finished already.

You can re-download it, revision 618

Here is the changes:

public static $securityHtAccess = true;

It default set as true, .htaccess files will be created automatic under cache folder. No one can send request to download or run from outside, except local users from 127.0.0.1 - Make sure you enable AllowOverride All in Apache Virtual Host for .htaccess ( most of the host enabled this as default )

Here is the .htaccess content that I have used:

order deny, allow
deny from all
allow from 127.0.0.1

For users who are running PHP as MOD PHP5 / Apache2Handler, right now don't need to chmod 0777 anymore, /tmp dir will be used as default. If you don't want to use /tmp dir, simple change $path to somewhere and chmod 0777 manual.

Here is the code I have used to check tmp dir

// revision 618
if(self::isPHPModule()) {
     $tmp_dir = ini_get('upload_tmp_dir') ? ini_get('upload_tmp_dir') : sys_get_temp_dir();
      self::$path = $tmp_dir;
} else {
      self::$path = dirname(__FILE__);
}

Try: Delete cache.storage folder, and do not set $path. Run your testing.php and see if it works or not.

@ghost ghost assigned khoaofgod Jun 26, 2013
@saiful
Copy link
Contributor Author

saiful commented Jun 27, 2013

I have try by set $path = ''; and it run like a charm (in cron job and others).

But when I set $path with a cache path, cron job still need ask me with Sorry, Please create /root/content/8899/94857283/html/myweb/cache/f011a24472fb8efed77741001d5bc793/ and SET Mode 0777 or any Writable Permission!. It does not create a .htaccess. I think we need everything run automatically with set path or not for cron job module or not. I just want to adjustment any probability with server setting and phpFastCache parameters.

@khoaofgod
Copy link
Member

Keep $path = ""; // default
Because u're running as PHP Module / Apache2Handler, so that 's the best I can do. PHP can't do everything automatic on files / folder under Apache2Handler.

With your current PHP Mod config, if you try to install wordpress, then they gonna tell you CHMOD 0777 for many folders to install plugins automatic.

If you want everything automatic switch your PHP Config to suPHP or CGI/FCGI
OR use root to run PHP as module on cronjob.

On ROOT@localhost
Type:

crontab -e

Then setup cron like this:

php /path/to/cron_file.php > /dev/null 2>&1

Do not use WGET, with PHP run as ROOT, your PHP CRON Files, have full permission on whole server.

@saiful
Copy link
Contributor Author

saiful commented Jun 27, 2013

Thank you khoaofgod

I think there is a bug, I try run on localhost with setting

phpFastCache::$storage = "files";// "pdo","mpdo","files","memcache","memcached","apc","xcache","wincache"
phpFastCache::$autosize = 50;
phpFastCache::$path = SRV_ROOT."cache";
phpFastCache::$securityKey = md5("cache.storage.23423sadfas2342fdd");
phpFastCache::$server = array(
array("localhost",11211,30),
array("localhost",11211,70)
);

But raise exception like below:

Sorry, Please create /Applications/MAMP/htdocs/myweb/cache/sdfsa3322342sdfa/ and SET Mode 0777 or any Writable Permission!

Last time I try $storage = "files" it's run normally.

This is if I am not wrong on parameters.

@saiful
Copy link
Contributor Author

saiful commented Jun 27, 2013

I have remove @ to check what happen in line 228 and 231

Warning: mkdir() [function.mkdir]: No such file or directory on line 228

Warning: chmod() [function.chmod]: No such file or directory on line 231

I look my path is real path/full path, this path is right

@saiful
Copy link
Contributor Author

saiful commented Jun 27, 2013

Oh I am sorry, I must set full access for myweb folder on localhost to do this.

thank you

@saiful saiful closed this as completed Jun 27, 2013
@saiful
Copy link
Contributor Author

saiful commented Jun 27, 2013

Thank you @khoaofgod for cron job I will keep $path = ''; It's good solution and safe

@saiful saiful reopened this Jun 27, 2013
@saiful saiful closed this as completed Jun 27, 2013
@saiful
Copy link
Contributor Author

saiful commented Jun 27, 2013

for information I don't use WGET and other CMS opensource.

@nikmauro
Copy link
Contributor

Here the config

$cms39_cache_config = array(
        "storage"   =>  "apc",
        "path"      =>  ABS_CACHE_PATH , /** /var/www/vhosts/###/httpdocs/tmp/cache/  */
        "htaccess"  =>  false
    );

phpFastCache::setup($cms39_cache_config);
$cache = phpFastCache();

The server running FastCGI with PHP 5.4.37

Why ignore the storage aPC and return the FILE chmod issue?
The chmod issue with FastCGI it not right!
Here the logs

Fatal error: Uncaught exception 'Exception' with message 'PLEASE CHMOD /var/www/vhosts/###/httpdocs/tmp/cache//cache.storage.###/ - 0777 OR ANY WRITABLE PERMISSION!' in /var/www/vhosts/###/httpdocs/vendor/phpfastcache/phpfastcache/phpfastcache/2.4.2/drivers/files.php:58 Stack trace: #0 /var/www/vhosts/###/httpdocs/vendor/phpfastcache/phpfastcache/phpfastcache/2.4.2/drivers/files.php(108): phpfastcache_files->getFilePath('4cf0c74dd903c3b...') #1 /var/www/vhosts/###/httpdocs/vendor/phpfastcache/phpfastcache/phpfastcache/2.4.2/base.php(159): phpfastcache_files->driver_get('4cf0c74dd903c3b...', Array) #2 /var/www/vhosts/###/httpdocs/library/cache.php(151): phpFastCache->get('4cf0c74dd903c3b...') #3 /var/www/vhosts/###/httpdocs/library/functions.php(1385): cms39_cache_fetch('siteurl') #4 /var/www/vhosts/###/httpdocs/library/plugins.php(6): get_option('siteurl') #5 /var/www/vhosts/###/httpdocs/library/settings.php(6): cms39_has_su in /var/www/vhosts/###/httpdocs/vendor/phpfastcache/phpfastcache/phpfastcache/2.4.2/drivers/files.php on line 58

@khoaofgod
Copy link
Member

i will test fastcgi tonight with ur config and do a hotfix.
--> APC can't run on FastCGI, so the APC Driver will be ignored, and the backup driver "files" will be use instead of APC.
--> The problem is /var/www/vhosts/###/httpdocs/tmp/cache//cache.storage.###/ <-- I will take a look if the chmod is right permission or not, because fastCGI should run as same owner already.

-----Original Message-----
From: "nikmauro" notifications@github.com
Sent: ‎2/‎12/‎2015 5:36 AM
To: "khoaofgod/phpfastcache" phpfastcache@noreply.github.com
Cc: "Khoa Bui" khoaofgod@gmail.com
Subject: Re: [phpfastcache] PDO CHMOD 0777 (#27)

Here the config
$cms39_cache_config = array(
"storage" => "apc",
"path" => ABS_CACHE_PATH , /** /var/www/vhosts/###/httpdocs/tmp/cache/ */
"htaccess" => false
);

phpFastCache::setup($cms39_cache_config);
$cache = phpFastCache();The server running FastCGI with PHP 5.4.37
And the script return
Fatal error: Uncaught exception 'Exception' with message 'PLEASE CHMOD /var/www/vhosts/###/httpdocs/tmp/cache//cache.storage.###/ - 0777 OR ANY WRITABLE PERMISSION!' in /var/www/vhosts/###/httpdocs/vendor/phpfastcache/phpfastcache/phpfastcache/2.4.2/drivers/files.php:58 Stack trace: #0 /var/www/vhosts/###/httpdocs/vendor/phpfastcache/phpfastcache/phpfastcache/2.4.2/drivers/files.php(108): phpfastcache_files->getFilePath('4cf0c74dd903c3b...') #1 /var/www/vhosts/###/httpdocs/vendor/phpfastcache/phpfastcache/phpfastcache/2.4.2/base.php(159): phpfastcache_files->driver_get('4cf0c74dd903c3b...', Array) #2 /var/www/vhosts/###/httpdocs/library/cache.php(151): phpFastCache->get('4cf0c74dd903c3b...') #3 /var/www/vhosts/###/httpdocs/library/functions.php(1385): cms39_cache_fetch('siteurl') #4 /var/www/vhosts/###/httpdocs/library/plugins.php(6): get_option('siteurl') #5 /var/www/vhosts/###/httpdocs/library/settings.php(6): cms39_has_su in /var/www/vhosts/###/httpdocs/vendor/phpfastcache/phpfastcache/phpfastcache/2.4.2/drivers/files.php on line 58

Reply to this email directly or view it on GitHub.

@nikmauro
Copy link
Contributor

The APC driver work with Fast CGI in my server, i will try and memcache without success
If change the config with this, the cache working with APC or MEMCACHE.

$cache = phpFastCache("apc");

here my PHPINFO

System  Linux  2.6.32-504.3.3.el6.x86_64 #1 SMP Wed Dec 17 01:55:02 UTC 2014 x86_64
Build Date  Jan 21 2015 11:11:51
Server API  CGI/FastCGI
Virtual Directory Support   disabled

Additional .ini files parsed    /etc/php.d/00-ioncube-loader.ini, /etc/php.d/apc.ini, #####

Configuration
apc
APC Support enabled
Version 3.1.15-dev
APC Debugging   Disabled
MMAP Support    Enabled
MMAP File Mask  /tmp/apc.cT3Aer
Locking type    pthread mutex Locks
Serialization Support   php, igbinary
Revision    $Revision$
Build Date  Feb 14 2014 13:49:03

memcache
memcache support    enabled
Version 3.0.8
Revision    $Revision: 329835 $

Directive   Local Value Master Value
memcache.allow_failover 1   1
memcache.chunk_size 32768   32768
memcache.compress_threshold 20000   20000
memcache.default_port   11211   11211
memcache.hash_function  crc32   crc32
memcache.hash_strategy  consistent  consistent
memcache.lock_timeout   15  15
memcache.max_failover_attempts  20  20
memcache.protocol   ascii   ascii
memcache.redundancy 1   1
memcache.session_redundancy 2   2

memcached
memcached support   enabled
Version 2.2.0
libmemcached version    1.0.18
SASL support    yes
Session support yes
igbinary support    yes
json support    yes
msgpack support yes

@khoaofgod
Copy link
Member

ok, I work on that. I will rewrite the way abstract class work right now on next release Feb 23.
New class will be coded for faster and config much easier.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants