{"id":471,"date":"2016-03-17T00:08:20","date_gmt":"2016-03-16T16:08:20","guid":{"rendered":"https:\/\/www.techcoil.com\/blog\/?p=471"},"modified":"2018-09-04T22:57:06","modified_gmt":"2018-09-04T14:57:06","slug":"how-i-solve-the-database-connection-error-from-my-wordpress-instance-which-is-hosted-on-the-default-php-fpm-server-in-mac-os-x-el-capitan","status":"publish","type":"post","link":"https:\/\/www.techcoil.com\/blog\/how-i-solve-the-database-connection-error-from-my-wordpress-instance-which-is-hosted-on-the-default-php-fpm-server-in-mac-os-x-el-capitan\/","title":{"rendered":"How I solved the database connection error from my WordPress installation which is hosted on the default PHP FPM server in Mac OS X EL Capitan"},"content":{"rendered":"<p>I was trying to setup a WordPress instance with the built-in PHP-FPM server on my Mac OS X el Capitan. After applying the relevant <a href=\"https:\/\/codex.wordpress.org\/Nginx\" title=\"Nginx configurations for WordPress installations\" target=\"_blank\">Nginx configurations for WordPress installations<\/a>, I had been able to run the php codes from my WordPress instance. <\/p>\n<p>However, when I tried to run the <a href=\"https:\/\/codex.wordpress.org\/Installing_WordPress\" title=\"WordPress installation guide\" target=\"_blank\">WordPress install script<\/a>, I was slapped with the following message in my browser:<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\nError establishing a database connection\r\nThis either means that the username and password information in your wp-config.php file is incorrect or we can\u2019t contact the database server at localhost. This could mean your host\u2019s database server is down.\r\n\r\nAre you sure you have the correct username and password?\r\nAre you sure that you have typed the correct hostname?\r\nAre you sure that the database server is running?\r\nIf you\u2019re unsure what these terms mean you should probably contact your host. If you still need help you can always visit the WordPress Support Forums.\r\n<\/pre>\n<p>This post documents how I solved the database connection error coming from my WordPress installation which is hosted on the default PHP FPM server that comes with my OS X El Capitan.<\/p>\n<h3>Why was my WordPress installation not being able to connect to MySQL database server on my Mac OS X EL Capitan<\/h3>\n<p>When my WordPress setup was not able to connect to my MySQL database server, the first thing that I did was to check the relevant MySQL settings that my php binary had taken. <\/p>\n<p>To do so, I ran the following command in my Terminal program:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nphp -i | grep 'mysql'\r\n<\/pre>\n<p>From the output of this call, I get to know the following:<\/p>\n<ol>\n<li>MySQL had been enabled.<\/li>\n<li>The default socket that php would use to talk to a MySQL database server was <code>\/var\/mysql\/mysql.sock<\/code><\/li>\n<\/ol>\n<p>With that, I went on to check whether the <code>\/var\/mysql\/mysql.sock<\/code> file exists on my file system. It turned out that <code>\/var\/mysql\/mysql.sock<\/code> does not exist on my file system, which was probably why my php binary was not able to connect to my MySQL database server for my WordPress setup.<\/p>\n<h3>Figuring out where MySQL database server had placed the mysql.sock file<\/h3>\n<p>Since I could use the mysql command to access and create a database instance for my WordPress installation, there should be a mysql.sock file lying somewhere on my computer. To do so, I ran the following command in my Terminal program:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nmysql_config --socket\r\n<\/pre>\n<p>This command tells me that MySQL database server had placed the <code>mysql.sock<\/code> file in the \/tmp folder. Since my php binary was being configured to read the mysql.sock file from another location, it could never been able to connect to the MySQL database server on my Mac. <\/p>\n<h3>Finding out where is the php.ini file that my php binary is loading configurations from<\/h3>\n<p>To find out the location of the php.ini file that is responsible for my php configurations, I ran the following command in my Terminal program:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nphp --ini\r\n<\/pre>\n<p>This command gave me the following output:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nConfiguration File (php.ini) Path: \/etc\r\nLoaded Configuration File:         (none)\r\nScan for additional .ini files in: \/Library\/Server\/Web\/Config\/php\r\nAdditional .ini files parsed:      (none)\r\n<\/pre>\n<p>This tells me that there was <strong>no php.ini<\/strong> file that was being processed by my php binary. <\/p>\n<h3>Creating the php.ini file and configuring the default mysql socket for my default php binary<\/h3>\n<p>To be able to get my php binary to take in my configurations, I will need to supply it with a <code>php.ini<\/code> file in the <code>\/etc<\/code> folder. Luckily for me, there was a <code>php.ini.default<\/code> file in the <code>\/etc<\/code> folder which I can reference from.<\/p>\n<p>I went on to create the <code>php.ini<\/code> file from the <code>php.ini.default<\/code> file by running the following command in my Terminal program:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nsudo cp php.ini.default php.ini\r\n<\/pre>\n<p>I then fired up my text editor and look for the line containing the <code>mysql.default_socket<\/code> variable and change it to the following:<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\nmysql.default_socket = \/tmp\/mysql.sock\r\n<\/pre>\n<p>After I had saved the changes made to the <code>php.ini<\/code> file, I ran the following command again to get my php binary to take in the configurations that I had created:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nphp --ini\r\n<\/pre>\n<p>This time, the command returned me the following result:<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\nLoaded Configuration File:         \/etc\/php.ini\r\nScan for additional .ini files in: \/Library\/Server\/Web\/Config\/php\r\nAdditional .ini files parsed:      (none)\r\n<\/pre>\n<p>This meant that the <code>php.ini<\/code> file that I had created was read by the php binary.<\/p>\n<p>I then restart my PHP-FPM server so that it could take the new configurations.<\/p>\n<p>After the PHP-FPM server had restarted, my WordPress installation was then able to allow me to continue on to the <a href=\"https:\/\/codex.wordpress.org\/Installing_WordPress#Famous_5-Minute_Install\" title=\"WordPress codex on the Famous 5-Minute Install process\" target=\"_blank\">famous five-minute WordPress installation process<\/a>. Database connection error from WordPress solved!<\/p>\n\n      <ul id=\"social-sharing-buttons-list\">\n        <li class=\"facebook\">\n          <a href=\"https:\/\/www.facebook.com\/sharer\/sharer.php?u=https%3A%2F%2Fwp.me%2Fp245TQ-7B\" target=\"_blank\" role=\"button\" rel=\"nofollow\">\n            <img decoding=\"async\" src=\"\/ph\/img\/3rd-party\/social-icons\/Facebook.png\" alt=\"Facebook icon\"> Share\n          <\/a>\n        <\/li>\n        <li class=\"twitter\">\n          <a href=\"https:\/\/twitter.com\/intent\/tweet?text=&url=https%3A%2F%2Fwp.me%2Fp245TQ-7B&via=Techcoil_com\" target=\"_blank\" role=\"button\" rel=\"nofollow\">\n          <img decoding=\"async\" src=\"\/ph\/img\/3rd-party\/social-icons\/Twitter.png\" alt=\"Twitter icon\"> Tweet\n          <\/a>\n        <\/li>\n        <li class=\"linkedin\">\n          <a href=\"https:\/\/www.linkedin.com\/shareArticle?mini=1&title=&url=https%3A%2F%2Fwp.me%2Fp245TQ-7B&source=https:\/\/www.techcoil.com\" target=\"_blank\" role=\"button\" rel=\"nofollow\">\n          <img decoding=\"async\" src=\"\/ph\/img\/3rd-party\/social-icons\/linkedin.png\" alt=\"Linkedin icon\"> Share\n          <\/a>\n        <\/li>\n        <li class=\"pinterest\">\n          <a href=\"https:\/\/pinterest.com\/pin\/create\/button\/?url=https%3A%2F%2Fwww.techcoil.com%2Fblog%2Fwp-json%2Fwp%2Fv2%2Fposts%2F471&description=\" class=\"pin-it-button\" target=\"_blank\" role=\"button\" rel=\"nofollow\" count-layout=\"horizontal\">\n          <img decoding=\"async\" src=\"\/ph\/img\/3rd-party\/social-icons\/Pinterest.png\" alt=\"Pinterest icon\"> Save\n          <\/a>\n        <\/li>\n      <\/ul>\n    ","protected":false},"excerpt":{"rendered":"<p>I was trying to setup a WordPress instance with the built-in PHP-FPM server on my Mac OS X el Capitan. After applying the relevant <a href=\"https:\/\/codex.wordpress.org\/Nginx\" title=\"Nginx configurations for WordPress installations\" target=\"_blank\">Nginx configurations for WordPress installations<\/a>, I had been able to run the php codes from my WordPress instance. <\/p>\n<p>However, when I tried to run the <a href=\"https:\/\/codex.wordpress.org\/Installing_WordPress\" title=\"WordPress installation guide\" target=\"_blank\">WordPress install script<\/a>, my WordPress setup complained that it was unable to connect to the database server.<\/p>\n","protected":false},"author":1,"featured_media":1217,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"advanced_seo_description":"","jetpack_seo_html_title":"","jetpack_seo_noindex":false,"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"footnotes":""},"categories":[4],"tags":[235,9,13,195,5],"jetpack_featured_media_url":"https:\/\/www.techcoil.com\/blog\/wp-content\/uploads\/WordPress-logo-on-black-background.gif","jetpack_shortlink":"https:\/\/wp.me\/p245TQ-7B","jetpack-related-posts":[],"jetpack_likes_enabled":true,"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.techcoil.com\/blog\/wp-json\/wp\/v2\/posts\/471"}],"collection":[{"href":"https:\/\/www.techcoil.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.techcoil.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.techcoil.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.techcoil.com\/blog\/wp-json\/wp\/v2\/comments?post=471"}],"version-history":[{"count":0,"href":"https:\/\/www.techcoil.com\/blog\/wp-json\/wp\/v2\/posts\/471\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.techcoil.com\/blog\/wp-json\/wp\/v2\/media\/1217"}],"wp:attachment":[{"href":"https:\/\/www.techcoil.com\/blog\/wp-json\/wp\/v2\/media?parent=471"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.techcoil.com\/blog\/wp-json\/wp\/v2\/categories?post=471"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.techcoil.com\/blog\/wp-json\/wp\/v2\/tags?post=471"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}