{"id":1183,"date":"2022-08-30T15:13:46","date_gmt":"2022-08-30T15:13:46","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2013\/11\/09\/accessing-a-database-from-cakephp-when-behind-a-proxy-server-collection-of-common-programming-errors\/"},"modified":"2022-08-30T15:13:46","modified_gmt":"2022-08-30T15:13:46","slug":"accessing-a-database-from-cakephp-when-behind-a-proxy-server-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2022\/08\/30\/accessing-a-database-from-cakephp-when-behind-a-proxy-server-collection-of-common-programming-errors\/","title":{"rendered":"Accessing a database from CakePHP when behind a proxy server-Collection of common programming errors"},"content":{"rendered":"<p>I&#8217;m working on a web application that&#8217;s using CakePHP and MySQL. Depending on the circumstances, I may be using one of two computers and I may be behind a proxy server that won&#8217;t allow me to directly modify any code on my web server. Because of this, I&#8217;ve installed XAMPP on my machines to act as a local web server, and I keep my code in an SVN respository I can still access from behind the proxy.<\/p>\n<p>With the web server, I have three places this code might be executed from (although it will ultimately only be on the web server), and since I&#8217;m in development, I&#8217;m constantly modifying the database. To make it easier on me, I want to set all three copies of this application to use the web server database so I don&#8217;t have to keep exporting and importing each time I modify the database.<\/p>\n<p>When I try to access the database, the first error I get is &#8220;Unknown MySQL server host &#8216;mysql.mywebsite.com'&#8221;. I&#8217;m assuming this is because I have to use an http proxy for all internet access, and without it, it can&#8217;t even resolve an address. Can I configure CakePHP or PHP or my local Apache or whatever to use the proxy server in order to access my database?<\/p>\n<ol>\n<li>\n<p>Neither Cake nor PHP will talk directly to MySQL. That&#8217;s handled by the low level mysql drivers. MySQL does provide their own proxy that you could try out.<\/p>\n<\/li>\n<li>\n<p>Right off the jump, you need to get your database under source control. I would recommend the CakeDC Migrations plugin.<\/p>\n<p>Getting this done will allow you to break the nightmarish cycle of phpMyAdmin importing\/exporting (or, worse yet, MySQL CLI commands). If you take the time to do this now, it will save you a lot of time and grey hair in the future. Moreover, your site&#8217;s database calls won&#8217;t be subject to the latency of leaving your local machine, much less your local network.<\/p>\n<p>If you want to keep a single, simple <code>app\/config\/database.php<\/code> configuration, you can use a fully-qualified URL for your database&#8217;s hostname, and alter your development boxes&#8217; hosts file (full path in Windows: <code>C:\\Windows\\System32\\drivers\\etc\\hosts<\/code>) to resolve the fully-qualified URL to <code>127.0.0.1<\/code>. Thus, when you&#8217;re on one of those boxes, Cake will end up connecting to your local database server, but will access the proper database server when you&#8217;ve deployed to your production web server.<\/p>\n<\/li>\n<li>\n<p>I tend to work either locally or on a hosted server. I find that using Netbeans I can work on the remote code without having to constantly upload and download.<\/p>\n<p>Whatever system you use, the fewer instances you have the better. Keeping things in sync can very rapidly become a major headache.<\/p>\n<\/li>\n<\/ol>\n<p id=\"rop\"><small>Originally posted 2013-11-09 23:37:42. <\/small><\/p>","protected":false},"excerpt":{"rendered":"<p>I&#8217;m working on a web application that&#8217;s using CakePHP and MySQL. Depending on the circumstances, I may be using one of two computers and I may be behind a proxy server that won&#8217;t allow me to directly modify any code on my web server. Because of this, I&#8217;ve installed XAMPP on my machines to act [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-1183","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/1183","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=1183"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/1183\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=1183"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=1183"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=1183"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}