I've been trying to install CiviCRM on fresh WordPress 4.7.3 installations on my managed server, but I keep having database connection problems.
When I try to install CiviCRM 4.7.17, the CiviCRM installer can't locate the database or validate any of the database details.
The MySQL server "Does the server exist?" line returns this message: *Can't find the a MySQL server on 'localhost:/tmp/mysql.sock'.: Unknown MySQL server host 'localhost:/tmp/mysql.sock' (2)**
I am using exactly the same database information --MySQL server at localhost:/tmp/mysql.sock/-- that I used to successfully install WordPress.
I've also tried installing CiviCRM 4.6.0 and 4.6.26 on separate fresh installations of WordPress 4.7.3. In both of these attempts, the CiviCRM installer locates the database just fine (using localhost:/tmp/mysql.sock as the MySQL server), and says that the installation has completed successfully after I click "Install."
However, when I click on the CiviCRM tab in both instances, this error appears, and CiviCRM fails to open:
Array ( [callback] => Array ( [0] => CRM_Core_Error [1] => simpleHandler )
[code] => -24
[message] => DB Error: connect failed
[mode] => 16
[debug_info] => [nativecode=Can't connect to local MySQL server through socket '/set-in-php.ini' (2)]
[type] => DB_Error
[user_info] => [nativecode=Can't connect to local MySQL server through socket '/set-in-php.ini' (2)]
[to_string] => [db_error: message="DB Error: connect failed" code=-24 mode=callback callback=CRM_Core_Error::simpleHandler prefix="" info=" [nativecode=Can't connect to local MySQL server through socket '/set-in-php.ini' (2)]"]
)
I've contacted my managed server's administrators about this, but they think this is CiviCRM-specific problem and haven't been able to help.
We're using PHP 5.6.30. Our other server information is as follows:
Server: Localhost via UNIX socket Server type: MySQL Server version: 5.5.27 - MySQL Community Server (GPL) Protocol version: 10 User: root@localhost
Apache/2.2.32 (Unix) mod_ssl/2.2.32 OpenSSL/1.0.1e-fips PHP/5.6.30 mod_pubcookie/3.3.4a mod_uwa/3.2.1 Database client version: libmysql - 5.5.18 PHP extension: mysqli
This PHP warning pops up in our error logs every time I try to access a CiviCRM installation unsuccessfully:
PHP Warning: mysqli_real_escape_string() expects parameter 1 to be mysqli, boolean given in /data/www/_our____website_/wp-content/plugins/civicrm/civicrm/install/index.php on line 1256
Line 1256 in index.php is: global $installDirPath;
I'm not sure what's causing this problem, and I appreciate any insights you might have.
Per Jon G's note below: the civicrm.settings.php files that are generated in the installation appear to be standard.
The default settings files that are generated return the following database lines:
if (!defined('CIVICRM_UF_DSN')) { define( 'CIVICRM_UF_DSN' , 'mysql://username:password@localhost:/tmp/mysql.sock/civicrm-again?new_link=true'); }
...which look standard. In the past, I've had to manually edit these lines to accommodate the non-standard localhost location (localhost:/tmp/mysql.sock) by inserting tcp( ), like this:
if (!defined('CIVICRM_UF_DSN')) { define( 'CIVICRM_UF_DSN' , 'mysql://username:password@tcp(**localhost:/tmp/mysql.sock)**/civicrm-again?new_link=true'); }
After that --in the past-- CiviCRM worked fine.
Now, neither the default version nor the adjusted tcp() one allows CiviCRM to initialize in my successful 4.6 installations. (I've also tried inputting just "localhost" in place of "localhost:/tmp/mysql.sock" here, but that returns the same error.)
Finally, the MySQL server is running on the standard port, 3306.
Also, I should mention two other things: I installed CiviCRM in 4.6.0 on our server successfully in the past, and this version was working fine till I tried to upgrade to 4.7.17. Since running the upgrade script, clicking on the CiviCRM tab returns an HTTP error 500.
Also, for this and the other 4.6 installations, I adjusted a line in the installation code in modules/civicrm/install/civicrm.php, adding an additional tcp(...) around the server location, per this thread: https://forum.civicrm.org/index.php?topic=12500.0;prev_next=prev#new
The revised line looks like this: $dsn = "mysql://{$config['mysql']['username']}:{$config['mysql']['password']}@tcp({$config['mysql']['server']})/{$config['mysql']['database']}?new_link=true";
UPDATE: I'm still not able to install CiviCRM 4.7.18, but I was able to upgrade my previous database to 4.7.22 by adjusting the civicrm.settings.php file. I got it to work by adding @tcp( ) to civicrm.settings.php (as mentioned above), changing "localhost" to 127.0.0.1, and specifying the port as :3306. The lines I changed were:
define( 'CIVICRM_UF_DSN'; 'mysql://user:password@tcp(127.0.0.1:3306)/database?new_link=true'); define('CIVICRM_DSN', 'mysql://user:password@tcp(127.0.0.1:3306)/database?new_link=true'); define('CIVICRM_DB_CACHE_HOST', '127.0.0.1'); define('CIVICRM_DB_CACHE_PORT', 3306 );
After running the upgrade script again, the upgrade worked!