systemadmin.es > LAMP y web > Instalación de un servidor LAMP V (apache con PHP y eAccelerator)

Instalación de un servidor LAMP V (apache con PHP y eAccelerator)

Anteriormente ya vimos como realizar una instalación básica de un servidor y instalar MySQL con todas sus herramientas. Hoy vamos a ver como instalar Apache con PHP y eAccelerator.

Primero de todo instalaremos el Apache, descargando la última versión:

cd /usr/local/src
yum install zlib-devel -y
wget http://mir2.ovh.net/ftp.apache.org/dist/httpd/httpd-2.2.14.tar.gz
tar xzf httpd-2.2.*.tar.gz
cd httpd-2.2.*

A continuación lo instalaremos con el mínimo de módulos que necesitemos y desactivando el autoindex por seguridad:

./configure --prefix=/usr/local/apache22 --exec-prefix=/usr/local/apache22 --enable-so --disable-autoindex --enable-rewrite --enable-deflate --enable-expires --disable-asis --disable-userdir
make && make install
mkdir -p /usr/local/supervise/apache22
useradd apache
sed -i 's%^#Include conf/extra/httpd-default.conf%Include conf/extra/httpd-default.conf%' /usr/local/apache22/conf/httpd.conf
sed -i 's%^#Include conf/extra/httpd-vhosts.conf%Include conf/extra/httpd-vhosts.conf%' /usr/local/apache22/conf/httpd.conf
sed -i 's/^User daemon/User apache/' /usr/local/apache22/conf/httpd.conf
sed -i 's/^Group daemon/Group apache/' /usr/local/apache22/conf/httpd.conf
sed -i 's%^#Include conf/extra/httpd-mpm.conf%Include conf/extra/httpd-mpm.conf%' /usr/local/apache22/conf/httpd.conf
sed -i 's%^#Include conf/extra/httpd-info.conf%Include conf/extra/httpd-info.conf%' /usr/local/apache22/conf/httpd.conf
sed -i 's/^ServerSignature On/ServerSignature Off/' /usr/local/apache22/conf/extra/httpd-default.conf
sed -i 's/^ServerTokens Full/ServerTokens Prod/' /usr/local/apache22/conf/extra/httpd-default.conf
sed -i 's/^KeepAliveTimeout 5/KeepAliveTimeout 2/' /usr/local/apache22/conf/extra/httpd-default.conf
sed -i 's/^MaxKeepAliveRequests 100/MaxKeepAliveRequests 512/' /usr/local/apache22/conf/extra/httpd-default.conf
echo "TraceEnable off" >> /usr/local/apache22/conf/httpd.conf
echo "AddOutputFilterByType DEFLATE text/html text/plain text/css text/javascript application/x-javascript text/xml" >> /usr/local/apache22/conf/httpd.conf
cat > /usr/local/apache22/conf/extra/httpd-vhosts.conf <<EOF
#
# Use name-based virtual hosting.
#
NameVirtualHost *:80

<VirtualHost *:80>
 Redirect 301 / http://www.systemadmin.es
</VirtualHost>

Include conf/extra/vhosts/*.conf
EOF
mkdir -p /usr/local/apache22/conf/extra/vhosts

A continuación instalaremos PHP:

yum install libxml2-devel -y  
yum install openssl-devel -y  
yum install libxslt-devel -y
yum install curl-devel -y  
yum install libjpeg-devel -y
yum install libmcrypt-devel -y
yum install libjpeg-devel -y
yum install libpng-devel -y
yum install libtool-ltdl-devel -y
yum install libc-client-devel -y
cd /usr/local/src
wget http://fr2.php.net/get/php-5.2.10.tar.gz/from/fr.php.net/mirror
tar xzf php-5.2.10.tar.gz
cd php-5.2.10
./configure --with-apxs2=/usr/local/apache22/bin/apxs --with-mysql=/usr/local/mysql/ --with-config-file-path=/usr/local/apache22/conf/ --with-zlib --with-gd --with-jpeg-dir=/usr/ --with-gettext --with-mcrypt --with-iconv --enable-mbstring=all --enable-mbregex --with-png-dir=/usr --with-mime-magic=/usr/share/misc/magic --with-libdir=lib64
make && make install
cp php.ini-dist /usr/local/apache22/conf/php.ini
mkdir /var/www/php/sessions -p
mkdir /var/www/php/tmp -p
chown -R apache. /var/www/php
sed -i 's%^;session.save_path = \"/tmp\"%session.save_path = \"/var/www/php/sessions\"%' /usr/local/apache22/conf/php.ini
sed -i 's%^;upload_tmp_dir =%upload_tmp_dir = /var/www/php/tmp%' /usr/local/apache22/conf/php.ini
sed -i 's#libphp5.so$#libphp5.so\n<FilesMatch \\.php\$>\nSetHandler application/x-httpd-php\n</FilesMatch>\n#' /usr/local/apache22/conf/httpd.conf
mkdir /var/www/php/sessions -p
mkdir /var/www/php/tmp -p
chown -R apache. /var/www/php
sed -i 's%^;session.save_path = \"/tmp\"%session.save_path = \"/var/www/php/sessions\"%' /usr/local/apache22/conf/php.ini
sed -i 's%^;upload_tmp_dir =%upload_tmp_dir = /var/www/php/tmp%' /usr/local/apache22/conf/php.ini
sed -i 's#libphp5.so$#libphp5.so\n<FilesMatch \\.php\$>\nSetHandler application/x-httpd-php\n</FilesMatch>\n#' /usr/local/apache22/conf/httpd.conf
sed 's#expose_php = On#expose_php = Off#g' -i /usr/local/apache22/conf/php.ini
sed 's#display_errors = On#display_errors = Off#g' -i /usr/local/apache22/conf/php.ini

A continuación instalaremos cronolog para la rotación de logs:

cd /usr/local/src
wget http://cronolog.org/download/cronolog-1.6.2.tar.gz
tar xzf cronolog-1.6.2.tar.gz
cd cronolog-1.6.2
./configure
make && make install

Finalmente instalamos eAccelerator:

yum install autoconf -y
cd /usr/local/src
wget http://bart.eaccelerator.net/source/0.9.6.1/eaccelerator-0.9.6.1.tar.bz2
tar xjf eaccelerator-0.9.6.1.tar.bz2
cd eaccelerator-*
phpize
./configure 
make && make install
cat >> /usr/local/apache22/conf/php.ini <<EOF

; eAccelerator
; Enable eAccelerator extension module
zend_extension = /usr/local/lib/php/extensions/no-debug-non-zts-20060613/eaccelerator.so
; Options for the eAccelerator module
eaccelerator.cache_dir = /var/www/eaccelerator.cache
eaccelerator.shm_size = 32
eaccelerator.enable = 1
eaccelerator.optimizer = 1
eaccelerator.check_mtime = 1
eaccelerator.filter = ""
eaccelerator.shm_max = 0
eaccelerator.shm_ttl = 3600
eaccelerator.shm_prune_period = 0
eaccelerator.shm_only = 1
eaccelerator.compress = 0
eaccelerator.compress_level = 9
eaccelerator.keys = "shm_only"
eaccelerator.sessions = "shm_only"
eaccelerator.content = "shm_only"
eaccelerator.debug = 0
EOF
mkdir -p /var/www/eaccelerator.cache
chown apache. /var/www/eaccelerator.cache

Para arrancar el apache con daemontools hacemos lo siguiente:

cat >/usr/local/supervise/apache22/run <<EOF
#!/bin/bash

tail /usr/local/apache22/logs/error_log -n 2 | grep "No space left on device: mod_rewrite: could not create rewrite_log_lock" 2>&1 >/dev/null

test \$? -eq 0 && ipcs -s | grep apache | awk ' { print \$2 } ' | xargs ipcrm sem

exec /usr/local/apache22/bin/httpd -DNO_DETACH -f /usr/local/apache22/conf/httpd.conf
EOF
chmod +x /usr/local/supervise/apache22/run
ln -s /usr/local/supervise/apache22/ /service/

2 comments to “Instalación de un servidor LAMP V (apache con PHP y eAccelerator)”

  1. Tan sólo aclarar para los novatillas. 😛
    El parámetro -with-lib=lib64 del configure de php indica dónde estan las librerías para entornos 64. Si no es el caso omitir el parámetro.

    Corrígeme Jordi si no estoy en lo cierto!
    😀

  2. Cierto, estas notas son para instalar en un sistema de 64bits. Para los de 32 simplemente se puede eliminar el

    --with-lib=lib64
    

    Muchas gracias por tu aportación

Deja un comentario:

XHTML - Tags permitidos:<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>