I have installed Magento 2.4.5 in Centos Server but Images and styles are not loading.
I can see the static assets from
<magento_root>/pub/static/
But in the source code I can't see '/pub' directory in the url
below is the generated path
http://mydomain.com/static/version1661267843/frontend/Magento/luma/en_US/mage/calendar.css
I run below command, but no luck
php bin/magento setup:upgrade php bin/magento setup:di:compile php bin/magento setup:static-content:deploy -f php bin/magento cache:flush php bin/magento indexer:reindex
This is the root .htaccess
RewriteEngine on RewriteCond %{REQUEST_URI} !^/pub/ RewriteCond %{REQUEST_URI} !^/setup/ RewriteCond %{REQUEST_URI} !^/update/ RewriteCond %{REQUEST_URI} !^/dev/ RewriteRule .* /pub/$0 [L] DirectoryIndex index.php
Hi @sainulabidnv ,
Please try solutions one by one.
One of the solution will fix your issue.
1)
Execute following commands in your terminal window
sudo a2enmod rewrite
sudo service apache2 restart
Navigate to /var/www/html/magento2_root and execute following command
sudo php bin/magento c:f
Check front-end or back-end in private window.
2)
open /etc/apache2/apache2.conf
Navigate to the place in the apache2.conf file <Directory /var/www/>
Change "AllowOverride None" to "AllowOverride All"
Save the file
Example:
From:
<Directory /var/www/> Options Indexes FollowSymLinks AllowOverride None Require all granted </Directory>
To:
<Directory /var/www/> Options Indexes FollowSymLinks AllowOverride All Require all granted </Directory>
sudo service apache2 restart
Navigate to /var/www/html/magento2_root and execute following command
sudo php bin/magento c:f
Check front-end or back-end in private window.
3)
Open app > etc > di.xml
find the virtualType name="developerMaterialization" section. In that section below, you will find an item <item name="view_preprocessed" xsi:type="object">
Modify
From: Magento\Framework\App\View\Asset\MaterializationStrategy\Symlink
To: Magento\Framework\App\View\Asset\MaterializationStrategy\Copy
Navigate to /var/www/html/magento2_root and execute following command
sudo php bin/magento s:di:c
sudo php bin/magento c:f
Check front-end or back-end in private window.
Problem Solved? Accept as Solution!
Hope it helps!
Thanks
Hello @sainulabidnv
Kindly follow below steps:
1) Change "Magento\Framework\App\View\Asset\MaterializationStrategy\Symlink" to "Magento\Framework\App\View\Asset\MaterializationStrategy\Copy" in app/etc/di.xml file (line 598) 2) Run via ssh: php bin/magento setup:static-content:deploy 3) Next command: chmod -R 777 pub/* 4) And finally: rm -rf var/*
It may help you!
Thank you
I have updated di.xml and run the mentioned command, but still the issue exist.
my di.xml code
<virtualType name="developerMaterialization" type="Magento\Framework\App\View\Asset\MaterializationStrategy\Factory"> <arguments> <argument name="strategiesList" xsi:type="array"> <item name="view_preprocessed" xsi:type="object">Magento\Framework\App\View\Asset\MaterializationStrategy\Copy</item> <item name="default" xsi:type="object">Magento\Framework\App\View\Asset\MaterializationStrategy\Copy</item> </argument> </arguments> </virtualType>
This was the setup code :
php bin/magento setup:install \ --base-url=http://subdomain.domain.com \ --db-host=localhost \ --db-name=xx_23db \ --db-user=xx_23dbusr \ --db-password=hc?]SsNreqvi \ --admin-firstname=admin \ --admin-lastname=admin \ --admin-email=admin@admin.com \ --admin-user=admin \ --admin-password=admin123 \ --language=en_US \ --currency=USD \ --timezone=America/Chicago \ --use-rewrites=1 \
Hi @Ankit Jasani ,
Thank you for the reply.
I tried all three solutions, but the issue still exist.
1, the mod_rewrite Apache module is enabled by default.
2, update "AllowOverride None" to "AllowOverride All" and resatarted apache and run listed command.
3, This is the current di.xml
<virtualType name="developerMaterialization" type="Magento\Framework\App\View\Asset\MaterializationStrategy\Factory"> <arguments> <argument name="strategiesList" xsi:type="array"> <item name="view_preprocessed" xsi:type="object">Magento\Framework\App\View\Asset\MaterializationStrategy\Copy</item> <item name="default" xsi:type="object">Magento\Framework\App\View\Asset\MaterializationStrategy\Copy</item> </argument> </arguments> </virtualType>
Hi @sainulabidnv ,
Could you please provide screenshot with inspect element console?
Thanks
- Source code screenshot
- Frond end
- Server file location
[root@ded4xxx /]# cd /home/domain-user/public_html/ [root@ded4xxx public_html]# ls app composer.json generated LICENSE_AFL.txt phpserver var auth.json.sample composer.lock grunt-config.json.sample LICENSE.txt project-community-edition vendor bin COPYING.txt Gruntfile.js.sample nginx.conf.sample pub cgi-bin dev index.php__ package.json.sample SECURITY.md CHANGELOG.md error_log lib
Hi @sainulabidnv ,
From your above screenshot of source code take first calendar.css path and open in browser.
I can see path contains pub word in between. If url not loaded data then remove pub/ from path and open url direct in browser.
Let me know what happens when you do above thing.
Hope it helps!
Thanks
Hi @Ankit Jasani ,
The calendar.css is working only in " /m2/pub/static/frontend/Magento/luma/en_US/mage/calendar.css"
I have installed the Magento in tow sub domain for testing,
1, Installed Magento in sub director named 'm2' and link is - m23 . masterpieceproav . com (no space)
2, Installed Magento in root directory and link is - mg . masterpieceproav . com (no space)
@sainulabidnv
If you are talking about subdomain then you need to do below steps I think.
1) copy index.php and .htaccess files from /pub to your magento root folder (into shop folder)
2) Find the below line in index.php (from the shop folder)
require _DIR_ . '/../app/bootstrap.php';
and replace it with
require _DIR_ . '/app/bootstrap.php';
3) Go to magento 2 database which you recently created and find the table core_config_data
In this table you need to insert/update below rows
Path => Value
a) web/secure/base_static_url => https://xyz.com/pub/static/
b) web/unsecure/base_static_url => https://xyz.com/pub/static/
c) web/secure/base_media_url => https://xyz.com/pub/media/
d) web/unsecure/base_media_url => https://xyz.com/pub/media/
Hope it helps!
Thanks