{"id":189,"date":"2021-03-29T21:26:49","date_gmt":"2021-03-29T21:26:49","guid":{"rendered":"http:\/\/blog.bp8.pl\/?p=189"},"modified":"2021-04-09T11:36:49","modified_gmt":"2021-04-09T11:36:49","slug":"azure-app-service-wordpress-database-connection-wp-config-php","status":"publish","type":"post","link":"https:\/\/blog.bp8.pl\/index.php\/2021\/03\/29\/azure-app-service-wordpress-database-connection-wp-config-php\/","title":{"rendered":"Azure App Service WordPress Database connection wp-config.php"},"content":{"rendered":"\n<p>For connect do Azure App Service MySQL in App you need to modify wp-config.php file on the top:<\/p>\n\n\n\n<pre><code>\n$connectstr_dbhost = '';\n$connectstr_dbname = '';\n$connectstr_dbusername = '';\n$connectstr_dbpassword = '';\n\nforeach ($_SERVER as $key =&gt; $value) {\n    if (strpos($key, \"MYSQLCONNSTR_localdb\") !== 0) {\n        continue;\n    }\n    \n    $connectstr_dbhost = preg_replace(\"\/^.*Data Source=(.+?);.*$\/\", \"\\\\1\", $value);\n    $connectstr_dbname = preg_replace(\"\/^.*Database=(.+?);.*$\/\", \"\\\\1\", $value);\n    $connectstr_dbusername = preg_replace(\"\/^.*User Id=(.+?);.*$\/\", \"\\\\1\", $value);\n    $connectstr_dbpassword = preg_replace(\"\/^.*Password=(.+?)$\/\", \"\\\\1\", $value);\n}\n\n\ndefine('DB_NAME', $connectstr_dbname);\n\ndefine('DB_USER', $connectstr_dbusername);\n\ndefine('DB_PASSWORD', $connectstr_dbpassword);\n\ndefine('DB_HOST', $connectstr_dbhost);\n<\/code>\n<\/pre>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>For connect do Azure App Service MySQL in App you need to modify wp-config.php file on the top: $connectstr_dbhost = &#8221;; $connectstr_dbname = &#8221;; $connectstr_dbusername = &#8221;; $connectstr_dbpassword = &#8221;; foreach ($_SERVER as $key =&gt; $value) { if (strpos($key, &#8220;MYSQLCONNSTR_localdb&#8221;) !== 0) { continue; } $connectstr_dbhost = preg_replace(&#8220;\/^.*Data Source=(.+?);.*$\/&#8221;, &#8220;\\\\1&#8221;, $value); $connectstr_dbname = preg_replace(&#8220;\/^.*Database=(.+?);.*$\/&#8221;, &#8220;\\\\1&#8221;, [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[95,94],"tags":[84,83,79,98,99],"_links":{"self":[{"href":"https:\/\/blog.bp8.pl\/index.php\/wp-json\/wp\/v2\/posts\/189"}],"collection":[{"href":"https:\/\/blog.bp8.pl\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.bp8.pl\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.bp8.pl\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.bp8.pl\/index.php\/wp-json\/wp\/v2\/comments?post=189"}],"version-history":[{"count":2,"href":"https:\/\/blog.bp8.pl\/index.php\/wp-json\/wp\/v2\/posts\/189\/revisions"}],"predecessor-version":[{"id":204,"href":"https:\/\/blog.bp8.pl\/index.php\/wp-json\/wp\/v2\/posts\/189\/revisions\/204"}],"wp:attachment":[{"href":"https:\/\/blog.bp8.pl\/index.php\/wp-json\/wp\/v2\/media?parent=189"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.bp8.pl\/index.php\/wp-json\/wp\/v2\/categories?post=189"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.bp8.pl\/index.php\/wp-json\/wp\/v2\/tags?post=189"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}