Codigo Logo

Based Zend frameworks' issues on MAMP

Many systems built in Zend can have issues with Mac's "AMP" platforms like MAMP or XAMPP.

A very popular eCommerce solution based in Zend is Magento, and same PHP to MySQL connections problems can happen when we are trying to run this platform in MAMP.

I've just download a Magento shop's backup from the production server (Debian) to my laptop to test some changes. My system is OS X Yosemite and I am using MAMP. You can imagine how big was my surprise when I was finishing the configuration of the files and database and I saw this:

For security reasons Magento doesn't display the errors on screen (you can change this if needed, take a look at this tutorial ) , so I had to go to var/report and open the file 1100685804233. These were the errors:

a:4:{i:0;s:48:"SQLSTATE[HY000] [2002] No such file or directory";i:1;s:2652:"#0 /test_server/lib/Zend/Db/Adapter/Pdo/Mysql.php(96): Zend_Db_Adapter_Pdo_Abstract->_connect()
#1 /test_server/lib/Varien/Db/Adapter/Pdo/Mysql.php(313): Zend_Db_Adapter_Pdo_Mysql->_connect()
#2 /test_server/lib/Zend/Db/Adapter/Abstract.php(459): Varien_Db_Adapter_Pdo_Mysql->_connect()

It seems that something wrong was happening with PDO socket, which is used by Zend. Probably the path was not correct. How we can be sure?. Well, first we need to know what is the true socket path, and we can use MySQL console for that. To open MySQL shell in MAMP I simply wrote:

$ /Applications/MAMP/Library/bin/mysql 

And then:

mysql> show variables like '%sock%';

and here was the information that I was looking for:

| Variable_name | Value                                   |
| socket        | /Applications/MAMP/tmp/mysql/mysql.sock |
1 row in set (0.01 sec)

So at this moment I knew where the sockets were placed. How about PHP? Did it was correctly configured?. Let's see the

mysql.default_socket	     /Applications/MAMP/tmp/mysql/mysql.sock	
mysqli.default_socket	     /Applications/MAMP/tmp/mysql/mysql.sock	
pdo_mysql.default_socket     /tmp/mysql.sock	

It seems that pdo_mysql.default_socket had a bad path (probably because PDO was never configurated, so it had default options activated), and this is the reason Zend wasn't working. The easiest way to change it was editing php.ini. I could find the filepath in same

Configuration File (php.ini) Path 	/Applications/MAMP/bin/php/php5.6.6/conf 

I opened the file and added these lines:

; PDO MySQL socket (required by Zend framework).
pdo_mysql.default_socket = /Applications/MAMP/tmp/mysql/mysql.sock

Then I rebooted MAMP, and Magento worked!


You can check if your server meets the requirements for Magento using the Compatibility Check script.


Based Zend frameworks' issues on MAMP