Ubuntu: Install suPhp

This installation has been tested on Ubuntu 14.04LTS but could also be used for a Debian production server.

Installation of Basic Packages

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

Update for 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

PHP Compilation

We start by creating a symbolic link to a library that may potentially be missing during the compilation

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

PHP update 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

Then we compile

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

Update for 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

Compilation of suPHP

We retrieve the sources

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

We create the various management directories

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

Then we need to run some commands for the compilation to be done correctly. We will use the following commands

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

We can already test if we have all the tools on the machine to do the final compilation by launching the following commands:

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

We create the symbolic links so that the headers are correctly found (normally this should work without this step)

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

Then look for the src/Makefile file and edit the MAYBE_AP=apache line to MAYBE_AP=apache2.
We can finally compile.

sudo make && sudo make install

Configuration of suPHP

We first enable the most common modules (we can disable them as needed with "a2dismod")

sudo a2enmod rewrite
sudo a2enmod suphp

We then delete all the information present in the conf file

sudo a2enmod suphp

We now configure the suPhp conf file

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"

And the last step, we make a vhost for our project.

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>