Alex Moreno

A Drupal Developer in London


the steps in refactoring, from the book: "Refactoring: Improving the Design of Existing Code" by Martin Fowler:

  • Identify the code in need of refactoring.
  • Have test coverage for the code.
  • Work in small steps.
  • Run your tests after each step. Code and test in quick iterations — which is much easier
  • in an interpreted language like PHP as compared with compiled languages.
  • Use refactoring to make your more readable and to improve performance.

Problems with mysql 5.5 upgrading ubuntu 12.04

After upgrading ubuntu to 12.04 i have run into problems with mysql.

First of all, if you are going to make an upgrade of "anything", the main tip is to make a backup of the databases and files which you consider important. If you didn't, maybe you still can save something, copy your /var/lib/mysql directory. If you finally have to reinstall your mysql, loosing the databases, maybe you will be lucky and copying again /var/lib/mysql directory could give your data back.

ok, the problem with mysql 5.5 and ubuntu 12.04.

The following packages have unmet dependencies:

 mysql-server : Depends: mysql-server-5.5 but it is not installed

E: Unmet dependencies. Try using -f.

Trying apt-get -f install did not solve anything. Tryied then apt-get install mysql-server-5.5

No luck, but then i saw this:

trying to overwrite '/usr/lib/mysql/plugin/', which is also in package libmysqlclient-dev

And the solution came to my mind: remove the conflictive package:

sudo dpkg -r libmysqlclient-dev

and now, 

apt-get -f install 

finally worked and did the magic. I did backups of my important databases before going to this "party", but anyway, after installing again mysql (apt-get -f intall did) everything was working fine, mysql included.

Hope it helps :-)

backups with screen and ncftp

Do you have a BIG database (or databases) in your server as a result of months and years of working? It use to be a hell to download the sql right? One solution is to get a backup ftp in your hosting provider. They are cheap, and the are going to save you a lot of time.

The trick, do the mysql backup maintenance things. Then, it's time to download your ENORMOUS .sql, but not directly to your computer.

First install screen, a usefull app to launch any console script or commad, and be able to let running while even you close your local computer.

Secondly, install ncftp, a wonderful ftp client (i love it).

And, lastly, some magic. Execute:


  1. screen
  2. put the file on the  ftp: ncftpput -v -R -u USER -p PASS FTPHOST [DIRECTORYWHERECOPY] [FILE(S)TOCOPY]


If file is too big, you can close your terminal with [CONTROL]A+D keys. But, we'll speak in another post about screen.


Drupal slow when saving nodes (content, comments, admin ...)

Drupal slow when saving nodes (content, comments, admin ...)? Maybe the problem is really simple, try to deactivate some modules that you don't use. It is common to test modules that you finally don't use in your production server. Search for them and deactivate, they take a lot of memory, even if you think you are not using them.




varnish in Drupal howto

Installing Varnish is really simple and easy to perform, and is very unlikely to give you problems with your server that any other more complex methods could give you, like using light servers or so. Probably you cannot compare both performances, but to start improving you Drupal server is a good point from where start.

Let's go:

1. Install Varnish. In Ubuntu / Debian is as easy as:

sudo apt-get install varnish

2. Install Varnish module in your Drupal:

Be sure not to make the START=no mistake.

3. Start your Varnish server: sudo /etc/init.d/varnish start

Go to admin/settings/varnish in your Drupal and select enabled.

4. Copy the Varnish Control Key which you´ll find in /etc/varnish/secret (you'll need to be root or read with "sudo vim /etc/varnish/secret").

5. Enjoy :-)

Varnish error: Not starting HTTP accelerator varnishd

Tipical mistake installing varnish accelerator:

* Not starting HTTP accelerator varnishd

Solution? so simple, edit /etc/default/varnish and look for the line:


change to


and restart:

* Starting HTTP accelerator varnishd 

Nice :-)



Buscar un fichero (recursivamente) en linux / *ix

seguro que más de una vez os habéis encontrado con este "problema". La solución, muy fácil, aunque seguro que usando el camino que probablemente habíais escogido no.

Olvida ls, para este problema necesitas la potencia de find:

find . -name 'nombreFichero.extension'


find . -name 'fichero.php'

o bien, con "wildcards"

find . -name '*.php'

De nada ;-)


eliminar una fila en una base de datos


DELETE FROM `bbdd`.`table` WHERE `crucero`.`agencia` = "AGENCIA";



Crear una nueva tabla en una base de datos con Symfony2


Añadimos una nueva entidad en CruiseHunter/CrucerosBundle/Entity/Naviera.php

actualizamos los datos:

- php app/console doctrine:generate:entities CruiseHunter/CrucerosBundle/Entity/Naviera


- php app/console doctrine:generate:entities CruiseHunter/CrucerosBundle/Entity/Naviera


Cuidado. si creamos el fichero en minúsculas, al hacer el doctrine:generate nos va a generar uno en mayúsculas, y nos dará el dichoso error de que no se puede crear dos veces una clase con el mismo nombre.

Más datos importantes, la cabecera con ORM es importante para generar la tabla automáticamente en nuestra base de datos:



 * CruiseHunter\CrucerosBundle\Entity\Naviera

 * @ORM\Table(name="naviera")

 * @ORM\Entity


class Naviera




y, por último, debemos tener una variable key, tipo id:



     * @ORM\Id

     * @ORM\Column(type="integer")

     * @ORM\GeneratedValue(strategy="AUTO")


    private $id;



Hasta aquí todo. Sólo nos queda generar la base de datos:


- php app/console doctrine:schema:update --force

Esto último lo que hace es revisar nuestro Entity, y comprobar que campos llevan un @ORM con un \Column asociado. Justamente este campo es el que el comando update usará para crear el campo en la base de datos. 

Por ejemplo:



     * @var string $descripcion

     * @ORM\Column(type="string",length=200)



    private $descripcion;


     * @var string $barco

     * @ORM\Column(type="string",length=100)


    private $barco;


     * @var string $enlace

     * @ORM\Column(type="string",length=200)


    private $enlace;


Symfony2: warning open_basedir restriction in effect

Error al subir una aplicación al sevidor en el que va a estar en producción:

symfony ErrorException: Warning: file_exists(): open_basedir restriction in effect

Después de estrujarme mucho los sesos, hize un

rm -rf app/cache/* 

y "evoilá" :-).

Después pueden salir algunos errores como:

UnexpectedValueException: The stream or file "/var/www/vhosts/*/app/logs/prod.log" could not be opened; it may be invalid or not writable.

lo que simplemente se arregla corrigiendo con los permisos adecuados los directorios que nos indique el propio mensaje, en este caso el directorio de logs:

chmod a+rw -R logs/