1

I need to copy webstore to my local environment to do some work on it before I apply these changes on the production version. I viewed multiple tutorials how to move a magento store to your local host and here is a list of things that I did:

  1. copied the files from the server to a folder called myfolder in mamp/projects/myfolder as well as exported the database

  2. edited the app/etc/local.xml for my local environment, these are the lines I have edited

    <host><![CDATA[localhost]]></host>
    <username><![CDATA[root]]></username>
    <password><![CDATA[root]]></password>
    <dbname><![CDATA[my_db_name]]></dbname>
    
  3. In phpmyadmin inside of my database I went to the m_core_config_data table and edited web/unsecture/base_url and web/secture/base_url I used http://localhost/projects/myfolder/

  4. Edited the permissions for folders: var; media and etc within app folder
  5. I have also cleared the var/cache folder

However, Magento returns an error. I cannot access neither front end nor back end. What can I do to start running the website locally?

The log file states:

a:4:{i:0;s:106:"SQLSTATE[HY000] [2002] Can't connect to local MySQL server through socket 'localhost/projects/myfolder' (2)";i:1;s:2832:"#0 /Users/Anton/Documents/mamp/projects/myfolder/lib/Zend/Db/Adapter/Pdo/Mysql.php(96): Zend_Db_Adapter_Pdo_Abstract->_connect()
#1 /Users/Anton/Documents/mamp/myfolder/myfolder/lib/Varien/Db/Adapter/Pdo/Mysql.php(313): Zend_Db_Adapter_Pdo_Mysql->_connect()
#2 /Users/Anton/Documents/mamp/projects/myfolder/lib/Zend/Db/Adapter/Abstract.php(459): Varien_Db_Adapter_Pdo_Mysql->_connect()
#3 /Users/Anton/Documents/mamp/projects/myfolder/lib/Zend/Db/Adapter/Pdo/Abstract.php(238): Zend_Db_Adapter_Abstract->query('SET NAMES utf8', Array)
#4 /Users/Anton/Documents/mamp/projects/myfolder/lib/Varien/Db/Adapter/Pdo/Mysql.php(419): Zend_Db_Adapter_Pdo_Abstract->query('SET NAMES utf8', Array)
#5 /Users/Anton/Documents/mamp/projects/myfolder/app/code/core/Mage/Core/Model/Resource.php(169): Varien_Db_Adapter_Pdo_Mysql->query('SET NAMES utf8')
#6 /Users/Anton/Documents/mamp/projects/myfolder/app/code/core/Mage/Core/Model/Resource.php(110): Mage_Core_Model_Resource->_newConnection('pdo_mysql', Object(Mage_Core_Model_Config_Element))
#7 /Users/Anton/Documents/mamp/projects/myfolder/app/code/core/Mage/Core/Model/Resource/Db/Abstract.php(320): Mage_Core_Model_Resource->getConnection('core_write')
#8 /Users/Anton/Documents/mamp/projects/myfolder/app/code/core/Mage/Core/Model/Resource/Db/Abstract.php(350): Mage_Core_Model_Resource_Db_Abstract->_getConnection('write')
#9 /Users/Anton/Documents/mamp/projects/myfolder/app/code/core/Mage/Core/Model/Resource/Db/Abstract.php(335): Mage_Core_Model_Resource_Db_Abstract->_getWriteAdapter()
#10 /Users/Anton/Documents/mamp/projects/myfolder/app/code/core/Mage/Core/Model/Resource/Cache.php(53): Mage_Core_Model_Resource_Db_Abstract->_getReadAdapter()
#11 /Users/Anton/Documents/mamp/projects/myfolder/app/code/core/Mage/Core/Model/Cache.php(455): Mage_Core_Model_Resource_Cache->getAllOptions()
#12 /Users/Anton/Documents/mamp/projects/myfolder/app/code/core/Mage/Core/Model/Cache.php(497): Mage_Core_Model_Cache->_initOptions()
#13 /Users/Anton/Documents/mamp/projects/myfolder/app/code/core/Mage/Core/Model/App.php(1183): Mage_Core_Model_Cache->canUse('config')
#14 /Users/Anton/Documents/mamp/projects/myfolder/app/code/core/Mage/Core/Model/Config.php(414): Mage_Core_Model_App->useCache('config')
#15 /Users/Anton/Documents/mamp/projects/myfolder/app/code/core/Mage/Core/Model/Config.php(294): Mage_Core_Model_Config->_canUseCacheForInit()
#16 /Users/Anton/Documents/mamp/projects/myfolder/app/code/core/Mage/Core/Model/App.php(413): Mage_Core_Model_Config->loadModulesCache()
#17 /Users/Anton/Documents/mamp/projects/myfolder/app/code/core/Mage/Core/Model/App.php(343): Mage_Core_Model_App->_initModules()
#18 /Users/Anton/Documents/mamp/projects/myfolder/app/Mage.php(683): Mage_Core_Model_App->run(Array)
#19 /Users/Anton/Documents/mamp/projects/myfolder/index.php(87): Mage::run('', 'store')
#20 {main}";s:3:"url";s:20:"/projects/myfolder/cp";s:11:"script_name";s:27:"/projects/myfolder/index.php";}

Error log record number: 565449617885 And magento ver 1.7.0.2

After restarting MAMP several times and clearing the var folder I no longer see those errors. However, I am facing a new problem, when I try to access the website locally, I type localhost/projects/myfolder/ and it redirects to the live version with www.webstore.com in the address bar. After some looking up time I thought it must be the rewrite base in .htaccess file. I ended up replacing it with one from a fresh magento, but it still redirects me to the live version. I cannot seem to find the solution online

  • AntK,please goto youMagentoDir/var/report/ and open the file 565449617885.let me know the issue – Amit Bera Apr 1 '15 at 15:53
  • I have added the log to the question. – AntK Apr 1 '15 at 16:02
  • Your mysql connection not work.please ckd – Amit Bera Apr 1 '15 at 16:06
  • ckd? Sorry, tried googling, but cannot figure out what is it – AntK Apr 1 '15 at 16:09
  • 1
    I have and it does. I am running a more recent version of magento in another folder which works just fine – AntK Apr 7 '15 at 14:02
1

Antk, there are well documented & somewhat odd interactions between MySQL and PHP on unix operating systems where both sockets and TCP connections are possible via localhost (detailed discussion here) and very specific quirky behaviors of the PHP PDO Library relating to how MySQL client connections that are initiated via the sockets implementation (detailed discussion here)....

BUT

tl;dr : Don't waste your time figuring out how to resolve the idiosyncracies between your local OS version, an older version of Magento, and the specific release of the MySQL client / server in your MAMP stack. It's easier to just ditch MAMP and grab a VM and use it to develop locally, plus it's more like the production environment you're going to run your code in when you deploy it.

OPTION 1 > Ditch MAMP for a VM Dev Environment

Here are the quickest ways to ditch MAMP and go with VM development for your version of Magento :

  1. FAST & SIMPLE: Grabbing a BitNami pre-built Magento 1.7.0.2 stack ready to run on boot on an Ubuntu VM (you will need virtualbox (free) or some other virtualization system like Parallels or VMWare Fusion). Although this is the fast route, there are some quirks with how BitNami lays out the filesystem and configures apache & php that will likely differ from your production environment, but it will work when you start it up because it's completely self-contained.

  2. SLOWER but CONTROLLED : Installing vagrant and virtualbox using a VM for your local development via one of the many scripts that will provision vagrant & set up Magento for you in your VM. This gives you the most flexibility to configure it the way you need, but requires that you do the configuration after the basic provisioning is done via vagrant and may take more time to complete.

I'm also not sure if phpMyAdmin is included in that vagrant file, but is IS included in the BitNami image if you prefer using it vs connecting to the Server via a MySQL Workbench or another SQL Editor.

If you're feeling like an adventure (or inflicting some self torture), these two options walk you through the best route to troubleshoot your specific error and get to the bottom of what's happening with your MAMP install:

-

OPTION 2 > Modify your php.ini file

As the first link states, you can force the PDO library to use sockets if you know what the name of the socket is:

(either by looking in the php.ini file or by using: phpmyadmin or the console (or construct it in mysql or mysqli)...to run the following query (anything but PDO):

show variables like 'socket'; //as mentioned by symcbean

THEN, in the PDO connection string, change it to use the socket instead of a hostname:

> $dbc = new
> PDO("mysql:unix_socket=/var/run/mysqld/mysqld.sock;dbname=$DBName",
> $User, $Password, array(PDO::ATTR_PERSISTENT => true));   // using
> persistent connections

OPTION 3 > Update to your app/etc/local.xml file.

Change localhost to 127.0.0.1 or to the IP address of your Mac and the PDO library should be able to initiate a connection from the MySQL client => Server.

Updated config below:

<host><![CDATA[127.0.0.1]]></host>
<username><![CDATA[root]]></username>
<password><![CDATA[root]]></password>
<dbname><![CDATA[my_db_name]]></dbname>

or

<host><![CDATA[192.168.0.1]]></host>
<username><![CDATA[root]]></username>
<password><![CDATA[root]]></password>
<dbname><![CDATA[my_db_name]]></dbname>

These might work, but requires directly modifying the PDO driver in the core files, which goes against best the recommended best practices of Magento development OR implement an overrided driver that is only used on your local development instance (seems like a lot of work to get a dev environment working if you ask me...)

  • 1
    Thank you for the answer, but even after changing the local host to either of ip addresses it returns an error saying SQLSTATE[HY000] [2003] Can't connect to MySQL server on '127.0.0.1' or the other ip address. – AntK Apr 7 '15 at 14:00
  • Can you connect to the server via a standard mysql client? – Bryan 'BJ' Hoffpauir Jr. Apr 7 '15 at 17:49
0

After taking time off I got back to this issue. I extracted the database once more and dropped off the log table content which noticeably reduced the size of the sql file. Dropped the content of my local database and inserted the tables using the new sql file. After reediting the base urls I could access the development version of the site on my machine.

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.