CSS not loading properly magento2 - magento2

CSS not loading properly in magento2. Getting below error:
NameError: variable #button__shadow-active is undefined
in _buttons.less

Do you use wampserver ?
Go to your wampserver icon and click on it and than
Apache->apache modules->rewrite_module[enable this]
After this start all services and check it ........

Css not loaded properly means static content rendering problem so,
Remove cache,page_cache,view_preprocessed from var table
Give full permissions to var folder
Run static command in magento root folder php bin/magento setup:static-content:deploy
now Roload the site

First Replace .htaccess.sample with .htaccess in root
Add .htaccess in pub/static
https://github.com/emizentech/magento2/blob/master/pub/static/.htaccess
Edit & Replace Apache config file & replace given details below.
sudo vi /etc/apache2/apache2.conf
From
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
From
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
sudo service apache2 restart
rm -rf var/cache/*
rm -rf var/generation/*
php bin/magento setup:upgrade
php bin/magento setup:static-content:deploy
chmod -R 777 pub var
This will solve your css issues, admin 404 issues , link/url 404 issue , version-xxx issue.

As the error says your less variable is missing and not found.
It means these are possible reasons for your error:
Invalid .less variable declaration.
If you are importing variables from another file - you have an invalid declaration of that file in the XML or you didn't import that file on your less file with #import "custom-variables.less";
There is a typo in your main .less file
Without code, there are only guesses. Please provide us a code so we could check it more precisely. Also, check your .log files there can be some hints.

CSS not loading properly due to static deploy not push the file to pub/static directory.
You have to follow the below steps.
rm -rf var/*
rm -rf pub/static/*
php bin/magento setup:static-content:deploy
chmod -R 7777 var pub/static

Try this,
set permission on /var and /pub folders to 777
ssh using this command
php bin/magento setup:static-content:deploy

Related

VS Code: NoPermissions (FileSystemError): Error: EACCES: permission denied

I'm trying to save a file called app.js on a folder called js.
Vs Code pop up this:
Failed to save 'app.js': Unable to write file 'vscode-remote://wsl+ubuntu-18.04/js/app.js'
(NoPermissions (FileSystemError): Error: EACCES: permission denied, mkdir '/js')
I tried:
sudo chown -R user /mnt/c/Users/myUser/Documents/myFolder/proyectFolder
but I still can't save this file.
Try this, fixed it for me
sudo chown -R username path
Example:
sudo chown -R emanuel /home/emanuel/test/
In the SSH terminal:
Recommended :
sudo chmod -R 777 folder_name_where_your_file_exists
or
sudo chmod -R 755 folder_name_where_your_file_exists
this works for me
sudo chown -R $USER:$USER /home/
TLDR;
If you're using a docker container, avoid making files from within the container because the owner and group permissions may cause problems with your editor (in my case VS Code)
I was running docker container for a Django project from Windows Terminal and using VS Code to edit my code.
It is a Linux file (since everything in Linux is a file) permission problem that arises because the files don't have proper user and/or group permissions. So VS Code tries to tell us that.
The problem I found only happened when I created files from within my docker container.
I would run docker exec ... bash
make new files using touch /path/to/file from the container bash
then try to edit those files on VS Code (say urls.py) only to get the scary permissions error preventing the file from saving.
I suspect that making files from within the container embellishes those files with different owner and group settings than your system would default to if you just ran the commands locally (not in the container).
Changing the file permissions with chown -hR and chgrp -hR would do the trick but to avoid the error altogether I stopped making files from within the container.
Try activating polling:
This worked for me during I tried using wsl.
The below is for individual file:
sudo chown yourUserNAme filename
For an entire directory it will be (when you write ls to terminal, you should see your directory to execute this command):
sudo chown yourUserNAme dirName
For recursive (i.e files and folders inside a folder):
sudo chown -R yourUserNAme dirName
Note: yourUserNAme is, if you do pwd under any Documents, you will see the path: /home/jhon/Documents. Here user is jhon.
Run VS Code as administrator and it will fix the problem.
https://answers.microsoft.com/en-us/windows/forum/all/error-in-vs-code-destination-directory-and-says/e70dc626-6b12-4791-a960-8b704e57098d
Install the extension Save as Root in Remote SSH in VS code.
While saving press Ctrl + Shift + P.
This open the command palette.
Search Save as Root
It is a Linux user permissions problem.
you should use the command:
sudo chown -R $USER:$USER.

What does [rm -rf /] do?

This is basically recursively remove everything from root right?
Would this really delete everything on the device?
Do any operating systems have protections against running this – like a confirmation or something?
Seemed like a better idea to ask than to try.
The rm command means it is applied for removing file-folders based on the file path but as you have specified rm -rf / it tells to remove the files which are part of the root directory in the Linux or Unix based system, but again it will not do anything until and unless you apply the command with sudo access or super user do access with your system password.
Yes this would delete recursively.
Actually their is also a protection:
rm: it is dangerous to operate recursively on '/'
rm: use --no-preserve-root to override this failsafe
rm -rf is a dangerouse command in linux.if rm -rf run with root privilage it force to delete all files and folders even hidden file and you must install os again. this command has not confirmation question.
As a security measure, you can set rm to always get you approved for the delete operation, it uses the "-i" option whenever you want to delete a file or directory. To make this command permanent, add the following alias to the $ HOME / .bashrc file.
When you run the rm command, it will run with the "-i" option by default. (If you use the "-f" option, these settings will be overwrite)
rm -rf
this code deletes all files on linux (system ,root files include)
this is very dangerous code

I am unable make file or directory in Visual Studio Code in Win Subsystem for Linux

I use this guide. When I take the step "Add a source code file", I am shown this report:
Unable to write file 'vscode-remote://wsl+ubuntu-20.04/home/alex/TEST/helloworld/helloworld' (NoPermissions (FileSystemError): Error: EACCES: permission denied, open '/home/alex/TEST/helloworld/helloworld')
I don't know what to do, can some one help me?
The VScode needs permissions thus
Try this command on your WSL terminal
sudo chown -R username /path/to/working/directory
Replace :
'username' with your username and the path of your directory
So I had the same problem and changing ownership via sudo chown -R username <path> did not work for me.
Simple solution!
My issue: Downloaded files for coursera project in zip. Copied files to ubuntu home/taylor/projects folder. and then tried accessing in vscode with code . I received the read error.
Solution:
go to your linux terminal.
Access the folder containing the files you are trying to work on.
For Example: app.py forms.py models.py in the projects folder. got to projects folder.
~/projects ls
app.py forms.py moodels.py routes.py
#they should be white meaning know permissions granted.
grant permissions
a. sudo chmod 777 app.py forms.py models.py routes.py
or
b. sudo chmod +rwx app.py forms.py models.py routes.py #r=read w=write x=execute
Try the above one by #uday Pratap, If not Working try this one's :
sudo chmod -R 777 folder_name_where_your_file_exists
or
sudo chmod -R 755 folder_name_where_your_file_exists

Magento2 : Admin redirection issue

I have installed Magento2 on my WAMP server. And when I tried to access http://127.0.0.1/magento2/admin/ it's redirecting to http://localhost/admin/admin/dashboard/ (An invalid URL)?
the file app/etc/env.php should start like this.. check your backend frontName :)
<?php
return array (
'backend' =>
array (
'frontName' => 'admin_xu4zwa'
),
);
I think your magento installation foldername and value in table core_config_data field "base_url" is not same.
In terminal run command: php bin/magento info:adminuri , say it shows: admin_mkp
In database run sql: SELECT * FROM core_config_data WHERE (scope LIKE '%_url%' OR path LIKE '%_url%' OR value LIKE '%_url%') LIMIT 50
Check value of web/unsecure/base_url say value is: http://127.0.0.1/magentoxyzfoldername/
Now your adminurl should be like this: http://127.0.0.1/magentoxyzfoldername/admin_mkp
note: magentoxyzfoldername is your magento installation folder name.
We can also check the admin url by using command
$ php bin/magento info:adminuri
You need to check the following
Check Your admin backend name
make sure you have mod_rewrite enabled in apache
Make sure you have installed magento properly if not try to reinstall it.
change the base_url value in table core_config_data to http://127.0.0.1/magento2/ instead of http://localhost/magento2/, you can find the record in the table using
SELECT * FROM core_config_data WHERE path='web/unsecure/base_url';.
change base url from core_config_data table and check frontName in app/etc/env.php file. Hope, this will help.
After installation of Magento2 site into a new location, you need to run all magento commands, after changing url in core_config_data table and changing connection in app/etc/env.php file.
php bin/magento setup:di:compile
php bin/magento setup:upgrade
php bin/magento setup:static-content:deploy -f
php bin/magento cache:flush
I think you need to set web/unsecure/base_url and web/secure/base_url in core_config_data table with your url like : http://127.0.0.1/magento2/
Or you can set this setting from admin side
Stores > Configuration > General > Web:
Base Urls
Base URL : http://127.0.0.1/magento2/
Base Urls (Secure)
Base URL : https://127.0.0.1/magento2/
I hope it will works!
First you can check the file app/etc/env.php and check backend frontName should be 'admin' like below.
return [
'backend' => [
'frontName' => 'admin'
],
...........
...........
...........
];
And then run this command
php bin/magento setup:di:compile
php bin/magento setup:upgrade
php bin/magento setup:static-content:deploy -f
php bin/magento cache:flush
try switch to Developer mode
bin/magento deploy:mode:set developer
Check your base_url on database core_config_data table
And also check app/etc/env.php frontName value.
After that:
set module:developer
setup:upgrade
clean cache
Open Mysql and run below mysql query:
UPDATE `core_config_data` set value = "http://127.0.0.1/magento2/admin/" WHERE path like "%base_url"
After run Mysql query you need to run below command in ssh terminal for flush cache or you can direct delete magento root var/cache folder. After that try to open magento admin it would work.
php bin/magento cache:flush
need to enter host entry for local
sudo nano /etc/apache2/sites-available/000-default.conf
Add the path to your Magento pub/ directory to the DocumentRoot directive
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot /var/www/html/magento2/pub
ServerName hostname.magento.com
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
<Directory "/var/www/html">
AllowOverride all
</Directory>
</VirtualHost>
sudo systemctl restart apache2

Using chmod for /usr directory

I used the following command to change the permissions of the usr directory from root
root> chmod -R 777 /usr
Now when I try to use the sudo command it gives the following error:
sudo: must be setuid root
On googling, I found that this error happens if /usr is chowned and I need to reinstall Ubuntu. But am I getting this error for chmod? Is there anyway to fix this problem without reinstalling?
To setuid /usr/bin/sudo: chmod +s /usr/bin/sudo.
But you changed ALL file/directory attributes in /usr recursivly (-R). You really should try some rescue mode. I don't think you'll have any chance to repair it.