Report inadequate content

Simple Varnish Installation

The first thing to do is to make sure your application is passing the headers properly. At least you'll need this (in PHP):

// Let's say Varnish caches for 12 hours:
$cache_max_age = 60*60*12;
header( "Cache-Control: public, must-revalidate, max-age=0, s-maxage=$cache_max_age" ); 

Varnish installation (CentOS/Redhat):
RPM taken from https://www.varnish-cache.org/installation/redhat

rpm --nosignature -i http://repo.varnish-cache.org/redhat/varnish-3.0/el5/noarch/varnish-release-3.0-1.noarch.rpm

After adding the package:

yum install varnish

If you have another Linux see in the link, is more or less the same.

Now Varnish is installed. What we want to do next is to configure Apache to listen in another port and let the port 80 for Varnish. Varnish will be the one requesting to Apache the html and saving it in the memory for later accesses.

We will use as example the port 8080 for Apache. The first thing is to tell Varnish, where Apache will be listening to:

vi /etc/varnish/default.vcl

# Change the port to 8080, like this. Leave the rest of file as is:
backend default {
  .host = "127.0.0.1";
  .port = "8080";
}

Then we have to change Varnish to make it listen in port 80:

vi /etc/sysconfig/varnish

# Change VARNISH_LISTEN_PORT variable to 80, like this:
VARNISH_LISTEN_PORT=80

And now in the Apache settings make it listen to 8080:

vi /etc/httpd/conf/httpd.conf
# Change the Listen variable to 8080:

Listen 8080

If you use Named Virtualhosts using the port number (e.g: You declare them with NameVirtualHost *:80) you'll need to change them to 8080 too. I usually store my virtual configurations under this file, use yours:

vi /etc/httpd/conf.d/virtual.conf

# You can replace all the 80 by 8080 easily with vi with (take care there aren't other things changed):
:%s/80/8080/g

And now hold your breathe. Stop both services and start them again to make changes effective:

/etc/init.d/httpd stop
/etc/init.d/varnish stop
/etc/init.d/httpd start
/etc/init.d/varnish start

Your application should be served by Varnish now. Check in the "Network" tab of your Google Chrome or Firefox that the headers are properly passed:

 TAGS:

{
}

Smarty: Concatenation of variables inside block parameters

In Smarty sometimes you need to concatenate 2 variables and pass it as a single variable inside a block. But the placeholder won't allow any expected PHP syntax

You want to accomplish something like:

{assign var="MYVAR" value=$variable1.$variable2}

But, the dot in smarty is for array access, so, what about...

{assign var="MYVAR" value=$variable1+$variable2}

No. It does not work either. Ah! Let's try a modifier:

{assign var="MYVAR" value=$variable1|cat:$variable2}

Aha! That's the solution!

Dedicated to my friend Sambel, no pun intended!

Mantener la sesión abierta en iTerm (keep-alive)

Similarmente a como explicamos sobre cómo mantener la sesión activa en Putty, si queremos dejar la terminal abierta y que no se nos cierre con iTerm cada vez que vamos a hacer un café, comer, o liberar la próstata, hay que seguir estos sencillos pasos:

  • Abrir Bookmarks -> Manage Profiles
  • Desplegar Terminal Profiles y seleccionar Default
  • Marcar When idle, sends ASCII code

El valor de esta casilla por defecto es 0, pero lo podéis cambiar a cualquier otro código ASCII. Yo lo he dejado tal cual.

 -

How to setup a remote development environment over SFTP (working copy)

This article explains how to setup the server and client to work with a remote working copy.

To properly understand this post you should have read the previous post, When to setup a remote development environment over SFTP (working copy).

To have the enviroment up and running you must setup once the server, and then apply the configuration of the client in every developer machine. But the client side is very simple and requires no installation at all.

Here's how:

Read more
{
}

When to setup a remote development environment over SFTP (working copy)

When a programmer has a local copy of the code and an environment fully functional where the web can be tested before going live, we usually call it a working copy.

The action of moving/copying/putting this work in the final live server (a.k.a production server/environment) is called the deploy action.

There are many ways of having a working copy up and running. We, the key stroker maniacs, use to work more or less with one of the following working copy configurations:

  • No working copy. The one who enters via SSH and uses the editor vi. Yeah!
  • Edit via FTP/SFTP with an editor installed in the local machine. No working copy, the return.
  • Local web server. Usually a pre-built LAMP solution, such as MAMP or XAMPP. Valid until you need to add 2 or 3 more services like Memcached, Sphinx, Solr, MongoDB, Redis or anything like that, or the Virtual host configuration starts to change over and over.
  • A web server in your LAN. Several users using a machine with all the services configured, having their own running copy. Different DocumentRoot per user.
  • The Virtual machine lover, who runs a VirtualBox or VMWare with a full linux installed and exports and shares the appliance with colleagues if necessary.
  • The Vagrant chef, who has an automated system to deliver pre-configured environments to any number of developers using VirtualBoxes underneath.

In this post, I am proposing something different, it has the smell and aroma of the early 90's development, but still, a good solution when you have a middle team (2-20) where people don't want to be bothered with constant database changes and service tunning. It is the private remote working copy over SFTP. Keep reading...

Read more

Putty keep-alive session (mantener activa la sesión)

Cuando utilizamos putty como cliente ssh muchas veces nos encontramos que, tras un tiempo de inactividad, la sesión se cierra.

Putty cuenta con una opción que nos permite envíar paquestes nulos, de forma automática, cada periodo definido de tiempo. De esa manera, putty, mantendrá la sesión activa.

Antes de activar esta opción hay que tener en cuenta que, el sistema de cancelación automática de una conexión no es más que una medida de seguridad por lo que, en caso de conectarnos a sistemas "sensibles", no conviene activar el keep-alive.

  TAGS:

 

 TAGS:

Git log mejorado. Color y ramas dibujadas

 -

Hace unos días me llegó un tweet de Dani con uno de esos regalos que hace de tanto en cuanto, que se acuerda de los amigos y te manda algo interesante. En este caso era un artículo en inglés de Filipe Kiss donde nos enseñaba como convertir el git log de terminal en algo con cara y ojos (hacer clic en imágen).

He modificado  el comando original para que muestre el email en vez de los nombres, que tiene problemas en algunas terminales con los acentos.

Podéis probarlo tal que así:

git log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)%Creset' --abbrev-commit

Y para crear un alias permanente y llamarlo siempre con git lg las siguientes veces hay que crear el alias:

git config --global alias.lg "log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)%Creset' --abbrev-commit"

Aún usando clientes gráficos como SourceTree (muy recomendable) el log en terminal sigue siendo lo más práctico para copiar y pegar en ficheros de texto para el control de cambios.

Inventazo!

Mysql: Llenar tabla con datos aleatorios (de una lista)

En alguna ocasión nos hemos encontrado con la necesidad de actualizar / insertar registors de una tabla con elementos aleatoris a partir de una lista.

Esta operación es especialmente útil cuando queremos crear datos "dummy" para entornos de desarrollo.

El ejemplo de este post es para MySql:

UPDATE files f SET license_type = (SELECT ELT(0.5 + RAND() * 2, 'Free', 'Try' ) )