Instalar XCache en CentOS 5

Breves instrucciones para compilar y instalar Xcache en Centos 5. No tiene mayor dificultad.

# wget http://xcache.lighttpd.net/pub/Releases/1.2.2/xcache-1.2.2.tar.gz
# tar -zxf xcache-1.2.2.tar.gz
# cd xcache
# phpize
# ./configure –enable-xcache
# make
# su
# make install

Instala las extesiones compartidas de php : /usr/lib/php/modules

# cat xcache.ini >> /etc/php.ini

Editamos php.ini para instalar Xcache como extension

# joe /etc/php.ini

zend_extension = /usr/lib/php/modules/xcache.so

La configuración del xcache está explicada en comentarios en el propio php.ini, pero hay cosas relevantes como el xcache.count, relativo al número de procesadores de nuestro sistema. Averiguamos el número de procesadores y luego editamos el php.ini

# cat /proc/cpuinfo |grep -c processor
xcache.count = 4

Las demás variables se pueden configurar fácilmente leyendo la documentación. Ahora podemos crear un archivo php con la función phpinfo ( ) y moverlo a nuestro directorio root para comprobar que Xcache funciona correctamente. No olvidemos reiniciar Apache!

# /etc/init.d/httpd restart

Instalar el Admin

Para instalar el admin primero creamos un fichero php como el siguiente para obtener el password encriptado en md5

echo md5("password");

Copiamos el resultado en php.ini, en la variable xcache.admin.pass

xcache.admin.pass = "password_en_md5"

Ahora copiamos el directorio web de Xcache a nuestro document root de apache


# cp -R admin/* /var/www/midominio.com/admin/.

Reiniciamos Apache. Accedemos al admin, introduciendo user y password.

Sobre el Error Segmentation Fault

Algo que me sucedió en la instalación de Xcache en Centos 5. Al comprobar los logs de Apache comprobé que había numerosos errores de Segmentation Fault.

# php -v
Segmentation fault

# cat /var/log/httpd/error_log
[Thu Oct 02 13:43:39 2008] [notice] child pid 15978 exit signal Segmentation fault (11)
[Thu Oct 02 13:43:42 2008] [notice] child pid 15979 exit signal Segmentation fault (11)
[Thu Oct 02 13:43:50 2008] [notice] child pid 15980 exit signal Segmentation fault (11)
[Thu Oct 02 13:44:08 2008] [notice] child pid 15981 exit signal Segmentation fault (11)
[Thu Oct 02 13:44:12 2008] [notice] child pid 15982 exit signal Segmentation fault (11)
[Thu Oct 02 13:44:33 2008] [notice] child pid 15983 exit signal Segmentation fault (11)

Para evitarlo hacemos lo siguiente


# rm /dev/zero
# mknod /dev/zero char 1 5
# /etc/init.d/httpd restart

Otro problema relativo. Aunque creemos el fichero /dev/zero, por una limitación (no se si de php.ini o el propio kernel) puede que el valor de cache que asignamos a xcache.size es superior a lo que puede guardar y eso provoca el siguiente error:

xcache /dev/zero: No space left on device

Para arreglar, hemos de reducir el valor asignado a xcache.size, por ejemplo empezando por 8M y reiniciando apache. No deberíamos ver más ese error ni Segmentation Faults en el apache. Y si los hay, deberían ser por otro motivo que no fuera Xcache.

Instalar plugins en WordPress automáticamente – TIP

Para instalar plugins en WordPress automáticamente y sin necesidad de tener que introducir datos de nuestro servidor ftp, podemos hacerlo de la siguiente manera.

1 .- Agregamos el siguiente código php al final de nuestro archivo wp-config.php

if(is_admin()) {
   add_filter('filesystem_method', create_function('$a', 'return "direct";' ));
   define( 'FS_CHMOD_DIR', 0751 );
}

2 .-  Por último damos permisos de escritura a los siguientes directorios:

/wp-content/plugins
/wp-content/themes
/wp-content/upgrade

Ahora cuando instalemos un plugin o tema en nuestro WordPress no necesitaremos agregar ningún dato y se instalarán automáticamente.

Funciones a deshabilitar en php.ini – Tips para securizar php

Y es que, cada vez se ven mas destrozos a causa de las webs mal hechas (o poco actualizadas) en php . Que si postnuke, que si phpnuke, phpbb, mybb y un larguisimo etc. Ya que esto es un dolor de cabeza para cualquier sysadmin, algo a tener en cuenta es el deshabilitar ciertas funciones de php en el php.ini, y el que las quiera.. que las habilite en el .htaccess de su virtualhost bajo su responsabilidad, no? Empezamos:

Editamos fichero de configuración de PHP php.ini

#vi /etc/php.ini

buscamos la linea que contiene disable_functions. Posiblemente tenga un ; delante, que sirve para inutilizarla. Eliminamos el ; y dejamos la linea de esta forma:

disable_functions = system, exec, popen, passthru, shell_exec, proc_close, proc_get_status, proc_nice, proc_open, proc_terminate

Asi, nos cargamos unas cuantas funciones peligrosas que a mas de uno le han dejado sin dormir.

Por otro lado, es de esperar el estar atentos a cosas como el safe_mode, allow_url_fopen y demas… pero creo que eso ya lo puse en otro post anterior 🙂

Instalar Memcached en CentOS 5.3

Memcached is a generic purpose distributed high performance memory object caching system to use in speeding up dynamic database driven websites by caching data and objects in memory to reduce the amount the database needs to be read.

Memcached was originally developed by Danga Interactive for LiveJournal but is now used by many popular and large community driven websites like Slashdot, Wikipedia, SourceForge, GameFAQs, Facebook, Digg, Fotolog, Kayak and like. It is being distributed under a permissive free software licence. Know more about who all are using memcached

Things to consider before Installing memcached.

  1. First, decide how much memory you want to give memcached to use for caching.
  2. Then decide if you want to run memcached on the default port (11211) or not.
  3. Next decide if you want memcached to listen to a specific IP address if you have multiple IP addresses on your server
  4. Finally decide, what user you want to run memcached as; typically, you want to run it using Apache user so that Apache processes can access memcache data

Installation Process

1. If you don’t have rpmforge installed, follow this step.

wget http://dag.wieers.com/rpm/packages/rpmforge-release/rpmforge-release-0.3.6-1.el5.rf.i386.rpm
rpm –install rpmforge-release-0.3.6-1.el5.rf.i386.rpm
yum install –enablerepo=rpmforge memcached

2. Start memcached.

memcached -d -m 512 -l 127.0.0.1 -p 11211 -u nobody

The “-m SIZE” is the flag for setting the memory requirements in MBs. Once this cache is filled memcache will just start to overwrite with newer content. Please experiment with this setting to find what works best for you.

3. Install PHP extension.

wget http://pecl.php.net/get/memcache-2.2.5.tgz

4. Extract tar file.

tar -xvf memcache-2.2.5.tgz

5. Open the directory.

cd memcache-2.2.5

6. Install the memchaced PHP extension.

phpize && ./configure –enable-memcache && make

7.  Copy the extension.

cp modules/memcache.so {PHP extension directory}

8. Edit your php.ini and add the following line.

extension=memcache.so

9. Last is restart your webserver.

10. If you check your server using a phpinfo page you should now see a MemCache section on the page. You can now fully use the MemCache functionality in your PHP.

memcached pre-requissites

yum -y install libevent libevent-devel

How to make memcached run automatically when you restart your server?. Add this line to rc.local

#!/bin/sh
echo “# Start memcached” >> /etc/rc.local
echo “/usr/local/bin/memcached -d -m 1024 -u httpd -l 127.0.0.1″ >> /etc/rc.local

How to have a multiple memcached server.

Create LocalSettings.php file and this line.

$wgMainCacheType = CACHE_MEMCACHED;
$wgParserCacheType = CACHE_MEMCACHED; # optional
$wgMessageCacheType = CACHE_MEMCACHED; # optional
$wgMemCachedServers = array( “127.0.0.1:11211″ );

$wgSessionsInMemcached = true; # optional

To use multiple servers (physically separate boxes or multiple caches on one machine on a large-memory x86 box), just add more items to the array. To increase the weight of a server (say, because it has twice the memory of the others and you want to spread usage evenly), make its entry a subarray:

$wgMemCachedServers = array(“127.0.0.1:11211″, # one gig on this box
array(“127.0.0.1:11211″, 2 ) # two gigs on the other box
);

Security Note:

Memcached has no security or authentication. Please ensure that your server is appropriately firewalled,
and that the port(s) used for memcached servers are not publicly accessible. Otherwise, anyone on the internet can put data into and read data from your cache.

ENJOY FRIENDS AND MAKE EASY¡¡¡¡¡¡¡¡¡¡¡