Symfony 2.3 to 2.8, 502 Bad Gateway

I recently had a problem while upgrading a Symfony 2.3 project to 2.8. A lot of pages started giving me “502 Bad Gateway” errors for no obvious reason but only when being accessed through ngrok. After some searching and testing I noticed that if I turned off debugging things worked just fine. The dev.log was full of deprecation messages so I fixed a couple of them to make the log more readable. This surprisingly fixed some of the pages.

After even more digging I eventually came across this:

After some testing with both Chrome and Firefox I realized that the culprit was ngrok which seems to have a limit on response headers and with all the deprecation messages the application was overflowing that limit. Since my team isn’t using server side debugging with Chrome I disabled the chromephp and firephp log handlers in app/config/config_dev.php and everything started working again.

Variables in Apache’s conf files

Apache 2.4 added a seemingly little known feature, setting and using variables in config files. It took me some time to find any information about this but it is in the documentation. It’s simple enough to use, at the beginning of your file you define the variable with Define, then you can access it with ${variable}. An example:

Symfony 2 development on Fedora 21

There are some packages that are needed in PHP for developing Symfony 2 applications on Fedora 21.

To install what is needed:

This will resolve and install some dependencies such as php-xml and php-pdo. It will even install the apache webserver (httpd). MariaDB is installed by default in at least the KDE spin so there’s no need to install that specifically and php-mysql would resolve to install mariadb any way.

It’s also good to edit some .ini files after this. In /etc/php.ini it’s a good idea to set the timezone variable:

In /etc/php.d/15-xdebug.ini the following will help with debugging from NetBeans:

To simplify access to logs it could be an idea to run the httpd server as your own user, in /etc/httpd/conf/httpd.conf change the user setting, leave the group as is:

To start and enable the services needed:


Fedora 21 in VirtualBox

Just installed Fedora 21 as a guest on a Windows 7. Some weird problems getting everything to work but a couple of things to remember:

  • To get full screen working properly make sure you check “Auto resize Guest Display”, in the View menu of a running VM.
  • Chromium based browsers (Chrome, Opera and Vivaldi) have been having some problems with mouse integration in VirtualBox, at least on linux guests. A workaround is to disable mouse integration if you can’t select any text by dragging in one of these browsers (Host+I).


Legacy code in PHP

If you are a PHP programmer you have probably had your share of exposure to old spaghetti code that doesn’t seem to follow any rules or patterns other than “I need this now”. I’ve worked on several such projects and I wish I had had a resource like Paul M. Jones’ Modernizing Legacy Applications In PHP at my disposal when trying to get through the code in these projects. The book shows several simple steps to make sense of and clean up legacy code. It’s well worth the money if you haven’t gone through a major refactoring process on code that someone else has written.

Disclaimer: I’m in no way affiliated with the author or publisher other than being a happy customer.

Doctrine 2 and Symfony2, Using INDEX BY in Query Builder

It can be useful to get the resulting array from a query using the object id as key. This can be achieved in PDO by using the PDO::FETCH_NAMED and PDO::FETCH_NUM fetch styles and Doctrine offers this as well. When using the query builder all you have to do is to use the third parameter on the “from” part:


The third parameter to the ‘from’ method tells doctrine to use the id property on the User object as the array key when returning the results. In most cases you’ll want the indexBy column to have a unique constraint as the results may be unpredictable otherwise.

Setting up software RAID-5 on CentOS 6.5

Note: I’ve moved everything to a new server running CentOS 7 and everything works without any problems with the same instructions. The RAID-5 array works on the new server without any modifications.

The hard disk in my home server had a minor hick up recently reminding me of my sloppy backup policy. The error was big enough to force me to make some changes to the server so I decided to start from scratch. The server had previously had several jobs to do, it was a router/gateway, a dhcp server, a dns server and on top of that a virtual machine host running KVM. I had already moved all services other than the VM host to another devices so getting a clean start looked like a good idea. Continue reading


I’ve been thinking about setting up a blog like this for a while and now I finally think it’s time to start. What’s this all about then? Programming, PHP mostly at first but other topics will show up as well.

So who am I? I’ll post an about page in a couple of days.