Fixing PHP on Old Ubuntus

Note: This process has been superceded and entirely automated by the installer and this no longer has to be done by hand.


PHP 5 is currently limited to a maximum of 2 Gbyte file uploads, even on 64-bit systems. Fortunately this is easily fixed.

These instructions are for Ubuntu 12 and earlier only.

sudo su -

mkdir php-source
cd php-source
apt-get -y install debhelper bison chrpath freetds-dev libcurl4-openssl-dev libedit-dev libgd2-xpm-dev libgmp3-dev libmhash-dev libpam0g-dev libpspell-dev librecode-dev libsasl2-dev libsnmp-dev libsqlite0-dev libt1-dev libtidy-dev re2c unixodbc-dev
apt-get -y install apache2-prefork-dev autoconf automake flex hardening-wrapper libapr1-dev libbz2-dev libdb-dev libenchant-dev libgcrypt11-dev libglib2.0-dev libicu-dev libmysqlclient-dev libpcre3-dev libpq-dev libsqlite3-dev libxmltok1-dev libxml2-dev libxslt1-dev quilt
apt-get -y install libevent-dev mysql-server-core mysql-client
apt-get -y install clamav clamav-daemon
apt-get -y install php5 php5-cli php5-sqlite php5-ldap
apt-get -y install rrdtool
apt-get -y install libmagic-dev lemon language-pack-de

apt-get -y source php5-cgi
cd php5*
perl -i -pe 's/int zend_atoi/long zend_atoi/' Zend/zend_operators.[ch];
perl -i -pe 's/\n/@@@@@@/g' Zend/zend_operators.c;
perl -i -pe 's/(long zend_atoi.*?)int retval/$1long retval/m' Zend/zend_operators.c;
perl -i -pe 's/@@@@@@/\n/g' Zend/zend_operators.c;
perl -i -pe 's/atoi\(content_length\)/atol(content_length)/' `find sapi -name '*.c'`
perl -i -pe 's/\(uint\)( SG\(request_info\))/$1/' `find sapi -name '*.c'`;
perl -i -pe 's/uint post_data_length, raw/uint IGNORE_post_data_length, IGNORE_raw/' main/SAPI.h;
perl -i -pe 's/} sapi_request_info/\tlong post_data_length, raw_post_data_length;\n} sapi_request_info/' main/SAPI.h;
perl -i -pe 's/int read_post_bytes/long read_post_bytes/'    main/SAPI.h;
perl -i -pe 's/int boundary_len *= *0, *total_bytes *= *0/long total_bytes=0; int boundary_len=0/' main/rfc1867.c;
perl -i -pe 's/int max_file_size *= *0,/long max_file_size = 0; int /' main/rfc1867.c;

dpkg-buildpackage -rfakeroot -uc -b -j2
  • Ubuntu 10
    cd debian/libapache2-mod-php5/usr/lib/apache2/modules
    mv /usr/lib/apache2/modules/libphp5.so /usr/lib/apache2/modules/libphp5.so-UBUNTU
    cp libphp5.so /usr/lib/apache2/modules/
  • Ubuntu 11 or 12
    At this point, it will state "Build complete" but complain about an error. Don't worry about this, the build has still worked. If you wish to test the build, run the command "cd fpm-build && make test; cd .." and it should pass the tests (except #39863). Then:
    cd apache2-build/.libs
    mv /usr/lib/apache2/modules/libphp5.so /usr/lib/apache2/modules/libphp5.so-UBUNTU
    cp libphp5.so /usr/lib/apache2/modules/