set permission for magento – magento-cleaning
set permission for magento – magento-cleaning
If you are facing issue of permissions or internal server error then try to set permission to magento folder that might help you.
set 777 for media , var and app/etc folder
and for rest of file and folders create a file with name “magento-cleaning.php” and paste the blow code in that file and put this on root folder and hit this in url.
example: www.yourdomain.com/magento-cleaning.php
Setting up Varnish Cache on Ubuntu and Magento 2: A Comprehensive Guide
<?php ## Function to set file permissions to 0644 and folder permissions to 0755 function AllDirChmod( $dir = "./", $dirModes = 0755, $fileModes = 0644 ){ $d = new RecursiveDirectoryIterator( $dir ); foreach( new RecursiveIteratorIterator( $d, 1 ) as $path ){ if( $path->isDir() ) chmod( $path, $dirModes ); else if( is_file( $path ) ) chmod( $path, $fileModes ); } } ## Function to clean out the contents of specified directory function cleandir($dir) { if ($handle = opendir($dir)) { while (false !== ($file = readdir($handle))) { if ($file != '.' && $file != '..' && is_file($dir.'/'.$file)) { if (unlink($dir.'/'.$file)) { } else { echo $dir . '/' . $file . ' (file) NOT deleted!<br />'; } } else if ($file != '.' && $file != '..' && is_dir($dir.'/'.$file)) { cleandir($dir.'/'.$file); if (rmdir($dir.'/'.$file)) { } else { echo $dir . '/' . $file . ' (directory) NOT deleted!<br />'; } } } closedir($handle); } } function isDirEmpty($dir){ return (($files = @scandir($dir)) && count($files) <= 2); } echo "----------------------- CLEANUP START -------------------------<br/>"; $start = (float) array_sum(explode(' ',microtime())); echo "<br/>*************** SETTING PERMISSIONS ***************<br/>"; echo "Setting all folder permissions to 755<br/>"; echo "Setting all file permissions to 644<br/>"; AllDirChmod( "." ); echo "Setting pear permissions to 550<br/>"; chmod("pear", 550); echo "<br/>****************** CLEARING CACHE ******************<br/>"; if (file_exists("var/cache")) { echo "Clearing var/cache<br/>"; cleandir("var/cache"); } if (file_exists("var/session")) { echo "Clearing var/session<br/>"; cleandir("var/session"); } if (file_exists("var/minifycache")) { echo "Clearing var/minifycache<br/>"; cleandir("var/minifycache"); } if (file_exists("downloader/pearlib/cache")) { echo "Clearing downloader/pearlib/cache<br/>"; cleandir("downloader/pearlib/cache"); } if (file_exists("downloader/pearlib/download")) { echo "Clearing downloader/pearlib/download<br/>"; cleandir("downloader/pearlib/download"); } if (file_exists("downloader/pearlib/pear.ini")) { echo "Removing downloader/pearlib/pear.ini<br/>"; unlink ("downloader/pearlib/pear.ini"); } echo "<br/>************** CHECKING FOR EXTENSIONS ***********<br/>"; If (!isDirEmpty("app/code/local/")) { echo "-= WARNING =- Overrides or extensions exist in the app/code/local folder<br/>"; } If (!isDirEmpty("app/code/community/")) { echo "-= WARNING =- Overrides or extensions exist in the app/code/community folder<br/>"; } $end = (float) array_sum(explode(' ',microtime())); echo "<br/>------------------- CLEANUP COMPLETED in:". sprintf("%.4f", ($end-$start))." seconds ------------------<br/>"; ?>
How to set permission in Magento 2
1. Magento 2 file permissions command
- find . -type f -exec chmod 644 {} \;
2. Magento 2 folder permissions command
- find . -type d -exec chmod 755 {} \;
3. Magento 2 pub/static permission command
- find ./var -type d -exec chmod 777 {} \;
- find ./pub/media -type d -exec chmod 777 {} \;
- find ./pub/static -type d -exec chmod 777 {} \;
4. Bin/magento permission
- chmod +x path_to_file/file_name
5. Magento 2 file permission Check failed
- sudo chmod 777 -R var/ generated/ pub/
6. Magento 2 reset file permissions
- cd <your Magento install dir>
- find . -type f -exec chmod 644 {} \;// 644 permission for files
- find . -type d -exec chmod 755 {} \;// 755 permission for folders
- chmod 644 ./app/etc/*.xml
- chown -R :<web server group>
- chmod u+x bin/magento
Recent Comments