3

I'm having issues installing a theme due to the 'generated' directory not generating all of the files that need to be generated after I run command:

php bin/magento setup:upgrade

Which I think is linked to permission issues (the generated directories have a default permission set to 775).

Because the generated folders are set to 775 permission, there is no 'write' permission for the other user (magento) and thus crashes instead of upgrading the new theme/modules.

I cannot run the command line as a root user as it uses cgi/fgi instead of cli. I end up having to run as the centos user which uses cli (magento's command line interface) If I could run cli commands as root user. I that would overcome the permission issues that prevents the 'generated' directory from generating all of the files and thus install modules and themes instead of throwing script errors.

I know magento 2.2.6 is relatively new and I'm probably facing an isolated issue given that the environment I'm running magento on is unique: aws instance with whm in the middle to provide greater flexibility and provide a cpanel interface.

  • This is exactly why Magento says you should setup Magento2 as a user on the server that has the correct group and permissions – Haim Nov 19 '18 at 5:04
3

Magento 2 recommended folder and file permission

Please follow following terminal commands for folder and file permission.

find . -type f -exec chmod 644 {} \;

find . -type d -exec chmod 755 {} \;

find var pub/static pub/media  generated/ app/etc -type f -exec chmod g+w {} \;

find var pub/static pub/media generated/ app/etc -type d -exec chmod g+ws {} \;
chown -R :<web server group> .

chmod u+x bin/magento

It worked like charm

|improve this answer|||||
1

It' sometimes happen, that after run any command bin/magento your generated folder has changed ovnership to youruser:youruser, but should be youruser:www-data (for apache2 for example).

To fix that run in magento directory:

sudo chown -R youruser:www-data .

and:

sudo usermod -a -G www-data youruser

after this you will never have this problem after running magento commands.

The -a -G options are important because they add apache or www-data as a secondary group to the user account, which preserves the user’s primary group. Adding a secondary group to a user account helps restrict file ownership and permissions to ensure members of a shared group only have access to certain files.

You can check this by running now:

php bin/magento c:f


ls -l generated/code

all ovnership should stay same so youruser:www-data

Ref: https://devdocs.magento.com/guides/v2.3/install-gde/prereq/file-system-perms.html

|improve this answer|||||
1

Give 777 permission to generated directory

|improve this answer|||||
0

You must read this article from Magento Devdocs, where say exactly what you want about the permissions.

cd /var/www/html/magento2 && find var vendor pub/static pub/media app/etc -type f -exec chmod g+w {} + && find var vendor pub/static pub/media app/etc -type d -exec chmod g+w {} + && chmod u+x bin/magento
|improve this answer|||||
0

If you are running selinux be sure to set the permissions for it.

semanage fcontext -a -t httpd_sys_rw_content_t '/path/to/your/magentofiles/generated(/.*)?'
restorecon -Rv '/path/to/your/magentofiles/'

Cheers!

|improve this answer|||||
0
sudo chown -R $(whoami) YOUR_PROJECT_FOLDER && sudo chmod -R 777 YOUR_PROJECT_FOLDER
|improve this answer|||||
0

In my case, I have installed a fresh Magento 2.3 setup on Windows 10 and getting permission issues. I solved it by following steps.

  1. Go to > app > etc > di.xml file and find this code Magento\Framework\App\View\Asset\MaterializationStrategy\Symlink Then replace with below code.

    Magento\Framework\App\View\Asset\MaterializationStrategy\Copy

  2. Go to vendor\magento\framework\View\Element\Template\File\Validator then fix the real pate like this:

    $realPath = str_replace('\', '/', $this->fileDriver->getRealPath($path));

  3. Now run following commands: php bin/magento setup:upgrade php bin/magento setup:di:compile php bin/magento s:s:d -f php bin/magento c:c

  4. After running step 3 if you got blank page then please remove/rename global.php file from generated\metadata\

Now it should work.

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.