Ubuntu: Instalar suPhp

Esta instalación ha sido probada en Ubuntu 14.04LTS pero también podría ser utilizada para un servidor de producción Debian.

Instalación de Paquetes Básicos

sudo apt-get install \
build-essential  \
fakeroot dh-make  \
debconf execstack  \
dh-modaliases  \
xserver-xorg-dev  \
automake  \
autoconf  \
libaprutil1  \
libaprutil1-dev  \
libsvn-dev  \
wx2.8-headers  \
libwxgtk2.8-dev  \
libxml2-dev  \
libpcre3-dev  \
libbz2-dev  \
libcurl4-openssl-dev  \
libjpeg-dev  \
libpng12-dev  \
libxpm-dev  \
libfreetype6-dev  \
libmysqlclient-dev  \
libt1-dev  \
libgd2-xpm-dev  \
libgmp-dev  \
libsasl2-dev  \
libmhash-dev  \
unixodbc-dev  \
freetds-dev  \
libpspell-dev  \
libsnmp-dev  \
libtidy-dev  \
libxslt1-dev  \
libmcrypt-dev  \
apache2  \
apache2-threaded-dev  \
libxml2  \
libaprutil1-dev  \
libxml2  \
libxml2-dev  \
libssl-dev  \
pkg-config  \
curl  \
libcurl4-nss-dev  \
enchant  \
libenchant-dev  \
libjpeg8  \
libjpeg8-dev  \
libpng12-0  \
libpng12-dev  \
libvpx1  \
libvpx-dev  \
libfreetype6  \
libfreetype6-dev  \
libt1-5  \
libt1-dev  \
libgmp10  \
libgmp-dev  \
libicu52 libicu-dev  \
mcrypt  \
libmcrypt4  \
libmcrypt-dev  \
libpspell-dev  \
libedit2  \
libedit-dev libsnmp30  \
libsnmp-dev  \
libxslt1.1  \
libxslt1-dev

Actualización para Ubuntu 15.01

sudo \
apt-get \
install \
build-essential \
fakeroot \
dh-make \
debconf \
execstack \
dh-modaliases \
xserver-xorg-dev \
automake \
autoconf \
libaprutil1 \
libaprutil1-dev \
libsvn-dev \
wx2.8-headers \
libwxgtk2.8-dev \
libxml2-dev \
libpcre3-dev \
libbz2-dev \
libcurl4-openssl-dev \
libjpeg-dev \
libpng12-dev \
libxpm-dev \
libfreetype6-dev \
libmysqlclient-dev \
libgd-dev \
libgmp-dev \
libsasl2-dev \
libmhash-dev \
unixodbc-dev \
freetds-dev \
libpspell-dev \
libsnmp-dev \
libtidy-dev \
libxslt1-dev \
libmcrypt-dev \
apache2 \
apache2-dev \
libxml2 \
libaprutil1-dev \
libxml2 \
libxml2-dev \
libssl-dev \
pkg-config \
curl \
libcurl4-openssl-dev \
enchant \
libenchant-dev \
libjpeg8 \
libjpeg8-dev \
libpng12-0 \
libpng12-dev \
libvpx-dev \
libfreetype6 \
libfreetype6-dev \
libgmp10 \
libgmp-dev \
libicu-dev \
mcrypt \
libmcryp4t \
libmcrypt-dev \
libpspell-dev \
libedit2 \
libedit-dev \
libsnmp30 \
libsnmp-dev \
libxslt1.1 \
libxslt1-dev \
postgresql-server-dev-9.4 \
postgresql-server-dev-all

Compilación de PHP

Iniciamos creando un enlace simbólico a una biblioteca que podría faltar potencialmente durante la compilación

sudo ln -s /usr/include/x86_64-linux-gnu/gmp.h /usr/include/gmp.h
On récupère les sources de PHP

sudo wget -O php-5.6.2.tar.gz http://fr2.php.net/get/php-5.6.2.tar.gz/from/this/mirror && tar xzvf php-5.6.2.tar.gz && cd php-5.6.2

Actualización de PHP 5.6.16

sudo wget -O php-5.6.16.tar.gz http://fr2.php.net/get/php-5.6.16.tar.gz/from/this/mirror &&\
tar xzvf php-5.6.16.tar.gz &&\
cd php-5.6.16

Luego compilamos

sudo \
./configure \
--prefix=/usr/local/php \
--with-apxs2=/usr/bin/apxs2 \
--with-config-file-path=/usr/local/php/conf \
--with-config-file-scan-dir=/usr/local/php/conf.d \
--enable-debug \
--with-openssl \
--with-kerberos \
--with-zlib \
--enable-calendar \
--with-curl \
--with-enchant \
--enable-exif \
--enable-ftp \
--with-gd \
--with-jpeg-dir=/usr \
--with-png-dir=/usr \
--with-vpx-dir=/usr \
--with-freetype-dir=/usr \
--with-t1lib \
--enable-exif \
--enable-gd-native-ttf \
--enable-gd-jis-conv \
--with-gettext \
--with-gmp \
--with-mhash \
--enable-intl \
--enable-mbstring \
--with-mcrypt \
--with-mysql \
--with-mysqli \
--enable-pcntl \
--with-pdo-mysql \
--with-pdo-pgsql \
--with-pgsql \
--with-pspell \
--with-libedit \
--with-readline \
--enable-shmop \
--enable-soap \
--enable-sockets \
--enable-sysvmsg \
--enable-sysvshm \
--with-xsl \
--enable-zip \
--with-pear \
--enable-zend-signals \
--enable-maintainer-zts \
--enable-bcmath &&\
sudo make &&\
sudo make install

Actualización para Ubuntu 15.01

sudo \
./configure \
--prefix=/usr/local/php \
--with-apxs2=/usr/bin/apxs2 \
--with-config-file-path=/usr/local/php/conf \
--with-config-file-scan-dir=/usr/local/php/conf.d \
--enable-debug \
--with-openssl \
--with-kerberos \
--with-zlib \
--enable-calendar \
--with-curl \
--with-enchant \
--enable-exif \
--enable-ftp \
--with-gd \
--with-jpeg-dir=/usr \
--with-png-dir=/usr \
--with-vpx-dir=/usr \
--with-freetype-dir=/usr \
--enable-exif \
--enable-gd-native-ttf \
--enable-gd-jis-conv \
--with-gettext \
--with-gmp \
--with-mhash \
--enable-intl \
--enable-mbstring \
--with-mcrypt \
--with-mysql \
--with-mysqli \
--enable-pcntl \
--with-pdo-mysql \
--with-pdo-pgsql \
--with-pgsql \
--with-pspell \
--with-libedit \
--with-readline \
--enable-shmop \
--enable-soap \
--enable-sockets \
--enable-sysvmsg \
--enable-sysvshm \
--with-xsl \
--enable-zip \
--with-pear \
--enable-zend-signals \
--enable-maintainer-zts \
--enable-bcmath &&\
sudo make && \
sudo make install

Compilación de suPHP

Recuperamos las fuentes

sudo wget  -O suphp-0.7.2.tar.gz  http://www.suphp.org/download/suphp-0.7.2.tar.gz &&\
sudo tar xzvf suphp-0.7.2.tar.gz &&\
cd suphp-0.7.2

Creamos los distintos directorios de gestión

sudo mkdir /etc/suphp && \
sudo mkdir /var/log/suphp

Luego necesitamos ejecutar algunos comandos para que la compilación se realice correctamente. Utilizaremos los siguientes comandos

sudo libtoolize --force #provides libtool support and replaces the default libtool files
sudo aclocal #creates the aclocal.m4 file by consolidating various macro files
sudo autoheader #creates a template file of C ‘#define’ statements
sudo automake --force-missing --add-missing #generates Makefile.in files
sudo autoconf #produces shell scripts for the automatic configuration

Ya podemos probar si tenemos todas las herramientas en la máquina para hacer la compilación final lanzando los siguientes comandos:

sudo libtoolize --force &&\
sudo aclocal && sudo autoheader &&\
sudo automake --force-missing --add-missing && sudo autoconf

Creamos los enlaces simbólicos para que los encabezados se encuentren correctamente (normalmente esto debería funcionar sin este paso)

sudo ln -s /usr/include/apr-1.0/*.h /usr/include/apache2/
sudo autoreconf -f -i && sudo libtoolize --force && sudo aclocal && sudo autoheader && sudo automake --force-missing --add-missing && sudo autoconf  && sudo ./configure --prefix=/usr --sysconfdir=/etc/suphp --with-apache-user=www-data --with-setid-mode=owner --with-apr=/usr/bin/apr-1-config --with-min-uid=33 --with-min-gid=33 --with-logfile=/var/log/suphp

Luego buscamos el archivo src/Makefile y editamos la línea MAYBE_AP=apache a MAYBE_AP=apache2.
Finalmente podemos compilar.

sudo make && sudo make install

Configuración de suPHP

Primero habilitamos los módulos más comunes (podemos deshabilitarlos según sea necesario con "a2dismod")

sudo a2enmod rewrite
sudo a2enmod suphp

Luego eliminamos toda la información presente en el archivo conf

sudo a2enmod suphp

Ahora configuramos el archivo conf de suPhp

sudo vi /etc/suphp/suphp.conf

[global]
;Path to logfile
logfile=/var/log/suphp/suphp.log

;Loglevel
loglevel=info

;User Apache is running as
webserver_user=www-data

;Path all scripts have to be in
docroot=/var/www:${HOME}/public_html

;Path to chroot() to before executing script
;chroot=/mychroot

; Security options
allow_file_group_writeable=false
allow_file_others_writeable=false
allow_directory_group_writeable=false
allow_directory_others_writeable=false

;Check wheter script is within DOCUMENT_ROOT
check_vhost_docroot=true

;Send minor error messages to browser
errors_to_browser=false

;PATH environment variable
env_path="/bin:/usr/bin"

;Umask to set, specify in octal notation
umask=0077

; Minimum UID
min_uid=33

; Minimum GID
min_gid=33

[handlers]
;Handler for php-scripts
application/x-httpd-suphp-php-cgi-562="php:/usr/local/php/bin/php-cgi-5.6.2"

;Handler for CGI-scripts
x-suphp-cgi="execute:!self"

Y el último paso, creamos un vhost para nuestro proyecto.

sudo vi /etc/apache2/sites-enabled/000-default.conf
<VirtualHost *:80>
ServerAdmin contact@localhost
ServerName  spikly.melis.dev
DocumentRoot /var/www/spikly-hyundai/trunk/melis/front/www
DirectoryIndex index.php

<Directory /var/www/spikly-hyundai/trunk/melis/front/www>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
DirectoryIndex index.php
</Directory>

suPHP_Engine on
suPHP_ConfigPath /var/www/spikly-hyundai/php.ini
suPHP_AddHandler application/x-httpd-suphp-php-cgi-562
AddHandler application/x-httpd-suphp-php-cgi-562 .php .php3 .php4 .php5

ErrorLog /var/log/error.log

# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
suPHP_UserGroup tbourdin tbourdin
CustomLog /var/log/access.log combined
</VirtualHost>