heroku-buildpack-php

by travstoll

GitHub Readme.md

Apache+PHP build pack

This is a build pack bundling PHP and Apache for Heroku apps.

Configuration

The config files are bundled with the build pack itself:

  • conf/httpd.conf
  • conf/php.ini

Pre-compiling binaries

On a Heroku Dyno, one can run the following as executable text. After running it, /app will contain, among other entities, apache-2.2.25-1.tar.gz, php-5.3.27-1.tar.gz, and mcrypt-2.5.8-1.tar.gz which should be uploaded to a location that can be downloaded by the build pack (see the URIs in compile).

#!/bin/bash
set -uex
cd /tmp

# Heroku revision.  Must match in 'compile' program.
#
# Affixed to all vendored binary output to represent changes to the
# compilation environment without a change to the upstream version,
heroku_rev='-2'

# Clear /app directory
find /app -mindepth 1 -print0 | xargs -0 rm -rf

# Take care of vendoring Apache.
httpd_version=2.2.25
httpd_dirname=httpd-$httpd_version
httpd_archive_name=$httpd_dirname.tar.bz2

# Download Apache if necessary.
if [ ! -f $httpd_archive_name ]
then
    curl -LO ftp://ftp.osuosl.org/pub/apache//httpd/$httpd_archive_name
fi

# Clean and extract Apache.
rm -rf $httpd_dirname
tar jxf $httpd_archive_name

# Build and install Apache.
pushd $httpd_dirname
./configure --prefix=/app/apache --enable-rewrite --with-included-apr
make -s
make install -s
popd

# Take care of vendoring PHP.
php_version=5.3.27
php_dirname=php-$php_version
php_archive_name=$php_dirname.tar.bz2

# Download PHP if necessary.
if [ ! -f $php_archive_name ]
then
    curl -Lo $php_archive_name http://us1.php.net/get/php-5.3.27.tar.bz2/from/www.php.net/mirror
fi

# Clean and extract PHP.
rm -rf $php_dirname
tar jxf $php_archive_name

# Compile PHP
pushd $php_dirname
./configure --prefix=/app/php --with-apxs2=/app/apache/bin/apxs     \
--with-mysql --with-pdo-mysql --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-sockets     \
--with-pear --with-mysqli
make -s
make install -s
popd

# Copy in MySQL client library.
mkdir -p /app/php/lib/php
cp /usr/lib/libmysqlclient.so.16 /app/php/lib/php

# Sanitize default cgi-bin to rid oneself of Apache sample
# programs.
find /app/apache/cgi-bin/ -mindepth 1 -print0 | xargs -0 rm -r

# Stamp and archive binaries.
pushd /app
echo $httpd_version > apache/VERSION
tar -zcf apache-"$httpd_version""$heroku_rev".tar.gz apache
echo $php_version > php/VERSION
tar -zcf php-"$php_version""$heroku_rev".tar.gz php
popd

Meta

//Edited by Travis Stoll //Rev 1.0 9/30/2013