0
Magento 2.4.2-p1
Smartwave Porto theme
9 extensions from Amasty
cPanel Version  98.0 (build 9)
Apache Version  2.4.51
PHP Version 7.3.31
MySQL Version   5.7.35
Operating System    linux
Perl Version    5.16.3
Kernel Version  5.13.4-x86_64-linode146

We have a problem with our new Magento 2.4.2-p1 which is running on a NEWmagento account in our VPS hosting account. This appears when I try to set the Main Website (Default Store View) to a different domain than is the domain where Magento is installed.

Here is what I'm trying to do:

On our old Magento 1.9.4 running on the OLDmagento account in the same VPS hosting account, we have the following in Configuration:

Default Config:

Main website and 'Main Website Default Store View':

We access that Magento's Admin panel via https://www.justadomainwhereOLDmagentoISinstalled.com/admin and this works perfectly well (no problems).

I moved the actualproductionstoredomain.com domain from the old Magento 1.9.4 (on OLDmagento account) to the new Magento 2.4.2-p1 (onto NEWmagento account). I have done this:

  • removed the actualproductionstoredomain.com domain from the 'Domains' area (in cPanel) of the OLDmagento account and added it to the 'Domains' area (in cPanel) in the NEWmagento account
  • changed the Secure and Unsecure URL for the Main store (NOT the default Config) and it completely crashed the Admin panel = the Admin panel disappeared as soon as I saved this change and was showing as a broken version of the website right away or as an internal Magento 404 later when trying to access it directly via the Admin URL = https://www.justadomainwhereNEWmagentoISinstalled.com/admin

I had to do the following just to bring the Magento Admin panel back:


Step 1:

Connect to our database via phpMyAdmin, sort the rows by the Value heading and look for starting with http...

Step 2: Change the URL(s) on all the lines back to https://www.justadomainwhereNEWmagentoISinstalled.com

Step 3: Run the following commands via SSH:

php bin/magento setup:upgrade

php bin/magento setup:static-content:deploy -f

php bin/magento cache:clean

php bin/magento cache:flush

php bin/magento indexer:reindex

Luckily, this did fix the Admin panel.


I have done a new experiment next:

  1. I set up a new domain in Domains in the cPanel of the NEWmagento account = TESTdomain.com.

  2. I've changed the Base URL in the ' Default Store View' only under 'MAIN WEBSITE' (NOT the 'Default Config' mind you) to the following for both Secure Base URL and Unsecure Base URL:

http://www.TESTdomain.com/

As soon as I have saved this change, the Admin panel broke and is only showing a broken version of the website itself.

Also, if I try to access the Magento Admin panel directly by going to:

https://www.justadomainwhereNEWmagentoISinstalled.com/admin

It showed the same = broken version of the Main Store's website or now it shows the Magento internal 404 Error message (please see the screenshot below).

Why is this happening and how to fix it? The way we had this set up previously on our old Magento 1.9.4 and the articles I found seem to suggest this should not happen.

One thing I did notice is that we have the actual domain in Base Link URL instead of {{unsecure_base_url}} or whatever value that supposes to have. Could that be causing the problem? I have since removed the actual domain from there and put these in instead but it is not making any difference:

{{unsecure_base_url}}
{{secure_base_url}}

UPDATED on October 11th, 2021:

I switched the live domain because I tested with a test domain and it seemed to work but what happened is:

https://www.actualproductionstoredomain.com/

but when I checked the Unsecure and Secure URL for the Main Store storefront - it had the following:

https://www.justadomainwhereNEWmagentoISinstalled.com

and I switched it to:

https://www.actualproductionstoredomain.com/

Now when trying to access the Admin panel - it loads the Main Website's header and footer and background color with the following Error:

404
You might want to check that URL again or head over to our homepage.

enter image description here


I tried deleting the .htaccess file in Magento root and also copying the one from the pub folder and both instances give the following error when trying to access the Admin panel:

Not Found
The requested URL was not found on this server.

Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.

I think the .htaccess file I have in there might be the one or at least with the lines from the old Magento 1.9.4:

## enable rewrites

    Options +FollowSymLinks
    RewriteEngine on
  
SetEnvIf Host .*website2.* MAGE_RUN_CODE=website2CODE
SetEnvIf Host .*website2.* MAGE_RUN_TYPE=website

SetEnvIf Host .*website3.* MAGE_RUN_CODE=website3CODE
SetEnvIf Host .*website3.* MAGE_RUN_TYPE=website

SetEnvIf Host .*website4.* MAGE_RUN_CODE=website4CODE
SetEnvIf Host .*website4.* MAGE_RUN_TYPE=website

Please note I don't have the Main Website (actualproductionstoredomain.com) in here at all! I tried to add it in but it just crashed the Admin panel again.


Updated again on October 11th, 2021:

I've added the actualproductionstoredomain.com into 'Domains' in cPanel. It says:

Document Root = /public_html

Should I change that to /public_html/pub/?

My Magento is installed in /public_html/.

Also - is 'Domain' the right place to put this into or should I use Addon Domains or Aliases in cPanel?


In the end what I found is this:

The Admin panel loads fine when I change the domain of the Main Website only (to actualproductionstoredomain.com) and keep the Default Store View to be this:

justadomainwhereNEWmagentoISinstalled.com

The problem with this is that when you go to:

actualproductionstoredomain.com

It loads the store's front page with the correct URL but as soon as you click on something on the front page, the URL changes back to:

justadomainwhereNEWmagentoISinstalled.com

but the Admin panel will load.

If I set it up with both:

Main Website
Default Store View 

to have actualproductionstoredomain.com in Secure and Unsecure URL then the Admin panel loads with the 404 Error above.

I found the following in my system.log - is that related?

2021-10-12 13:33:03] main.INFO: Consumer "async.operations.all" skipped as required connection "amqp" is not configured. Unknown connection name amqp [] []

I have also raised this with my hosting company but they weren't much help:

"I have reviewed your 'https://www.justadomainwhereNEWmagentoISinstalled.com' website and it is accessible as per the following screenshot:

However, there are multiple entries for 'actualproductionstoredomain.com' as you can see in the following screenshot:

This is exactly the reason why the issue with the Admin Area of the website occurs and the best we can do in this case, would be to attempt to replace all entries for 'actualproductionstoredomain.com' with 'justadomainwhereNEWmagentoISinstalled.com', however, we would need your confirmation in order to do so.

However, if that is a Multistore Magento website that is supposed to work under both of the Domains, I would advise you to contact a Certified Web Developer because the configuration and investigation of issues related to a Multistore Magento website is a task that requires deep Web Development Knowledge which is out of our Scope of Expertise as a Web Hosting Provider.

If any server-side adjustments are required, you can update us via this ticket and we would gladly apply them for you.


UPDATED on October 14th, 2021:

When I run the following in my phpMyAdmin:

Select * from mget_core_config_data where path like '%secure%'

I get a long list where:

scope (ID=0) DEFAULT web/unsecure/base_url=https://www.justadomainwhereNEWmagentoISinstalled.com/

scope (ID=0) DEFAULT web/secure/base_url=https://www.justadomainwhereNEWmagentoISinstalled.com/

scope (ID=1) websites web/unsecure/base_url=https://www.actualproductionstoredomain.com

scope (ID=1) websites web/secure/base_url=https://www.actualproductionstoredomain.com

scope (ID=1) stores=web/unsecure/base_url=https://www.justadomainwhereNEWmagentoISinstalled.com/

scope (ID=1) stores=web/unsecure/base_url=https://www.justadomainwhereNEWmagentoISinstalled.com/

scope (ID=1) stores=web/secure/base_url=https://www.justadomainwhereNEWmagentoISinstalled.com/

scope (ID=1) stores=web/secure/base_url=https://www.justadomainwhereNEWmagentoISinstalled.com/

That's the problem really because if I change the scope ID=1 stores to the actualproductiondomain - then the Admin panel will not load.


Here is the .htaccess from Magento root:

enable rewrites

Options +FollowSymLinks
RewriteEngine on


SetEnvIf Host .*actualproductionstoredomain.* MAGE_RUN_CODE=base
SetEnvIf Host .*actualproductionstoredomain.* MAGE_RUN_TYPE=website
    
SetEnvIf Host .*domain2.* MAGE_RUN_CODE=domain2
SetEnvIf Host .*domain2.* MAGE_RUN_TYPE=website

SetEnvIf Host .*domain3.* MAGE_RUN_CODE=domain3
SetEnvIf Host .*domain3.* MAGE_RUN_TYPE=website

SetEnvIf Host .*domain4.* MAGE_RUN_CODE=domain4
SetEnvIf Host .*domain4.* MAGE_RUN_TYPE=website

SetEnvIf Host .*domain5.* MAGE_RUN_CODE=flowers
SetEnvIf Host .*domain5.* MAGE_RUN_TYPE=website

Please note that all other domains (domain2.com, domain3.com domain4.com and domain5.com) work as expected.


The one from Magento root/pub looks different - it does not have the domains in it:

############################################
## Optional override of deployment mode. We recommend you use the
## command bin/magento deploy:mode:set to switch modes instead

# Options are default, production, or developer
#   SetEnv MAGE_MODE default

############################################
## Uncomment these lines for CGI mode.
## Make sure to specify the correct cgi php binary file name
## it might be /cgi-bin/php-cgi

#    Action php5-cgi /cgi-bin/php5-cgi
#    AddHandler php5-cgi .php

############################################
## GoDaddy specific options

#   Options -MultiViews

## You might also need to add this line to php.ini
##     cgi.fix_pathinfo = 1
## If it still doesn't work, rename php.ini to php5.ini

############################################
## Enable usage of methods arguments in backtrace

    #SetEnv MAGE_DEBUG_SHOW_ARGS 1

############################################
## This line is specific for 1and1 hosting

    #AddType x-mapp-php5 .php
    #AddHandler x-mapp-php5 .php

############################################
## Default index file

    DirectoryIndex index.php

<IfModule mod_php7.c>
############################################
## Adjust memory limit

    php_value memory_limit 756M
    php_value max_execution_time 18000

############################################
## Disable automatic session start
## before autoload was initialized

    php_flag session.auto_start off

############################################
## Enable resulting html compression

    #php_flag zlib.output_compression on

###########################################
# Disable user agent verification to not break multiple image upload

    php_flag suhosin.session.cryptua off
</IfModule>

<IfModule mod_security.c>
###########################################
# Disable POST processing to not break multiple image upload

    SecFilterEngine Off
    SecFilterScanPOST Off
</IfModule>

<IfModule mod_deflate.c>

############################################
## Enable apache served files compression
## http://developer.yahoo.com/performance/rules.html#gzip

    # Insert filter on all content
    ###SetOutputFilter DEFLATE
    # Insert filter on selected content types only
    #AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css text/javascript application/javascript application/x-javascript application/json image/svg+xml

    # Netscape 4.x has some problems...
    #BrowserMatch ^Mozilla/4 gzip-only-text/html

    # Netscape 4.06-4.08 have some more problems
    #BrowserMatch ^Mozilla/4\.0[678] no-gzip

    # MSIE masquerades as Netscape, but it is fine
    #BrowserMatch \bMSIE !no-gzip !gzip-only-text/html

    # Don't compress images
    #SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png)$ no-gzip dont-vary

    # Make sure proxies don't deliver the wrong content
    #Header append Vary User-Agent env=!dont-vary

</IfModule>

<IfModule mod_ssl.c>

############################################
## Make HTTPS env vars available for CGI mode

    SSLOptions StdEnvVars

</IfModule>

############################################
## Workaround for Apache 2.4.6 CentOS build when working via ProxyPassMatch with HHVM (or any other)
## Please, set it on virtual host configuration level

##    SetEnvIf Authorization "(.*)" HTTP_AUTHORIZATION=$1
############################################

<IfModule mod_rewrite.c>

############################################
## Enable rewrites

    Options +FollowSymLinks
    RewriteEngine on

############################################
## You can put here your magento root folder
## path relative to web root

    #RewriteBase /magento/

############################################
## Workaround for HTTP authorization
## in CGI environment

    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

############################################
## TRACE and TRACK HTTP methods disabled to prevent XSS attacks

    RewriteCond %{REQUEST_METHOD} ^TRAC[EK]
    RewriteRule .* - [L,R=405]

############################################
## Redirect for mobile user agents

    #RewriteCond %{REQUEST_URI} !^/mobiledirectoryhere/.*$
    #RewriteCond %{HTTP_USER_AGENT} "android|blackberry|ipad|iphone|ipod|iemobile|opera mobile|palmos|webos|googlebot-mobile" [NC]
    #RewriteRule ^(.*)$ /mobiledirectoryhere/ [L,R=302]

############################################
## Never rewrite for existing files, directories and links

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-l

############################################
## Rewrite everything else to index.php

    RewriteRule .* index.php [L]

</IfModule>


############################################
## Prevent character encoding issues from server overrides
## If you still have problems, use the second line instead

    AddDefaultCharset Off
    #AddDefaultCharset UTF-8
    AddType 'text/html; charset=UTF-8' html

<IfModule mod_expires.c>

############################################
## Add default Expires header
## http://developer.yahoo.com/performance/rules.html#expires

    ExpiresDefault "access plus 1 year"
    ExpiresByType text/html A0
    ExpiresByType text/plain A0

</IfModule>

###########################################
## Deny access to release notes to prevent disclosure of the installed Magento version

    <Files RELEASE_NOTES.txt>
        <IfVersion < 2.4>
            order allow,deny
            deny from all
        </IfVersion>
        <IfVersion >= 2.4>
            Require all denied
        </IfVersion>
    </Files>
    <Files .htaccess>
        <IfVersion < 2.4>
            order allow,deny
            deny from all
        </IfVersion>
        <IfVersion >= 2.4>
            Require all denied
        </IfVersion>
    </Files>
## Deny access  to cron.php
    <Files cron.php>
        <IfVersion < 2.4>
            order allow,deny
            deny from all
        </IfVersion>
        <IfVersion >= 2.4>
            Require all denied
        </IfVersion>
    </Files>
## Deny access  to .user.ini
    <Files .user.ini>
        <IfVersion < 2.4>
            order allow,deny
            deny from all
        </IfVersion>
        <IfVersion >= 2.4>
            Require all denied
        </IfVersion>
    </Files>

# For 404s and 403s that aren't handled by the application, show plain 404 response
ErrorDocument 404 /errors/404.php
ErrorDocument 403 /errors/404.php

################################
## If running in cluster environment, uncomment this
## http://developer.yahoo.com/performance/rules.html#etags

    #FileETag none

# ######################################################################
# # INTERNET EXPLORER                                                  #
# ######################################################################

# ----------------------------------------------------------------------
# | Document modes                                                     |
# ----------------------------------------------------------------------

# Force Internet Explorer 8/9/10 to render pages in the highest mode
# available in the various cases when it may not.
#
# https://hsivonen.fi/doctype/#ie8
#
# (!) Starting with Internet Explorer 11, document modes are deprecated.
# If your business still relies on older web apps and services that were
# designed for older versions of Internet Explorer, you might want to
# consider enabling `Enterprise Mode` throughout your company.
#
# https://msdn.microsoft.com/en-us/library/ie/bg182625.aspx#docmode
# http://blogs.msdn.com/b/ie/archive/2014/04/02/stay-up-to-date-with-enterprise-mode-for-internet-explorer-11.aspx

<IfModule mod_headers.c>
    ############################################
    Header set X-UA-Compatible "IE=edge"

    # `mod_headers` cannot match based on the content-type, however,
    # the `X-UA-Compatible` response header should be send only for
    # HTML documents and not for the other resources.
    <FilesMatch "\.(appcache|atom|bbaw|bmp|crx|css|cur|eot|f4[abpv]|flv|geojson|gif|htc|ico|jpe?g|js|json(ld)?|m4[av]|manifest|map|mp4|oex|og[agv]|opus|otf|pdf|png|rdf|rss|safariextz|svgz?|swf|topojson|tt[cf]|txt|vcard|vcf|vtt|webapp|web[mp]|webmanifest|woff2?|xloc|xml|xpi)$">
        Header unset X-UA-Compatible
    </FilesMatch>

    ## Prevent clickjacking
    Header set X-Frame-Options SAMEORIGIN
</IfModule>

Do I need to upload the .htaccess from root to Magento root/pub/ ?


UPDATED on October 16th, 2021:

I am still desperately trying to make this work. I made a ticket with our hosting company (Fastcomet.com) today to modify my /etc/httpd/conf/httpd.conf as follows:

<VirtualHost *:80>
   ServerName          justadomainwhereNEWmagentoISinstalled.com/
   DocumentRoot        
</VirtualHost>


<VirtualHost *:80>
   ServerName          actualproductionstoredomain.com/
   DocumentRoot        
   SetEnv MAGE_RUN_CODE "base"
   SetEnv MAGE_RUN_TYPE "website"
</VirtualHost>



<VirtualHost *:80>
   ServerName          domain2.com
   DocumentRoot        
   SetEnv MAGE_RUN_CODE "domain2"
   SetEnv MAGE_RUN_TYPE "website"
</VirtualHost>


<VirtualHost *:80>
   ServerName          domain3.com
   DocumentRoot        
   SetEnv MAGE_RUN_CODE "domain3"
   SetEnv MAGE_RUN_TYPE "website"
</VirtualHost>


<VirtualHost *:80>
   ServerName          domain4.com
   DocumentRoot        
   SetEnv MAGE_RUN_CODE "domain4"
   SetEnv MAGE_RUN_TYPE "website"
</VirtualHost>

Where my Magento root actually is root/public_html/

and they've come back saying:

Note that the httpd configuration file has already been configured in order to serve your Magento 2 application from the following document root:

> /home/justadomainwhereNEWmagentoISinstalled/public_html

With the current configuration you requested, the site appears as such:

and there was a picture of a broken site = text only, no pictures etc.

Then our site was down for hours and finally they came back with:

*After thoroughly reviewing the matter, it appears the following lines:

SetEnv MAGE_RUN_CODE "domain2"
SetEnv MAGE_RUN_TYPE "website"

Were causing the main issue with the 404 on the admin page. Furthermore, your pub/static directory was missing an .htaccess file, and the pub directory itself had an incorrect .htaccess file. I have since reconfigured the .htaccess files and removed the SetEnv from the httpd configuration and your admin area should now be fully accessible:*

But this only brought things back to the way they were before (as described in this post) = Admin panel still broken when MAIN WEBSITE DEFAULT STORE VIEW URL is changed to: actualproductionstoredomain.com/

!The issue is still not fixed and on top of that - I am unable to load domain/website2!


Other things I've tried:

SELECT * FROM mget_core_config_data WHERE path = 'web/seo/use_rewrites'

and made sure value = 0.

Deleted var/cache folder



UPDATED on October 17th, 2021:

THIS ISSUE HAS NOW BEEN RESOLVED BY OUR HOSTING COMPANY! I first asked them to configure /etc/httpd/conf/httpd.conf. They replied:

Note that the httpd configuration file has already been configured in order to serve your Magento 2 application from the following document root:

> /home/justadomainwhereOLDmagentoISinstalled/public_html

With the current configuration you requested, the site appears broken.

and it was.

After a lot of back and forth, I asked them to edit the file

/etc/apache2/apache2.conf

Modify 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> 

They applied this requested configuration, however, this only made the application inaccessible.

Then they fixed it and when I asked HOW, they replied:

*At the beginning of the ticket, the mapping for your multi-site configuration was placed in both .htaccess file:

/home/justadomainwhereOLDmagentoISinstalled/public_html/pub/.htaccess /home/justadomainwhereOLDmagentoISinstalled/public_html/.htaccess

which we believe was one of the main causes for the issue. After leaving the rules only in the mentioned .htaccess and purging the Magento cache, the issue was indeed resolved.*

I wonder if it had to do with the way THEY configured /etc/httpd/conf/httpd.conf to begin with.

Any which way, THIS IS NOW FIXED - thanks to everyone who took the time to read this post and ponder what the cause/solution might be!

12
  • It would help if you could define "crashes" more specifically. HTTP 5XX error? HTTP 4XX error? HTTP errors only for CSS/JS files? I would also run this query in the database and make sure that all of the URLs are as expected: SELECT * FROM core_config_data WHERE path LIKE 'web/%_url' ORDER BY scope ASC;
    – jiheison
    Oct 10, 2021 at 21:15
  • @jiheison I have updated the original post - it now loads the Main Website's header and footer and background color with the following Error: 404 You might want to check that URL again or head over to our homepage.
    – Allysin
    Oct 11, 2021 at 18:42
  • Is [magento root path]/pub configured as the root directory for the vhost that corresponds to the domain that you are testing?
    – jiheison
    Oct 11, 2021 at 20:05
  • @jiheison How do I check that? It loaded fine before I changed the domain of the Main store and Main store front. In fact, I believe if I change the Main store front domain back to the justadomainwhereNEWmagentoISinstalled.com domain and keep the Main Store domain as actualproductionstoredomain.com, the Admin panel will load. The drawback to this is that then the Main store loads correctly on the actualproductionstoredomain.com domain but as soon as you click on a product, the URL will change to justadomainwhereNEWmagentoISinstalled.com. Any help on this will be very much appreciated. :-(
    – Allysin
    Oct 11, 2021 at 20:16
  • @jiheison I see what you mean now. I've added the actualproductionstoredomain.com into 'Domains' in cPanel. It says: Document Root = /public_html Should I change that to /public_html/pub ? My Magento is installed in /public_html. Also - is 'Domain' the right place to put this into or should I use Addon Domains or Aliases in cPanel?
    – Allysin
    Oct 11, 2021 at 21:15

1 Answer 1

1
+250

This is the best tutorial on how to properly set up Multiple Stores and Domains with Magento 2. It covers everything needed:

How to Setup Magento 2 with Multiple Stores and Domains

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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