Skip to content

Instantly share code, notes, and snippets.

@njh
Last active September 23, 2015 19:07
Show Gist options
  • Save njh/601712 to your computer and use it in GitHub Desktop.
Save njh/601712 to your computer and use it in GitHub Desktop.
Given a URL to a tarball, build a PHP CLI binary, with minimal dependancies.
#!/usr/bin/env perl
#
# Script to build a minimal version of PHP
#
# https://gist.github.com/njh/601712
#
use File::Basename;
use strict;
my $URL = $ARGV[0];
die "Error: missing URL of PHP to build" unless ($URL);
my $TARBALL = basename($URL);
my ($VERSION) = ($TARBALL =~ /(\d+\.\d+\.\d+)/);
my $DIRPATH="php-$VERSION";
if (`uname` =~ /^Darwin/) {
$ENV{'LDFLAGS'} .= " -lresolv";
}
unless (-e $TARBALL) {
print "Downloading: $URL\n";
safe_system('curl', '-o', $TARBALL, $URL);
}
if (-e $DIRPATH) {
print "Deleting old: $DIRPATH\n";
safe_system('rm', '-Rf', $DIRPATH);
}
safe_system('tar', '-zxvf', $TARBALL);
chdir($DIRPATH) or die "Failed to change directory: $!";
safe_system(
'./configure',
'--disable-cgi',
'--disable-fastcgi',
'--without-kerberos',
'--disable-bcmath',
'--with-bz2=/usr',
'--disable-calendar',
'--without-curl',
'--without-curlwrappers',
'--disable-dba',
'--disable-dbase',
'--disable-exif',
'--without-fbsql',
'--without-fdftk',
'--disable-ftp',
'--without-gd',
'--without-gettext',
'--without-gmp',
'--without-iconv',
'--without-imap',
'--without-ldap',
'--without-mcrypt',
'--without-ming',
'--without-msql',
'--without-mssql',
'--without-mysql',
'--without-mysqli',
'--without-ncurses',
'--without-adabas',
'--without-ibm-db2',
'--without-iodbc',
'--disable-pcntl',
'--disable-pdo',
'--without-pgsql',
'--without-libedit',
'--without-readline',
'--disable-soap',
'--without-sqlite',
'--without-xmlrpc',
'--with-openssl=/usr',
'--with-zlib',
'--with-zlib-dir=/usr',
'--enable-ctype',
'--enable-xml',
'--enable-filter',
'--enable-json',
'--enable-cli',
'--enable-dom',
'--enable-libxml',
'--enable-mbstring',
'--enable-mbregex',
'--enable-simplexml',
'--enable-hash'
);
safe_system('make');
safe_system('cp', 'sapi/cli/php', "../php");
sub safe_system {
my (@cmd) = @_;
print "Running: ".join(' ',@cmd)."\n";
if (system(@cmd)) {
die "Command failed";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment