Two Copies of Magento Installation on Localhost

2019-09-06 09:15发布

问题:

My goal is two have two versions of Magento installed in my Sites/ folder. One is the current version we are using (1.12), and the other is the upgraded version (1.14). There are several reasons why I need to do this.

Another developer upgraded Magento and sent over the site files, which I put in Sites/magento2.dev, and I also have the working original in Sites/magento1.dev.

I created a separate database, imported the dump from the upgraded version, and put this in the local.xml file for magento2:

<host><![CDATA[localhost]]></host>
<username><![CDATA[root]]></username>
<password><![CDATA[mypassword]]></password>
<dbname><![CDATA[mydatabase]]></dbname>
<active>1</active>

Then I went into the database and changed the core_config_data base urls for our three websites to mimic what I had set on the older version:

http://www.magento2.dev/
http://www.magento2-b.dev/
http://www.magento2-c.dev/

I updated my /etc/apache2/extra/httpd-vhosts.conf file:

# Virtual Hosts
# Note: You also need to edit the hosts file /private/etc/hosts
NameVirtualHost *:80
#magento1.dev / Magento 1.12
<VirtualHost *:80>
ServerAdmin myuser@mywebsite.com
DocumentRoot "/Users/myuser/Sites/magento1.dev"
<Directory "/Users/myuser/Sites/magento1.dev">
Options Indexes FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
ServerName magento1.dev
ErrorLog "/private/var/log/apache2/magento1.dev-error_log"
CustomLog "/private/var/log/apache2/magento1.dev-access_log" common
</VirtualHost>

#magento-b.dev / Magento 1.12
<VirtualHost *:80>
ServerAdmin myuser@mywebsite.com
DocumentRoot "/Users/myuser/Sites/magento1.dev"
ServerName magento1-b.dev
ErrorLog "/private/var/log/apache2/magento1-b.dev-error_log"
CustomLog "/private/var/log/apache2/magento1-b.dev-access_log" common
</VirtualHost>

#magento-c.dev / Magento 1.12
<VirtualHost *:80>
ServerAdmin myuser@mywebsite.com
DocumentRoot "/Users/myuser/Sites/magento1.dev"
ServerName magento1-c.dev
ErrorLog "/private/var/log/apache2/magento1-c.dev-error_log"
CustomLog "/private/var/log/apache2/magento1-c.dev-access_log" common
</VirtualHost>

#magento2.dev / Magento 1.14
<VirtualHost *:80>
ServerAdmin myuser@mywebsite.com
DocumentRoot "/Users/myuser/Sites/magento2.dev"
ServerName magento2.dev
ErrorLog "/private/var/log/apache2/magento2.dev-error_log"
CustomLog "/private/var/log/apache2/magento2.dev-access_log" common
</VirtualHost>

#magento2-b.dev / Magento 1.14
<VirtualHost *:80>
ServerAdmin myuser@mywebsite.com
DocumentRoot "/Users/myuser/Sites/magento2.dev"
ServerName magento2-b.dev
ErrorLog "/private/var/log/apache2/magento2-b.dev-error_log"
CustomLog "/private/var/log/apache2/magento2-b.dev-access_log" common
</VirtualHost>

#magento2-c.dev / Magento 1.14
<VirtualHost *:80>
ServerAdmin myuser@mywebsite.com
DocumentRoot "/Users/myuser/Sites/magento2.dev"
ServerName magento2-c.dev
ErrorLog "/private/var/log/apache2/magento2-c.dev-error_log"
CustomLog "/private/var/log/apache2/magento2-c.dev-access_log" common
</VirtualHost>  

I updated my /private/etc/hosts file:

127.0.0.1       localhost
127.0.0.1       www.magento1.dev
127.0.0.1       www.magento1-b.dev
127.0.0.1       www.magento1-c.dev
127.0.0.1       www.magento2.dev
127.0.0.1       www.magento2-b.dev
127.0.0.1       www.magento2-c.dev

I have tried a few other iterations of this (adding trailing slashes, http, www, etc), always with the same result. When I go to www.magento2.dev, www.magento2-b.dev, or www.magento2-c.dev, I get a slightly different version (fonts broken) of my old version of the site (www.magento1.dev), but with the new URL. Logging into the backend, I can see that it is 1.12, and the URL changes to the older version. Basically it seems like I just made three new local domains for the old version of the primary store website.

I've restarted apache and mysql about a million times.

I should also note that if I got to http://localhost/~myuser/magento2.dev, I get a 403 notice.

What am I missing here?

回答1:

First, match the ServerName in your httpd.conf with the corresponding domains you added in your local hosts file. Also try viewing the logs i realtime when you visit any of the urls in your browser.

$ cd /private/var/log/apache2/
$ tail -f magento1-b.dev-error_log

You can also tail all the log files at once to see which vhost gets a hit when visiting any of the localhost host file domains in your browser.

$ cd /private/var/log/apache2/
$ tail -f *.log

Also, test if the vhost's are working by creating a simple .php file in Magento root and visit it with your browser. For example, create /Users/myuser/Sites/magento1.dev/info.php with the following content:

<?php
echo gethostname() . "\n";
echo getcwd() . "\n";
?>

Visit http://www.magento1.dev/info.php Visit http://www.magento2.dev/info.php

Verify local hosts file (Mac)

127.0.0.1       www.magento1.dev
127.0.0.1       www.magento1-b.dev
127.0.0.1       www.magento1-c.dev
127.0.0.1       www.magento2.dev
127.0.0.1       www.magento2-b.dev
127.0.0.1       www.magento2-c.dev

Otherwise, use this as a minimum httpd.conf (with matching ServerName. This currently works in my local MAMP environment.)

NameVirtualHost *

<VirtualHost *>
DocumentRoot "/Users/myuser/Sites/magento1.dev"
ServerName www.magento1.dev
ErrorLog "/Users/myuser/Sites/magento1.dev-error_log"
CustomLog "/Users/myuser/Sites/magento1.dev-access_log" common
</VirtualHost>

<VirtualHost *>
DocumentRoot "/Users/myuser/Sites/magento1.dev"
ServerName www.magento1-b.dev
ErrorLog "/Users/myuser/Sites/magento1-b.dev-error_log"
CustomLog "/Users/myuser/Sites/magento1-b.dev-access_log" common
</VirtualHost>

<VirtualHost *>
DocumentRoot "/Users/myuser/Sites/magento1.dev"
ServerName www.magento1-c.dev
ErrorLog "/Users/myuser/Sites/magento1-c.dev-error_log"
CustomLog "/Users/myuser/Sites/magento1-c.dev-access_log" common
</VirtualHost>


<VirtualHost *>
DocumentRoot "/Users/myuser/Sites/magento2.dev"
ServerName www.magento2.dev
ErrorLog "/Users/myuser/Sites/magento2.dev-error_log"
CustomLog "/Users/myuser/Sites/magento2.dev-access_log" common
</VirtualHost>

<VirtualHost *>
DocumentRoot "/Users/myuser/Sites/magento2.dev"
ServerName www.magento2-b.dev
ErrorLog "/Users/myuser/Sites/magento2-b.dev-error_log"
CustomLog "/Users/myuser/Sites/magento2-b.dev-access_log" common
</VirtualHost>

<VirtualHost *>
DocumentRoot "/Users/myuser/Sites/magento2.dev"
ServerName www.magento2-c.dev
ErrorLog "/Users/myuser/Sites/magento2-c.dev-error_log"
CustomLog "/Users/myuser/Sites/magento2-c.dev-access_log" common
</VirtualHost>

If you have working vhost's, then check the index.php & .htaccess files within each copy of Magento for any hard-coded domain or store code occurrences.