Skip to content

Commit

Permalink
improved build w/ vulcan, stripped sasl, postgres support from php an…
Browse files Browse the repository at this point in the history
…d smaller binaries, changing the serverlimit back to 8 clients, log request time to serve

added jpeg and PNG support for GD. bsdiff so releases can simply be patched against the base buildpack binary,
mcrypt support, missing libmemcached.so.11
  • Loading branch information
winglian committed Sep 29, 2012
1 parent a429092 commit 657ca54
Show file tree
Hide file tree
Showing 7 changed files with 156 additions and 91 deletions.
83 changes: 4 additions & 79 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ This is a build pack bundling PHP and Apache for Heroku apps.
Configuration
-------------

The config files are bundled with the LP itself:
The config files are bundled with the buildpack itself:

* conf/httpd.conf
* conf/php.ini
Expand All @@ -15,82 +15,8 @@ The config files are bundled with the LP itself:
Pre-compiling binaries
----------------------

# use AMI ami-5c9b4935
apt-get -y update && apt-get -y install g++ gcc libssl-dev libpng-dev libxml2-dev libmysqlclient-dev libpq-dev libpcre3-dev php5-dev php-pear curl libcurl3 libcurl3-dev php5-curl libsasl2-dev libmcrypt-dev

#download all the srcs
curl -L http://www.apache.org/dist/httpd/httpd-2.2.22.tar.gz -o /tmp/httpd-2.2.22.tar.gz
curl -L http://us.php.net/get/php-5.3.10.tar.gz/from/us2.php.net/mirror -o /tmp/php-5.3.10.tar.gz
curl -L https://launchpad.net/libmemcached/1.0/1.0.4/+download/libmemcached-1.0.4.tar.gz -o /tmp/libmemcached-1.0.4.tar.gz
curl -L http://pecl.php.net/get/memcached-2.0.1.tgz -o /tmp/memcached-2.0.1.tgz

#untar all the srcs
tar -C /tmp -xzvf /tmp/httpd-2.2.22.tar.gz
tar -C /tmp -xzvf /tmp/php-5.3.10.tar.gz
tar -C /tmp -xzvf /tmp/libmemcached-1.0.4.tar.gz
tar -C /tmp -xzvf /tmp/memcached-2.0.1.tgz

#make the directories
mkdir /app
mkdir /app/{apache,php,local}
mkdir /app/php/ext
mkdir /app/local/{lib,bin}

#copy libs
cp -a /usr/lib/libmcrypt* /app/local/lib/
cp -a /usr/lib/libmysqlclient* /app/local/lib/
cp -a /usr/lib/libsasl2* /app/local/lib/

cp -a /usr/bin/mysql_config /app/local/bin/

export CFLAGS='-g0 -O2'
export CXXFLAGS="${CFLAGS}"

# apache
cd /tmp/httpd-2.2.22
./configure --prefix=/app/apache --enable-rewrite --enable-so --enable-deflate --enable-expires --enable-headers
make && make install

# php
cd /tmp/php-5.3.10
./configure --prefix=/app/php --with-apxs2=/app/apache/bin/apxs --with-mysql=mysqlnd --with-pdo-mysql=mysqlnd --with-pgsql --with-pdo-pgsql --with-iconv --with-gd --with-curl=/usr/lib --with-config-file-path=/app/php --enable-soap=shared --with-openssl --enable-mbstring --with-mhash --enable-pcntl --enable-mysqlnd --with-pear --with-mysqli=mysqlnd
make && make install

# libmemcached
cd /tmp/libmemcached-1.0.4
./configure --prefix=/app/local
make && make install

/app/php/bin/pear config-set php_dir /app/php
/app/php/bin/pecl install memcache
/app/php/bin/pecl install apc

# pecl memcached
cd /tmp/memcached-2.0.1
# edit config.m4 line 21 so no => yes ############### IMPORTANT!!! ###############
sed -i -e '21 s/no, no/yes, yes/' /tmp/memcached-2.0.1/config.m4
/app/php/bin/phpize
./configure --with-libmemcached-dir=/app/local/ --prefix=/app/php --with-php-config=/app/php/bin/php-config
make && make install

# make it a little leaner
rm -rf /app/apache/manual/

cp /app/local/lib/libsasl2.so.2 /app/php/ext/
cp /usr/lib/libmcrypt.so.4 /app/php/ext/
cp /usr/lib/libmysqlclient.so.16 /app/php/ext/
cp /app/local/lib/libmemcachedutil.so.2 /app/php/ext/
cp /app/local/lib/libmemcached.so.9 /app/php/ext/
cp /app/local/lib/libmemcachedprotocol.so.0 /app/php/ext/
cp /app/local/lib/libhashkit.so.1 /app/php/ext/

# package
cd /app
echo '2.2.22' > apache/VERSION
tar -cv apache | gzip -c9 > apache-2.2.22.tar.gz
echo '5.3.10' > php/VERSION
tar -cv php | gzip -c9 > php-5.3.10.tar.gz

vulcan build -v -s ./build -p /tmp/build -c "./vulcan.sh"
cp /tmp/build.tgz src/build.tgz

Hacking
-------
Expand All @@ -101,5 +27,4 @@ To change this buildpack, fork it on Github. Push up changes to your fork, then
Meta
----

Created by Pedro Belo.
Many thanks to Keith Rarick for the help with assorted Unix topics :)
Original buildpack by Pedro Belo. https://github.com/heroku/heroku-buildpack-php
28 changes: 19 additions & 9 deletions bin/compile
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
set -e

# config
APACHE_VERSION="2.2.22"
APACHE_VERSION="2.2.23"
APACHE_PATH="apache"
PHP_VERSION="5.3.10"
PHP_VERSION="5.3.17"
PHP_PATH="php"
BUILDPACK_VERSION="1.2"


BIN_DIR=$(dirname $0)
BUILD_DIR=$1
Expand All @@ -30,13 +32,16 @@ if [ -f www/Procfile ]; then
mv www/Procfile .
fi

APACHE_URL="https://s3.amazonaws.com/heroku-buildpack-binaries/apache-$APACHE_VERSION.tar.gz"
echo "-----> Bundling Apache version $APACHE_VERSION"
curl --silent --max-time 60 --location "$APACHE_URL" | tar xz
BP_URL="https://s3.amazonaws.com/licorice-labs-buildpacks/apache-$APACHE_VERSION-php-$PHP_VERSION-v$BUILDPACK_VERSION.tar.gz"
echo "-----> Bundling Apache $APACHE_VERSION PHP $PHP_VERSION build $BUILDPACK_VERSION"
curl --silent --max-time 60 --location "$BP_URL" | tar xz

PHP_URL="https://s3.amazonaws.com/heroku-buildpack-binaries/php-$PHP_VERSION.tar.gz"
echo "-----> Bundling PHP version $PHP_VERSION"
curl --silent --max-time 60 --location "$PHP_URL" | tar xz
# echo "-----> Extracting bsdiff binary"
# tar xzf $LP_DIR/src/bsdiff.tgz
# echo "-----> Bundling Apache $APACHE_VERSION/PHP $PHP_VERSION build"
# gunzip $LP_DIR/src/build.tgz
# local/bin/bspatch $LP_DIR/src/build.tar $LP_DIR/src/build-apache-$APACHE_VERSION-php-$PHP_VERSION.tar $LP_DIR/src/build.bsdiff
# tar xf $LP_DIR/src/build-apache-$APACHE_VERSION-php-$PHP_VERSION.tar

# update config files
cp $LP_DIR/conf/httpd.conf $APACHE_PATH/conf
Expand All @@ -46,6 +51,8 @@ cp $LP_DIR/conf/php.ini php
mkdir -p bin
ln -s /app/php/bin/php bin/php

export LD_LIBRARY_PATH=$BUILD_DIR/local/lib

# set a slug_id identifier
slug_id=$(php/bin/php -r "echo md5(uniqid('', TRUE));")
echo $slug_id > SLUG_ID
Expand All @@ -57,14 +64,17 @@ if [ -n "\${WWWROOT:+x}" ]; then
sed -ie "s%/app/www%/app/www\$WWWROOT%" /app/apache/conf/httpd.conf
fi
export HW_ADDR=\`/sbin/ifconfig eth0 | grep HWaddr | awk '{print \$5}'\`
echo "SetEnv HW_ADDR \$HW_ADDR" >> /app/apache/conf/httpd.conf;
for var in \`env|cut -f1 -d=\`; do
echo "PassEnv \$var" >> /app/apache/conf/httpd.conf;
done
touch /app/apache/logs/error_log
touch /app/apache/logs/access_log
tail -F /app/apache/logs/error_log &
tail -F /app/apache/logs/access_log &
export LD_LIBRARY_PATH=/app/php/ext
export LD_LIBRARY_PATH=/app/local/lib
export PHP_INI_SCAN_DIR=/app/www
# let's check for hook scripts
Expand Down
13 changes: 13 additions & 0 deletions build/bsdiff.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash

cd /tmp
curl -O curl -O http://www.daemonology.net/bsdiff/bsdiff-4.3.tar.gz
tar -xzf bsdiff-4.3.tar.gz
cd bsdiff-4.3
sed -i '13 s/^/#/' Makefile
sed -i '14 s/^/#/' Makefile
sed -i '15 s/^/#/' Makefile
make
mkdir -p /tmp/build/local/bin
cp bsdiff /tmp/build/local/bin
cp bspatch /tmp/build/local/bin
105 changes: 105 additions & 0 deletions build/vulcan.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
#!/bin/bash
set -e

mkdir /app/local
mkdir /app/local/lib
mkdir /app/local/bin
mkdir /app/local/include
mkdir /app/apache
mkdir /app/php
mkdir /app/php/ext

cd /tmp
curl -O http://mirrors.us.kernel.org/ubuntu//pool/universe/m/mcrypt/mcrypt_2.6.8-1_amd64.deb
curl -O http://mirrors.us.kernel.org/ubuntu//pool/universe/libm/libmcrypt/libmcrypt4_2.5.8-3.1_amd64.deb
curl -O http://mirrors.us.kernel.org/ubuntu//pool/universe/libm/libmcrypt/libmcrypt-dev_2.5.8-3.1_amd64.deb
ls -tr *.deb > packages.txt
while read l; do
ar x $l
tar -xzf data.tar.gz
rm data.tar.gz
done < packages.txt

cp -a /tmp/usr/include/* /app/local/include
cp -a /tmp/usr/lib/* /app/local/lib

# curl -L ftp://mcrypt.hellug.gr/pub/crypto/mcrypt/libmcrypt/libmcrypt-2.5.7.tar.gz -o /tmp/libmcrypt-2.5.7.tar.gz
# curl -L ftp://ftp.andrew.cmu.edu/pub/cyrus-mail/cyrus-sasl-2.1.25.tar.gz -o /tmp/cyrus-sasl-2.1.25.tar.gz
curl -L https://launchpad.net/libmemcached/1.0/1.0.11/+download/libmemcached-1.0.11.tar.gz -o /tmp/libmemcached-1.0.11.tar.gz
curl -L http://www.apache.org/dist/httpd/httpd-2.2.23.tar.gz -o /tmp/httpd-2.2.23.tar.gz
curl -L http://us.php.net/get/php-5.3.17.tar.gz/from/us2.php.net/mirror -o /tmp/php-5.3.17.tar.gz
curl -L http://pecl.php.net/get/memcached-2.1.0.tgz -o /tmp/memcached-2.1.0.tgz

# tar -C /tmp -xzf /tmp/libmcrypt-2.5.7.tar.gz
# tar -C /tmp -xzf /tmp/cyrus-sasl-2.1.25.tar.gz
tar -C /tmp -xzf /tmp/libmemcached-1.0.11.tar.gz
tar -C /tmp -xzf /tmp/httpd-2.2.23.tar.gz
tar -C /tmp -xzf /tmp/php-5.3.17.tar.gz
tar -C /tmp -xzf /tmp/memcached-2.1.0.tgz

export CFLAGS='-g0 -O2 -s -m64 -march=core2 -mtune=generic -pipe '
export CXXFLAGS="${CFLAGS}"
export CPPFLAGS="-I/app/local/include"
export LD_LIBRARY_PATH="/app/local/lib"
export MAKEFLAGS="-j5"
export MAKE_CMD="/usr/bin/make $MAKEFLAGS"

# cd /tmp/libmcrypt-2.5.7
# ./configure --prefix=/app/local --disable-posix-threads --enable-dynamic-loading --enable-static-link
# ${MAKE_CMD} && ${MAKE_CMD} install

cd /tmp/httpd-2.2.23
./configure --prefix=/app/apache --enable-rewrite --enable-so --enable-deflate --enable-expires --enable-headers
${MAKE_CMD} && ${MAKE_CMD} install

cd /tmp/php-5.3.17
./configure --prefix=/app/php --with-apxs2=/app/apache/bin/apxs --with-mysql=mysqlnd --with-pdo-mysql=mysqlnd --with-iconv --with-gd --with-curl=/usr/lib --with-config-file-path=/app/php --enable-soap=shared --with-openssl --enable-mbstring --with-mhash --enable-mysqlnd --with-pear --with-mysqli=mysqlnd --disable-cgi --with-jpeg-dir --with-png-dir --with-mcrypt=/app/local --enable-static
${MAKE_CMD} && ${MAKE_CMD} install

/app/php/bin/pear config-set php_dir /app/php
/app/php/bin/pecl install igbinary
echo " " | /app/php/bin/pecl install memcache
echo " " | /app/php/bin/pecl install apc

# cd /tmp/cyrus-sasl-2.1.25
# ./configure --prefix=/app/local
# ${MAKE_CMD} && ${MAKE_CMD} install
# export SASL_PATH=/app/local/lib/sasl2

cd /tmp/libmemcached-1.0.11
./configure --prefix=/app/local
# the configure script detects sasl, but is still foobar'ed
# sed -i 's/LIBMEMCACHED_WITH_SASL_SUPPORT 0/LIBMEMCACHED_WITH_SASL_SUPPORT 1/' Makefile
${MAKE_CMD} && ${MAKE_CMD} install

# for libmemcached 1.0.4
# LDFLAGS=-L/app/local/lib ./configure --prefix=/app/local --with-libsasl2-prefix=/usr

cd /tmp/memcached-2.1.0
/app/php/bin/phpize
./configure --with-libmemcached-dir=/app/local \
--prefix=/app/php \
--enable-memcached-igbinary \
--enable-memcached-json \
--with-php-config=/app/php/bin/php-config \
--enable-static
${MAKE_CMD} && ${MAKE_CMD} install

echo '2.2.23' > /app/apache/VERSION
echo '5.3.17' > /app/php/VERSION
mkdir /tmp/build
mkdir /tmp/build/local
mkdir /tmp/build/local/lib
mkdir /tmp/build/local/lib/sasl2
cp -a /app/apache /tmp/build/
cp -a /app/php /tmp/build/
# cp -aL /usr/lib/libmysqlclient.so.16 /tmp/build/local/lib/
# cp -aL /app/local/lib/libhashkit.so.2 /tmp/build/local/lib/
cp -aL /app/local/lib/libmcrypt.so.4 /tmp/build/local/lib/
cp -aL /app/local/lib/libmemcached.so.11 /tmp/build/local/lib/
# cp -aL /app/local/lib/libmemcachedprotocol.so.0 /tmp/build/local/lib/
# cp -aL /app/local/lib/libmemcachedutil.so.2 /tmp/build/local/lib/
# cp -aL /app/local/lib/sasl2/*.so.2 /tmp/build/local/lib/sasl2/

rm -rf /tmp/build/apache/manual/

4 changes: 2 additions & 2 deletions conf/httpd.conf
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ ServerRoot "/app/apache/"
#Listen 12.34.56.78:80
Listen ${PORT}

ServerLimit 1
MaxClients 1
ServerLimit 8
MaxClients 8
ListenBackLog 1024

#
Expand Down
14 changes: 13 additions & 1 deletion conf/php.ini
Original file line number Diff line number Diff line change
Expand Up @@ -1906,9 +1906,21 @@ extension=apc.so
apc.stat=0

[memcache]
;extension=memcache.so
; extension=memcache.so

[memcached]
extension=memcached.so
memcached.use_sasl = 1

[igbinary]
extension=igbinary.so
; Use igbinary as session serializer
session.serialize_handler=igbinary

; Enable or disable compacting of duplicate strings
; The default is On.
igbinary.compact_strings=On

; Use igbinary as serializer in APC cache (3.1.7 or later)
; apc.serializer=igbinary

Binary file added src/bsdiff.tgz
Binary file not shown.

0 comments on commit 657ca54

Please sign in to comment.