About chmod issue

Hello everybody,
My English not perfect sorry.

After I installed fresh magento ( I did step by step - https://digitalstartup.co.uk/magento/how-to-install-magento-23/)
Everything is good, and everything is working very well.
For example, I select magento user and If I run this chmod command,
chmod -R 777 var
I saw this issue:
chmod: changing permissions of ‘XXXXX’: Operation not permitted

Have a any idea?
Thank you so much.

Hi @gntlby

You should not need to change anything to 777. I’m not sure why you would do that.

If you are seeing this error (chmod: changing permissions of ‘XXXXX’: Operation not permitted), whilst trying to run the command as magento user then it means:

During the installation process you didn’t switch users before running some of the commands - So all of the ownerships are incorrect

If you type ls -l /var/www/html/ in the command line, it will show a list of everything in your web directory. If your magento user and file owners don’t match, then this confirms the the reason.

It’s extremely important that you double-check each step before executing a command. If these don’t match then you need to completely reset the ownership of your Magento folders and files. To do this, run the following command as the superuser.

sudo chown -R magento:www-data /var/www/html/

2 Likes

Thank you so much and I fixed it.
sudo chmod -R magento:www-data /var/www/html/

This is will be sudo chown -R magento:www-data /var/www/html/
Right?
Thank you so much again.

1 Like

Awesome. And yes, well spotted! I’ve fixed my original reply. Sorry about that.

1 Like

This post made me think of a t-shirt I saw once …

2 Likes

Hi Craig,
I need some help because I cannot handle my problem.
So, I installed Magento 2.3 as you did. Everything was ok, I set permisson, etc.
I did not get errors.
After I installed a theme, also was everything ok under installation process, but after installation a lot of directories and files permission were changed.
I made a photos before theme installation and after theme installation.
I see the new template well, but when I login to Magento backend and I would like to choose an other layout from this theme I get an error about permission problem.
Warning: mkdir(): Permission denied in /var/www/html/app/code/MageBig/MbFrame/Controller/Adminhtml/Theme/Save.php on line 265
I do not know how to set again that permission rigths what was before I installed the theme.
I used this command as a superuser: sudo chown -R magento:www-data /var/www/html/
and after I run sudo chown magento:www-data /var/www/html/
After I login as magento user and I used this command: find var generated vendor pub/static pub/media app/etc -type f -exec chmod g+w {} + && find var generated vendor pub/static pub/media app/etc -type d -exec chmod g+ws {} + && chown -R :www-data . && chmod u+x bin/magento

I am confused so much, I tired a lot of varians, but my problem is did not dissapeared.

One thing:
When I installed Magento 2.2.6 as your video instruction and after I used this commands always when I installed anything and works, but this commands not work now.
find . -type f -exec chmod 644 {} ;
find . -type d -exec chmod 755 {} ;
find ./var -type d -exec chmod 777 {} ;
find ./pub/media -type d -exec chmod 777 {} ;
find ./pub/static -type d -exec chmod 777 {} ;
chmod 777 ./app/etc
chmod 644 ./app/etc/*.xml

Hi @tomzol,

The following 2 commands (as you mentioned) would normally work for an issue like the one you’ve described:

Reset Ownership and Group:
Run from any directory as superuser

sudo chown -R magento:www-data /var/www/html/

Reset Folder and File Permissions:
Run from Magento root directory as magento user

find var generated vendor pub/static pub/media app/etc -type f -exec chmod g+w {} + && find var generated vendor pub/static pub/media app/etc -type d -exec chmod g+ws {} + && chmod u+x bin/magento

So let’s dig a little deeper into the following error:

“Warning: mkdir(): Permission denied in /var/www/html/app/code/MageBig/MbFrame/Controller/Adminhtml/Theme/Save.php on line 265”

This would suggest that either the Ownership, Group or File Permissions are incorrect. Therefore when Magento tries to make a new directory, it can’t. But obviously that shouldn’t be the case as you’ve already reset those with the above commands.

Apparently, on line 265 there is a command being executed (probably make directory). This gives us 2 things to go on.

First, you should see what the code is for line 265 of the Save.php file. This can be done by opening the Save.php file in nano and jumping to line 256:

  • nano app/code/MageBig/MbFrame/Controller/Adminhtml/Theme/Save.php
  • Then press Ctrl+_ (Control & Underscore) and type 256 to jump to that line number
  • Let me know what’s written on that line

Second, you should check the var/logs/system.log file, as this might provide further information to go on:

  • nano var/log/system.log
  • Then press Ctrl+_ (Control & Underscore)
  • Then press Ctrl+V (Control & V)
  • Then use Page Up to find the error (if it exists) here
  • Let me know what you find

Hi @digitalstartup
Thank you for your fast answer.

I checked system.log and same message than I pasted in the first comment.
I paste few lines from about this save.php file. This is the 265 line, but you can see this part to see all codes.
265 line is:

    mkdir($pathDir, 0755, true);
    
    "protected function createLess($pathDir, $dataValue)
    {
    $section        = 'mbdesign';
    $pathToLessFile = $pathDir . '_' . $section . '.less';

    if (!is_dir($pathDir)) {
        mkdir($pathDir, 0755, true);
    }

    if (!is_writable($pathDir)) {
        @chmod($pathDir, '0755');
    }

    if (is_file($pathToLessFile) && !is_writable($pathToLessFile)) {
        @chmod($pathToLessFile, '0644');
    }

    $file = @fopen($pathToLessFile, 'w') or die('error: Can not open ' . $pathToLessFile . ' file');

    $configs = [];
    //$settingHelper = $this->_objectManager->get('\MageBig\MbFrame\Helper\Data');"

Can you do the following:

  1. Share a full copy of the Save.php file
  2. Paste the output from the following command: ls -la pub/media

@digitalstartup
Of course.
To tell the truth, I restored the image from snapshot (digitalocean)so, this is a fresh status after I installed the theme but I did not run permission commands, only when you ran in the video.
permission

https://drive.google.com/open?id=1yB7k6fqi3xYh2uUwhpiGcbeRHt6umxez

Your output for ls -la is exactly what I’d hope to find with the Folders and Files being either:

  • magento www:data or
  • www-data www-data

I also don’t see anything in the Save.php that could offer any further help.

Based on what you’ve shared so far, I honestly don’t see where your issue originates from :confused:

@digitalstartup

So, If I understand well you say me that all permission is ok?
Pls. explain me again this two command works:
sudo chown magento:www-data /var/www/html/ - Is this command give owner rigths for magento user.
If I would like to reset this rights, I run sudo chown -R magento:www-data /var/www/html/ ??
Furtermore, is this long comands set the permission for this files and directories?
find var generated vendor pub/static pub/media app/etc -type f -exec chmod g+w {} + && find var generated vendor pub/static pub/media app/etc -type d -exec chmod g+ws {} + && chown -R :www-data . && chmod u+x bin/magento
By the way, I see the before last line chown -R… Could you explain what does it mean? We take the right from www-data?

Here’s a breakdown in a little more detail

Reset Ownership and Group:
Run from any directory as superuser

sudo chown -R magento:www-data /var/www/html/

  • sudo: Run command with superuser privilege.
  • chown: Change owner
  • -R: Stands for “Recursively” (This means all Files and Folders contained within the directory)
  • magento:www-data: Owner:Group
  • /var/www/html/: Directory to make changes to

On a Ubuntu OS running Apache, the Group will always be www-data. However, the Owner will be whoever you created as your magento user.

Reset Folder and File Permissions:
Run from Magento root directory as magento user

find var generated vendor pub/static pub/media app/etc -type f -exec chmod g+w {} + && find var generated vendor pub/static pub/media app/etc -type d -exec chmod g+ws {} + && chmod u+x bin/magento

This command can consist of either 3 or 4 commands all strung together with “&&”:

  1. Find files in listed directories and update the permissions
    find var generated vendor pub/static pub/media app/etc -type f -exec chmod g+w {} +
  2. Find directories and update the permissions
    find var generated vendor pub/static pub/media app/etc -type d -exec chmod g+ws {} +
  3. Change Group or everything to www-data (Not required if you’ve already run the chown command above)
    chown -R :www-data .
  4. Change File to be executable
    chmod u+x bin/magento

Hi @digitalstartup

Sorry for the late response.
Craig, your explanation is fantastic.
I appreciate your detailed answer for my problem.
Solution was the following:
I set only /app/design folders permission.
755 and 644 change to 775 and 664.
As a matter of fact, your videos are impressive and very useful. I learned much more from your videos than from all of others in the web.
Thank you so much and I hope you to continue this way.

1 Like