Giter Club home page Giter Club logo

Comments (17)

khoaofgod avatar khoaofgod commented on July 28, 2024

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.

from phpfastcache.

saiful avatar saiful commented on July 28, 2024

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..

from phpfastcache.

khoaofgod avatar khoaofgod commented on July 28, 2024

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.

from phpfastcache.

saiful avatar saiful commented on July 28, 2024

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

Thank you very much,

from phpfastcache.

khoaofgod avatar khoaofgod commented on July 28, 2024

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

from phpfastcache.

khoaofgod avatar khoaofgod commented on July 28, 2024

@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.

from phpfastcache.

saiful avatar saiful commented on July 28, 2024

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.

from phpfastcache.

khoaofgod avatar khoaofgod commented on July 28, 2024

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.

from phpfastcache.

saiful avatar saiful commented on July 28, 2024

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.

from phpfastcache.

saiful avatar saiful commented on July 28, 2024

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

from phpfastcache.

saiful avatar saiful commented on July 28, 2024

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

thank you

from phpfastcache.

saiful avatar saiful commented on July 28, 2024

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

from phpfastcache.

saiful avatar saiful commented on July 28, 2024

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

from phpfastcache.

nikmauro avatar nikmauro commented on July 28, 2024

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

from phpfastcache.

khoaofgod avatar khoaofgod commented on July 28, 2024

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" [email protected]
Sent: ‎2/‎12/‎2015 5:36 AM
To: "khoaofgod/phpfastcache" [email protected]
Cc: "Khoa Bui" [email protected]
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.

from phpfastcache.

nikmauro avatar nikmauro commented on July 28, 2024

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

from phpfastcache.

khoaofgod avatar khoaofgod commented on July 28, 2024

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.

from phpfastcache.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.