Patrick's playground

Random thoughts, problems and solutions

SQLSTATE[HY000] [2003] Can’t connect to MySQL server

A while ago I was in a project which had separate CentOS web server and database servers. I had whitelisted the IP addresses we were using so the machines could reach each other, but all other connections were dropped. One would expect that to be enough, but my requests returned me 'SQLSTATE[HY000] [2003] Can't connect to MySQL server'. Apparently SE Linux didn't want me to connect yet.

How can it be? Did I misconfigure the firewall?

In short: no I didn't. I wrote a script which was using PDO for its database connection from PHP to MySQL. At first the script was working and connecting fine. After accessing a web page that was using the script, the error appeared. At first I thought a configuration error in the firewall had to be the issue. While thinking back of what I did there was one difference: I tested the script on the command line. On the CLI the script worked, so I assumed the script to be working in a web environment as well. However, this is a different sapi!
It took me a while to find out that the problem was caused by SE Linux. I searched for a while before finding this post: https://www.drupal.org/node/1124234
It refers to this article: http://googolflex.com/?p=482

Solving it

In short: SE Linux is blocking network connections.

Please don't

The author of the googolflex blog set

SELINUX=enforcing

to

SELINUX=disabled

in 

/etc/selinux/config 

or to issue a command 

sudo setenforce 0

Please do

However, I would advice to not disable SE Linux and just issue the commands
setsebool httpd_can_network_connect_db 1
setsebool -P httpd_can_network_connect 1
Disabling SE Linux should be your last resort, not your first.

Monitoring Apache with Supervisord

Monitoring is great. Especially if it works and you don't have to take care of restarting the services yourself. Supervisord can make your life a little bit easier by doing this for you. It can monitor the processes you want on your server and (re)start them for you if they are not started. That is, if you play by its rules.
I was completely new to Supervisor (although I knew what it does) and my goal was to monitor the apache2 process on my server. In doing that I encountered some problems. This blogpost shows the summary of my journey and concludes with a working configuration.

Read More

My tools around my development tools

The most frequent asked questions I encounter on, for example, LinkedIn start with "What is the best..". "What application is the best for doing x?" etc.

And every time I comment on such a discussion, my answer contains the message "There is no tool that is the best. There's no tool to rule them all". What matters is that the tool works for you.

This blogpost is not about code packages I use, but about the tools I use to organize myself, to keep my data/thoughts/code in sync to minimize the time loss on stuff I want to do good, but quick so I can maximize the time to do what I love most: write code! This post is about what works for me and, most important, WHY it works for me! If you have any additions to my list or awesome stuff that must be mentioned, feel free to add them in the comments below this post.

Read More

CloudVPS object store beta introduction

Lately I’ve been playing around with the CloudVPS ObjectStore, which is currently in beta phase. This blogpost shows the options of this ObjectStore in a practical way and concludes with a summary of commands you can use yourself to interact with it and some ideas. For this post, I assume you are familiar with cURL, REST and HTTP headers.

Read More

Daycamp 4 Developers #4 Business 101.

Last Saturday the fourth edition of daycamp 4 developers took place. This time’s topic was all about freelancing, entrepreneurship and taking care of your career-life-balance.  Next to some familiar speakers there were also experts from other fields completing the line-up. This blogposts is a summary of the things I’ve learned during this conference, I’ve mixed them up with my own experiences and opinion, of which this blogpost is a result.

Read More

Practical: creating a REST application with Silex

Okay, you’ve read LornaJane’s blogpost series on REST, you’ve attended the Techademy Silex/REST workshop to hear Stefan Koopmanschap talk about Silex and Joshua Thijssen about REST, seen the post of Dave Marshall on REST so what now?

Try and create a REST example application with Silex of course! This blogpost describes my steps creating this example application from front to back.

The order in which I’ve written down and done things is not pre-defined. There are multiple orders to achieve the same result. This is just the way I did it.

Read More

PHP SPL data structure: SplFixedArray

PHP 5.3 introduced some new data structures. The talk of Jurriën Stutterheim on PFCongres 2011 on SPL structures and their performance triggered me to have a closer look at the performance of these structures. I was kind of fooled by two comments on the PHP.net page, so it was time to find out myself.

Read More

Using SimpleAdapter for populating simple_list_item_2 with Strings

I don't know it it's my searching skills which are fading or the lack of examples, but I wasn't able to find a simple example on how to use the simple_list_item_2 which is built into Android. I've used some custom layouts to establish the same result, and sometimes some extras (display an icon on the right for example). However, now I wanted to use the built-in feature, but had to search quite some time. If you experience the same, hopefully this post will save you time.

Read More

Custom checkboxes for CheckBoxPreferences on Android

For an App I'm writing I need to use custom checkboxes in a PreferenceScreen. I want to use the CheckboxPreferences as it's designed for that. Many searches lead to StackOverflow, but caused me a stack overflow as well as they didn't work. In this (short) post I outline my findings and provide a working solution step by step.

Read More

Propel and the zero date issue

Today I was unpleasantly surprised by a change in behavior when upgrading Propel from version 1.5.4 to 1.6. I frequently use zero dates in MySQL ('0000-00-00') and these dates are affected by the upgrade. As it was deployment time I had to find a solution quickly. This post outlines what the problem is and what I did to solve it.

Read More

Page 1 of 5

Powered by WordPress & Theme by Anders Norén