Hi There,
Is this script is correct to run to correct folder and files permissions for the CRM please ?
Fixing SugarCRM file and directory permissions...
<?php // // fix-permissions.php // 22 August 2011 // for SugarCRM 5 and 6. // Not tested on other releases, but may work. // // fix-permissions-v2.php // 29 Jan 2012 // Adapted to work on the more restrictive shared servers // that block access to PHP function "system()" for security reasons. // // v3 // with contribution from Courtney L. Bostdorff (selfmade64856). // - two separate sets of permissions: // - 755 all folders and 644 all files, except // - 775 (4 folders and all their subfolders) and 664 (3 files in the Sugar root, and all files in all the subdirectories of the 4 folders). // - todo: add support for automatic modification of the default_permissions in ./config.pgp and ./include/utils.php // // Purpose: Allows SugarCRM to run correctly on a Linux shared web hosting acount // by fixing file permissions to 644 and folder permissions to 755. // v3.0: 2 sets of permissions for files/folders, // and 2 sets of permissions for variables in config.php and util.php // // Credits: Adapted by Chris Coleman of www.ESPACEnetworks.com // // Directions: // 1) Save this file in the base folder of your SugarCRM installation. // Example: Your company's SugarCRM instance is at the URL http://www.mycompany.com/crm // SugarCRM files are installed on the Linux shared host on the folder: public_html/crm // So save this file at the location: public_html/crm/fix-permissions.php // 2) To run this file, view the corresponding URL in your browswer: // http://www.mycompany.com/crm/fix-permissions.php // // Questions or feedback, feel free to contact me. // -Chris Coleman // /** * get execution time in seconds at current point of call in seconds * @return float Execution time at this point of call */ function get_execution_time() { static $microtime_start = null; if($microtime_start === null) { $microtime_start = microtime(true); return 0.0; } return microtime(true) - $microtime_start; } get_execution_time(); //set start point to now.function chmod_R($path, $filemode = 0644, $dirmode = 0755) {
if (is_dir($path) ) {
if (!chmod($path, $dirmode)) {
$dirmode_str=decoct($dirmode);
print “Failed applying filemode ‘$dirmode_str’ on directory ‘$path’\n”;
print " `-> the directory ‘$path’ will be skipped from recursive chmod\n";
return;
}
$dh = opendir($path);
while (($file = readdir($dh)) !== false) {
if($file != ‘.’ && $file != ‘…’) { // skip self and parent pointing directories
$fullpath = $path.’/’.$file;
chmod_R($fullpath, $filemode,$dirmode);
}
}
closedir($dh);
} else {
if (is_link($path)) {
print “link ‘$path’ is skipped\n”;
return;
}
if (!chmod($path, $filemode)) {
$filemode_str=decoct($filemode);
print “Failed applying filemode ‘$filemode_str’ on file ‘$path’\n”;
return;
}
}
}$current_user = get_current_user();
echo ’ Script owner: ’ . $current_user . ‘
’;
$processUser = posix_getpwuid(posix_geteuid());
$processUserName = $processUser[‘name’];
echo ‘Process owner: ‘. $processUserName .’
’;// Phase I: 644 all files, 755 all folders.
echo “
Phase I: Permissions. 644 all files, 755 all folders
Fixing: set all files to 644, all folders to 755, recursively.
”;
chmod_R ( “./” );// Phase II: 664 files, 775 folders.
echo “
Phase II: Permissions. Some files 664 and some folders 775.
Fixing config.php
”;
chmod_R ( “./config.php”, 0664, 0775 );
echo “
Fixing config_override.php
”;
chmod_R ( “./config_override.php”, 0664, 0775 );
echo “
Fixing sugarcrm.log
”;
chmod_R ( “./sugarcrm.log”, 0664, 0775 );
echo “
Fixing cache dir (all files and subdirs)
”;
chmod_R ( “./cache”, 0664, 0775 );
echo “
Fixing custom dir (all files and subdirs)
”;
chmod_R ( “./custom”, 0664, 0775 );
echo “
Fixing data dir (all files and subdirs)
”;
chmod_R ( “./data”, 0664, 0775 );
echo “
Fixing modules dir (all files and subdirs)
”;
chmod_R ( “./modules”, 0664, 0775 );//Phase III: Fix settings inside ./config.php and ./include/utils.php
echo "
Phase III: Do the following manually.
Fix the default_permissions setting in 3 places:
1) ./config.php
";$fixed_config = “‘dir_mode’ => 02755,\n ‘file_mode’ => 0644,\n ‘user’ => ‘$current_user’,\n ‘group’ => ‘$current_user’,”;
echo " ‘default_permissions’ => array (
$fixed_config
),
\n";echo "
2) ./include/utils.php - in the function make_sugar_config() - line 138
";$fixed_make_sugar_config = “‘dir_mode’ => 02770,\n ‘file_mode’ => 0660,\n ‘chown’ => ‘$current_user’,\n ‘chgroup’ => ‘$current_user’,”;
echo " ‘default_permissions’ => array (
$fixed_make_sugar_config
),
\n";echo “
3) ./include/utils.php - in the function get_sugar_config_defaults() - line 264
”;$fixed_get_sugar_config_defaults = “‘dir_mode’ => 02770,\n ‘file_mode’ => 0660,\n ‘user’ => ‘$current_user’,\n ‘group’ => ‘$current_user’,”;
echo " ‘default_permissions’ => array (
$fixed_get_sugar_config_defaults
),
\n";echo “
Done.
”;
echo “
Execution time: “.get_execution_time().” seconds.
”
?>