Ross's Shared News Items

Wednesday, March 04, 2015

HOWTO: Test php7 on Ubuntu 14.04 LAMP stack

So, you've heard php7 is going to be fast... you've heard it's not going to be released until late this year... and you'd really like to TEST it out with a test copy of an existing LAMP stack running on Ubuntu 14.04 now versus waiting until November or December or until the release of Ubuntu 16.04?

Yeah, that's what I was thinking. I figured there would be a ppa and packages, but I didn't find any... UPDATE: August 10th, 2015 - there is a PPA now -- you should try it first. https://launchpad.net/~ondrej/+archive/ubuntu/php-7.0

[historical content]... So... with a little help from: http://www.zimuel.it/install-php-7/ , I managed to refine a test process so that it is relatively easy and quick and works with apache.

Before you start... you may want to look at what has been or quickly will be deprecated in php7 and start getting your code in gear. https://wiki.php.net/rfc/remove_deprecated_functionality_in_php7

GIANT DISCLAIMER:


This is a gross hack. You'd be silly to do this on any production server. Do this on a throw-away VM, just for testing. My recipe below OVERWRITES the system php -- because I wanted a quick and dirty hack to keep as many settings the same as possible. If you don't have the ability to clone a vm or build a new test LAMP stack in a few minutes... do not proceed. You shouldn't be reading any further. Here be dragons!

OK... so you're still with me? You understand this is an EXPERIMENT... good.

Build a test Ubuntu 14.04 LAMP stack.
I'm *ASSUMING* you have some workload already that you want to test with php7 and that you're running Ubuntu 14.04 and your LAMP stack is already running.

All we're going to do is:
  • Add missing packages required to build php7 from latest source
  • Overwrite php5 with php7
  • Disable php5 in apache
  • Make existing Apache work with libphp7.so
  • restart apache and hope it worked
  • do some testing on our own


Add build dependencies for php5 -- this is probably a good idea and MAY pull in most if not all of the packages below.

sudo apt-get build-dep php5

Add missing requisite packages:

sudo apt-get install build-essential libt1-dev bison libbz2-dev libjpeg62-dev libpng12-dev libfreetype6-dev libgmp3-dev libmcrypt-dev libmysqlclient-dev libpspell-dev librecode-dev apache2-dev git

Symlink the gmp.h file into /usr/include/ so the makefile can find it. I tried explicitly specifying the path in configure and it didn't work, so... unless you know why, just make this symlink

ln -s /usr/include/x86_64-linux-gnu/gmp.h /usr/include/gmp.h

Check out the latest php source code

mkdir $HOME/php7
cd $HOME/php7
git clone https://git.php.net/repository/php-src.git

Change into the source directory and run buildconf

cd php-src
./buildconf

Configure php7 source code

./configure \
    --prefix=/usr \
    --with-config-file-path=/etc/php7/apache2 \
    --with-config-file-scan-dir=/etc/php7/apache2/conf.d \
    --enable-mbstring \
    --enable-zip \
    --enable-bcmath \
    --enable-pcntl \
    --enable-ftp \
    --enable-exif \
    --enable-calendar \
    --enable-sysvmsg \
    --enable-sysvsem \
    --enable-sysvshm \
    --enable-wddx \
    --with-curl \
    --with-mcrypt \
    --with-iconv \
    --with-gmp=/usr/include/x86_64-linux-gnu \
    --with-pspell \
    --with-gd \
    --with-jpeg-dir=/usr \
    --with-png-dir=/usr \
    --with-zlib-dir=/usr \
    --with-xpm-dir=/usr \
    --with-freetype-dir=/usr \
    --enable-gd-native-ttf \
    --enable-gd-jis-conv \
    --with-openssl \
    --with-pdo-mysql=/usr \
    --with-gettext=/usr \
    --with-zlib=/usr \
    --with-bz2=/bin \
    --with-recode=/usr \
    --with-mysqli=/usr/bin/mysql_config \
    --with-apxs2 \
    --enable-dtrace

NOTE: As of March 4th code, I had to remove the following line from configure above:
    --with-mysql=/usr \

NOTE: As of August 6th, I had to remove the following line from the configure above:
    --with-t1lib=/usr \

Build the code - now would be a good time for a cup of coffee.

make

Might as well run the tests, I got two errors that seemed safe to ignore out of over 10K tests. I chose not to email the dev list.

** Mar 5th, 2015 - UPDATE - after this code update ... there are a lot of failing tests that will need to be removed. #FIXME This update and removal of the mysql code broke my app on March 5th - looks like we're using ext/mysql - time to dig into code and use mysqli http://www.saotn.org/migrate-php-mysql-mysqli/

make test

Install php7 -AGAIN.... if you type the command below, you're overwriting your php-5.5.9 install and should ubuntu php packages be updated in the future and upgraded, you might be unhappy. We're just trying to do a quick test of php7... remember?

make install

Now... In case your app specificially calls out php5 binary as /usr/bin/php5, let's force php apps to use the new php...

cd /usr/bin
mv php5 php5.orig
mv phpize5 phpize5.orig
mv php-config5 php-config5.orig
ln -s php php5
ln -s phpize phpize5
ln -s php-config php-config5

We need a php7.conf file. Assuming your LAMP stack already worked with php5, path of least resistance is to copy existing one to new name.

cp /etc/apache2/mods-enabled/php5.conf /etc/apache2/mods-enabled/php7.conf

Disable php5 in apache - we can't have php5 and php7 enabled - then restart apache

a2dismod php5
/etc/init.d/apache2 restart

Create /etc/php7 directory by making a symlink to /etc/php5 - not clear if this is required - I just did it since I'd already hacked up so much of the php install already.

cd /etc/ && ln -s php5 php7

Check to see if this worked..


From commandline:

# php --version
PHP 7.0.0-dev (cli) (built: Mar  4 2015 20:49:17)
Copyright (c) 1997-2015 The PHP Group
Zend Engine v3.0.0-dev, Copyright (c) 1998-2015 Zend Technologies

From Apache webserver:

tail -200 /var/log/apache2/error.log
[Wed Mar 04 21:28:21.603995 2015] [mpm_prefork:notice] [pid 20692] AH00163: Apache/2.4.7 (Ubuntu) PHP/7.0.0-dev OpenSSL/1.0.1f configured -- resuming normal operations

Success!  (or... if not, maybe you need to do some debugging)

Now what?

You can do whatever you want. I chose to do an application benchmark, some manual QA testing of my app, and I wrote a blog post.

* opcache is now working once I updated the --with-config* statements above.

Just remember - when you're done testing and playing, destroy this test environment before a php package update overwrites everything. This was just for some quick tests, remember?

No comments: