Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

MySql connection with cgi-bin hack
 
ttwhy
Member
 
Avatar
Total Posts:  70
Joined:  2008-01-27
 

Hi,

ive tried to install magento on a german provider which does not support PHP 5.2 yet. For that ive used the PHP5.2 cgi-bin hack
for some people maybe this code is helpful (the part for the cgi-bin hack for the .htaccess file):

Action php5-cgi /cgi-bin/php5-cgi
AddHandler php5
-cgi .php .phtml
AddType application
/x-httpd-php5-cgi .php .phtml .php3 .php4 .php5

[EDIT]
and maybe something “unlucky”. When using the PEAR update, the .htaccess you modified will be overwritten and in the next step the webservice has the old (not modified) .htaccess file.
[/EDIT]

So the installation keept on and i was able to come to install/wizard/config/
Ive tried a lot of connection possibilties and allways got server errors.
With Host localhost i get :

SQLSTATE[HY000] [2002] Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)

Possibilties ive tried:
- localhost
- localhost:3306
- 127.0.0.1:3306
- 127.0.0.1
- Servers IP with and without port (but thats a low issus… that shouldnt work until my providers will allow it)

Maybe this is because of “permission restrictions” from my provider (asked him about that, but until now -> no answer)
Phpmyadmin works fine with localhost and so it must be because of the cgi-bin hack (phpmyadmin doesnt use the cgi-bin php).

Is there any possibility without the help from my provider to get rid of this error?

 
Magento Community Magento Community
Magento Community
Magento Community
 
Moshe
Magento Team
 
Avatar
Total Posts:  1770
Joined:  2007-08-07
Los Angeles
 

In your mysql console get result for:

show variables like 'socket';

Enter the result string into “Host” field

 
Magento Community Magento Community
Magento Community
Magento Community
 
ttwhy
Member
 
Avatar
Total Posts:  70
Joined:  2008-01-27
 
Moshe - 27 January 2008 06:40 AM

In your mysql console get result for:

show variables like 'socket';

Enter the result string into “Host” field

From PHPMyAdmin:

Variable_name     Value (tableheader)
socket              /var/run/mysqld/mysqld.sock

Return from Magento if i enter “/var/run/mysqld/mysqld.sock” as host

SQLSTATE[HY000] [2002] Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)

its thems to be not overwriting the differend “socket file”. (see attached file… ignore user wink doesnt work on the server wink )

Image Attachments
magentoscreenshot.png
 
Magento Community Magento Community
Magento Community
Magento Community
 
ttwhy
Member
 
Avatar
Total Posts:  70
Joined:  2008-01-27
 

new version same problem.

the installer doesnt take the /var/run/mysqld/mysqld.sock and falls back to defauls.

 
Magento Community Magento Community
Magento Community
Magento Community
 
ttwhy
Member
 
Avatar
Total Posts:  70
Joined:  2008-01-27
 

tried to trace the problem a bit more and its thems to go more in the frameworks you use.

from lib/Zend/Db/Adapter/Pdo/Abstract.php

$this->_connection = new PDO(
                
$dsn,
                
$this->_config['username'],
                
$this->_config['password'],
                
$this->_config['driver_options']
            
);

Until there everthings fine, but $this->_config[’driver_options’] is a not set.
The Config sets $this->_config[’unix_socket’]…

i dont know the correct order for the data of this PDO Object. Maybe you can help me with that.

 
Magento Community Magento Community
Magento Community
Magento Community
 
Moshe
Magento Team
 
Avatar
Total Posts:  1770
Joined:  2007-08-07
Los Angeles
 

@ttwhy: It’s working in our tests.

See this link, it’s the correct way of specifying the socket for ZF PDO DB adapter:
http://framework.zend.com/issues/browse/ZF-1914

the ‘unix_socket’ parameter is used in Zend_Db_Adapter_Pdo_Abstract::_dsn method to generate connection DSN.

You might want to change socket value in mysql configuration (my.cnf under [mysqld] section), just make sure this won’t break other applications.

 
Magento Community Magento Community
Magento Community
Magento Community
 
ttwhy
Member
 
Avatar
Total Posts:  70
Joined:  2008-01-27
 

found the problem and hardcodet the solution (dirty)

file which need to be modified:
/html/lib/Zend/Db/Adapter/Pdo/Abstract.php

abstract class Zend_Db_Adapter_Pdo_Abstract extends Zend_Db_Adapter_Abstract
{

    
/**
     * Creates a PDO DSN for the adapter from $this->_config settings.
     *
     * @return string
     */
    
protected function _dsn() {
/*
...
// normal code here. 
...
*/
 // use all remaining parts in the DSN
        
foreach ($dsn as $key => $val{
            $dsn[$key] 
"$key=$val";
        
}
        
//output thems to be wrong
        //return $this->_pdoType . ':' . implode(';', $dsn); <--------- this has been disabled (cant review it)
    
return 'mysql:unix_socket=/var/run/mysqld/mysqld.sock;dbname=GET_YOUR_DB_IN_DATABASE';
   
}

so at least i just changed the return value. sry that i didnt fixed the problem on the correct way (to get rid of this problem) but the steps whent on and so i missed to fix it rly.

maybe someone with the same issus will get rid of the problem. shouldnt be the hardest.

Thanks for your help with this issuas.

 
Magento Community Magento Community
Magento Community
Magento Community
 
ttwhy
Member
 
Avatar
Total Posts:  70
Joined:  2008-01-27
 

new version and the dirty hack doesnt work anymore (tried it the same why like befor, but now i still get errors).

With the original Abstract.php:

exception 'Zend_Db_Adapter_Exception' with message 'SQLSTATE[HY000] [2002] Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)' in /home/www/web7397/html/lib/Zend/Db/Adapter/Pdo/Abstract.php:137
Stack trace:
#0 /home/www/web7397/html/lib/Varien/Db/Adapter/Pdo/Mysql.php(91): Zend_Db_Adapter_Pdo_Abstract->_connect()
#1 /home/www/web7397/html/lib/Zend/Db/Adapter/Abstract.php(390): Varien_Db_Adapter_Pdo_Mysql->_connect()
#2 /home/www/web7397/html/lib/Zend/Db/Adapter/Pdo/Abstract.php(212): Zend_Db_Adapter_Abstract->query('
SET NAMES utf8', Array)
#3 /home/www/web7397/html/app/code/core/Mage/Core/Model/Resource/Type/Db/Pdo/Mysql.php(39): Zend_Db_Adapter_Pdo_Abstract->query('
SET NAMES utf8')
#4 /home/www/web7397/html/app/code/core/Mage/Core/Model/Resource.php(71): Mage_Core_Model_Resource_Type_Db_Pdo_Mysql->getConnection(Object(Mage_Core_Model_Config_Element))
#5 /home/www/web7397/html/app/code/core/Mage/Core/Model/Resource/Setup.php(52): Mage_Core_Model_Resource->getConnection('
core_setup')
#6 /home/www/web7397/html/app/code/core/Mage/Core/Model/Resource/Setup.php(99): Mage_Core_Model_Resource_Setup->__construct('
core_setup')
#7 /home/www/web7397/html/app/code/core/Mage/Core/Model/Config.php(181): Mage_Core_Model_Resource_Setup::applyAllUpdates()
#8 /home/www/web7397/html/app/code/core/Mage/Core/Model/App.php(174): Mage_Core_Model_Config->init(NULL)
#9 /home/www/web7397/html/app/Mage.php(367): Mage_Core_Model_App->init('
base', NULL)
#10 /home/www/web7397/html/app/Mage.php(387): Mage::app('
base', NULL)
#11 /home/www/web7397/html/index.php(28): Mage::run('
base')
#12 {main}

print_r ($dsn) befor it will be returned

Array
(
    
[model] => model=mysql4
    [initStatements] 
=> initStatements=SET NAMES utf8
    [type] 
=> type=pdo_mysql
    [host] 
=> host=
    
[dbname] => dbname=XXXXXXX
    [active] 
=> active=1
    [unix_socket] 
=> unix_socket=/var/run/mysqld/mysqld.sock
)

with implode

mysql:model=mysql4;initStatements=SET NAMES utf8;type=pdo_mysql;host=;dbname=XXXXXX;active=1;unix_socket=/var/run/mysqld/mysqld.sock

so everthings should be allright, but in the endeffect it allways switch back to /var/lib/mysql/mysql.sock instead of /var/run/mysqld/mysqld.sock

is there maybe some “cached” config, or something which let it allways fall back to defaults? (maybe because of the cgi-bin?

XXX= Dbname ... removed it wink you never know who is out there wink

 
Magento Community Magento Community
Magento Community
Magento Community
 
ttwhy
Member
 
Avatar
Total Posts:  70
Joined:  2008-01-27
 

okay ... fixed ->

$dsn['model''model=unix_socket';
    unset(
$dsn['host']);

dont know why it still tries to use the host instead of the unix socket. maybe its my fault.

 
Magento Community Magento Community
Magento Community
Magento Community
 
timpea
Member
 
Total Posts:  68
Joined:  2007-09-03
 

@ttwhy, big thanks, I was having the same problem, using the php-cgi which was pointing at the wrong mysql path, trying to set this in the installation wizard was ignored, using your dirty hack got me up and running on my test setup.

Cheers
Tim

 
Magento Community Magento Community
Magento Community
Magento Community
 
Jaclin
Jr. Member
 
Total Posts:  2
Joined:  2009-08-31
 

I tried 127.0.0.1:3306 and my problems were over.
Thank you all.

Jac

 
Magento Community Magento Community
Magento Community
Magento Community
 
satishkpal
Jr. Member
 
Total Posts:  2
Joined:  2010-07-26
 

leave host name blank.I have tried this it working fine

 
Magento Community Magento Community
Magento Community
Magento Community
 
e-mike
Jr. Member
 
Total Posts:  1
Joined:  2011-01-19
 

Without hacking any files or symlinking mysql.sock to other directories, the solutions for me was simple:

1) Replace localhost with 127.0.0.1

or

2) Replace localhost with socket location

<default_setup>
                <
connection>
                    <
host><![CDATA[/Applications/AMPPS/mysql/tmp/mysql.sock]]></host>
                    <
username><![CDATA[username]]></username>
                    <
password><![CDATA[password]]></password>
                    <
dbname><![CDATA[dbname]]></dbname>
                    <
initStatements><![CDATA[SET NAMES utf8]]></initStatements>
                    <
model><![CDATA[mysql4]]></model>
                    <
type><![CDATA[pdo_mysql]]></type>
                    <
pdoType><![CDATA[]]></pdoType>
                    <
active>1</active>
                </
connection>
            </
default_setup>

or:

3) Add unix_socket with socket location:

<default_setup>
                <
connection>
                    <
host><![CDATA[localhost]]></host>
                    <
unix_socket><![CDATA[/Applications/AMPPS/mysql/tmp/mysql.sock]]></unix_socket>
                    <
username><![CDATA[username]]></username>
                    <
password><![CDATA[password]]></password>
                    <
dbname><![CDATA[dbname]]></dbname>
                    <
initStatements><![CDATA[SET NAMES utf8]]></initStatements>
                    <
model><![CDATA[mysql4]]></model>
                    <
type><![CDATA[pdo_mysql]]></type>
                    <
pdoType><![CDATA[]]></pdoType>
                    <
active>1</active>
                </
connection>
            </
default_setup>

For MAMP: /Applications/MAMP/tmp/mysql/mysql.sock

Else: $ locate sock | grep socket

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top