Skip to content

Commit

Permalink
Updated with EC2 PHP build script.
Browse files Browse the repository at this point in the history
  • Loading branch information
iphoting committed May 17, 2012
1 parent 28cd00e commit 528a10b
Show file tree
Hide file tree
Showing 2 changed files with 156 additions and 3 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,14 @@ The binary package will be produced in the current directory. Upload it to Amazo
### PHP
PHP with mcrypt requires libmcrypt to be installed. Vulcan cannot be used to build in this case.

To pre-compile PHP for Heroku, spin up an Amazon EC2 instance within the US-East Region: `ami-04c9306d`.
To pre-compile PHP for Heroku, spin up an Amazon EC2 instance within the US-East Region: `ami-04c9306d`. Refer to `support/ec2-up.sh` for some hints.

The use the following to compile PHP:
````
# after logging into EC2 instance, preferably with screen running.
$ curl -L "https://gist.github.com/raw/2650976/860a0a23aaf42069391717b1dd9fa4f7d4230563/build-php.sh" -o - | sudo bash
$ curl -L "https://github.com/iphoting/heroku-buildpack-php-tyler/raw/master/support/ec2-build-php.sh" -o - | sudo bash
````
You should review the build script at <https://gist.github.com/2650976>.
You should review the build script at <https://github.com/iphoting/heroku-buildpack-php-tyler/blob/master/support/ec2-build-php.sh>.

Usage
-----
Expand Down
153 changes: 153 additions & 0 deletions support/ec2-build-php.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
#!/bin/bash
# use AMI ami-04c9306d
# run this script as root on EC2 machine.

## EDIT
export S3_BUCKET="heroku-buildpack-php-tyler"
export LIBMCRYPT_VERSION="2.5.8"
export PHP_VERSION="5.4.1"
export APC_VERSION="3.1.10"
export PHPREDIS_VERSION="2.2.1"
## END EDIT

orig_dir=$( pwd )

echo "+ Using S3 update sources..."
sed -i 's/us-east-1.ec2.archive.ubuntu.com/us-east-1.ec2.archive.ubuntu.com.s3.amazonaws.com/g' /etc/apt/sources.list

echo "+ Updating apt-get sources..."
apt-get -y update

echo "+ Installing build dependencies..."
# install build deps
apt-get -y install g++ \
gcc \
libssl-dev \
libpng-dev \
libjpeg-dev \
libxml2-dev \
libmysqlclient-dev \
libpq-dev \
libpcre3-dev \
php5-dev \
php-pear \
curl \
libcurl3 \
libcurl3-dev \
php5-curl \
libsasl2-dev \
libbz2-dev \
ccache \
git-core
#libmcrypt-dev \

# update path to use ccache
export PATH=/usr/lib/ccache:$PATH

# retrieve ccache
echo "+ Fetching compiler cache..."
curl -f -L "https://s3.amazonaws.com/${S3_BUCKET}/ccache.tar.bz2" -o - | tar xj

mkdir build && pushd build

echo "+ Fetching libmcrypt libraries..."
# install mcrypt for portability.
mkdir -p /app/local
curl -L "https://s3.amazonaws.com/${S3_BUCKET}/libmcrypt-${LIBMCRYPT_VERSION}.tar.gz" -o - | tar xz -C /app/local

echo "+ Fetching PHP sources..."
#fetch php, extract
curl -L http://us.php.net/get/php-$PHP_VERSION.tar.bz2/from/www.php.net/mirror -o - | tar xj

pushd php-$PHP_VERSION

echo "+ Configuring PHP..."
# new configure command
## WARNING: libmcrypt needs to be installed.
./configure \
--prefix=/app/vendor/php \
--with-config-file-path=/app/vendor/php \
--with-config-file-scan-dir=/app/vendor/php/etc.d \
--disable-debug \
--disable-rpath \
--enable-fpm \
--enable-gd-native-ttf \
--enable-inline-optimization \
--enable-libxml \
--enable-mbregex \
--enable-mbstring \
--enable-pcntl \
--enable-soap=shared \
--enable-zip \
--with-bz2 \
--with-curl \
--with-gd \
--with-gettext \
--with-jpeg-dir \
--with-mcrypt=/app/local \
--with-iconv \
--with-mhash \
--with-mysql \
--with-mysqli \
--with-openssl \
--with-pcre-regex \
--with-pdo-mysql \
--with-png-dir \
--with-zlib \
--without-pdo-sqlite \
--without-sqlite3

echo "+ Compiling PHP..."
# build & install it
make install

popd

# update path
export PATH=/app/vendor/php/bin:$PATH

# configure pear
pear config-set php_dir /app/vendor/php

echo "+ Installing APC..."
# install apc from source
curl -L http://pecl.php.net/get/APC-${APC_VERSION}.tgz -o - | tar xz
pushd APC-${APC_VERSION}
# php apc jokers didn't update the version string in 3.1.10.
sed -i 's/PHP_APC_VERSION "3.1.9"/PHP_APC_VERSION "3.1.10"/g' php_apc.h
phpize
./configure --enable-apc --enable-apc-filehits --with-php-config=/app/vendor/php/bin/php-config
make && make install
popd

echo "+ Installing memcache..."
# install memcache
yes '' | pecl install memcache
# answer questions
# "You should add "extension=memcache.so" to php.ini"

echo "+ Installing phpredis..."
# install phpredis
git clone git://github.com/nicolasff/phpredis.git
pushd phpredis
git checkout ${PHPREDIS_VERSION}

phpize
./configure
make && make install
# add "extension=redis.so" to php.ini
popd

echo "+ Packaging PHP..."
# package PHP
echo "5.4.1" > /app/vendor/php/VERSION
pushd /app/vendor/php
tar czf $orig_dir/php-${PHP_VERSION}-with-fpm-heroku.tar.gz *
popd

echo "+ Binaries are packaged in $orig_dir/*.tar.gz. Upload to s3 bucket of your choice."

tar cjf ccache.tar.bz2 .ccache/

echo "+ Compiler cache packaged in $orig_dir/ccache.tar.bz2. Upload to s3 bucket of your choice."
echo "+ Done!"

0 comments on commit 528a10b

Please sign in to comment.