bentideswell / magento2-wordpress-integration

A free WordPress integration module for Magento 2 by FishPig.
https://fishpig.co.uk/magento/wordpress-integration/
83 stars 46 forks source link

Module does not work with MySQL over ssl. #117

Closed powelles closed 2 years ago

powelles commented 2 years ago

Currently using magento version 2.4.3-p1 and 3.8.0 of the magento2-wordpress-integration module.

When connecting to MySQL via a connection that requires SSL; Magento will work fine and wordpress will work fine but the wordpress integration breaks. I get the following error:

SQLSTATE[HY000] [3159] Connections using insecure transport are prohibited while --require_secure_transport=ON.

#1 Zend_Db_Adapter_Pdo_Mysql->_connect() called at [vendor/magento/framework/DB/Adapter/Pdo/Mysql.php:424]
#2 Magento\Framework\DB\Adapter\Pdo\Mysql->_connect() called at [vendor/magento/zendframework1/library/Zend/Db/Adapter/Abstract.php:861]
#3 Zend_Db_Adapter_Abstract->quote() called at [generated/code/Magento/Framework/DB/Adapter/Pdo/Mysql/Interceptor.php:1139]
#4 Magento\Framework\DB\Adapter\Pdo\Mysql\Interceptor->quote() called at [vendor/magento/zendframework1/library/Zend/Db/Adapter/Abstract.php:931]
#5 Zend_Db_Adapter_Abstract->quoteInto() called at [vendor/magento/framework/DB/Adapter/Pdo/Mysql.php:1529]
#6 Magento\Framework\DB\Adapter\Pdo\Mysql->quoteInto() called at [generated/code/Magento/Framework/DB/Adapter/Pdo/Mysql/Interceptor.php:257]
#7 Magento\Framework\DB\Adapter\Pdo\Mysql\Interceptor->quoteInto() called at [vendor/fishpig/magento2-wordpress-integration/App/ResourceConnection.php:93]
#8 FishPig\WordPress\App\ResourceConnection->getConnection() called at [vendor/fishpig/magento2-wordpress-integration/App/Option.php:30]
#9 FishPig\WordPress\App\Option->get() called at [vendor/fishpig/magento2-wordpress-integration/Model/OptionRepository.php:42]
#10 FishPig\WordPress\Model\OptionRepository->get() called at [vendor/fishpig/magento2-wordpress-integration/Model/OptionRepository.php:69]
#11 FishPig\WordPress\Model\OptionRepository->getUnserialized() called at [vendor/fishpig/magento2-wordpress-integration/App/Plugin.php:27]
#12 FishPig\WordPress\App\Plugin->getActivePlugins() called at [vendor/fishpig/magento2-wordpress-integration/Model/PluginManager.php:33]
#13 FishPig\WordPress\Model\PluginManager->isEnabled() called at [vendor/fishpig/magento2-wordpress-integration-yoastseo/Model/Config.php:47]
#14 FishPig\WordPress_Yoast\Model\Config->isEnabled() called at [vendor/fishpig/magento2-wordpress-integration-yoastseo/App/View/AssetProvider.php:42]
#15 FishPig\WordPress_Yoast\App\View\AssetProvider->provideAssets() called at [vendor/fishpig/magento2-wordpress-integration/App/View/AssetProvider.php:62]
#16 FishPig\WordPress\App\View\AssetProvider->provideAssets() called at [vendor/fishpig/magento2-wordpress-integration/Plugin/Magento/Framework/Controller/ResultPlugin.php:36]
#17 FishPig\WordPress\Plugin\Magento\Framework\Controller\ResultPlugin->afterRenderResult() called at [vendor/magento/framework/Interception/Interceptor.php:146]
#18 Magento\Framework\View\Result\Page\Interceptor->Magento\Framework\Interception\{closure}() called at [vendor/magento/framework/Interception/Interceptor.php:153]
#19 Magento\Framework\View\Result\Page\Interceptor->___callPlugins() called at [generated/code/Magento/Framework/View/Result/Page/Interceptor.php:95]
#20 Magento\Framework\View\Result\Page\Interceptor->renderResult() called at [vendor/magento/framework/App/Http.php:120]
#21 Magento\Framework\App\Http->launch() called at [generated/code/Magento/Framework/App/Http/Interceptor.php:23]
#22 Magento\Framework\App\Http\Interceptor->launch() called at [vendor/magento/framework/App/Bootstrap.php:264]
#23 Magento\Framework\App\Bootstrap->run() called at [pub/index.php:29]

The Magento env.php has the following lines added to the mysql configuration:

'driver_options' => [
    \PDO::MYSQL_ATTR_SSL_VERIFY_SERVER_CERT => 'false',
    \PDO::MYSQL_ATTR_SSL_CA => '/path/to/certificate.crt'
]

... and my wp-config.php has the following line:

define('MYSQL_CLIENT_FLAGS', MYSQLI_CLIENT_SSL);

I also have the magento2-wordpress-integration-yoastseo and magento2-wordpress-integration-pluginshortcodewidget modules installed if that makes a difference.

bentideswell commented 2 years ago

Hi @powelles, I have just released version 3.11.0 and this should fix this issue.

If you're using local integration mode, this should be picked up from your wp-config.php automatically as it will check for either of the following:

define('MYSQL_CLIENT_FLAGS', MYSQLI_CLIENT_SSL); define('DB_SSL', true);

If using external integration mode, a new 'SSL' field has been added to the database config options in the Magento Admin (Stores > FishPig > WordPress).

I will close this issue but if it's not resolved, please feel free to re-open.

powelles commented 2 years ago

@bentideswell Still getting the error.

The current issue is \PDO::MYSQL_ATTR_SSL_VERIFY_SERVER_CERT = false is not enough. \PDO::MYSQL_ATTR_SSL_CA cannot be blank for some reason and any value like 1 or true will make it work.

I tried adding the line $config['driver_options'][\PDO::MYSQL_ATTR_SSL_CA] = true; after vendor/fishpig/magento2-wordpress-integration/App/ResourceConnection.php:95 and everything works.

bentideswell commented 2 years ago

Thanks for the clarification. I've added this modification and released v3.11.1 and this should resolve the issue.