Category Archives: work

Installing PHP 5.4.0RC8 and Apache 2.4 on Ubuntu 11.10

About once every other week I try and spend some time at work thinking ahead. With PHP 5.4 on the horizon I began to wonder how our current Zend Framework application would fare if the SysAdmins decided to jump straight from PHP 5.2 to PHP 5.4. Would the site work at all? One way to find out. Lets install PHP 5.4RC8 and Apache 2.4.

I started by creating a fresh Ubuntu 11.10 VM. In complete disclosure, I removed some of the unneeded packages like LibreOffice first. I then cloned it so I would always have a base to work off of in the future.

Build Environment

Open a terminal prompt and switch to root.

sudo su -

This just makes life easier throughout the process. Normally I would recommend only switching to root when you fully need to, like when you run apt-get install or make install. Now lets make sure we have all the build environment pieces we need.

apt-get update
apt-get -y -q install make g++ flex bison build-essential zlib1g-dev binutils \
cmake automake autoconf libmcrypt-dev libmhash-dev libxslt1-dev \
libtidy-dev libbz2-dev libxml2-dev libssl-dev libmysqlclient16 libmysqlclient16-dev \
libpng12-dev libpng12-0 libpng3 libjpeg62 libjpeg62-dev libxpm-dev libpcre3 \
libpcre3-dev zlib1g zlib1g-dev libltdl-dev libltdl7 pkg-config \
libcurl4-openssl-dev libfreetype6 libfreetype6-dev libc-client2007e \
libc-client2007e-dev libkrb5-3 libkrb5-dev openssl libglobus-openssl \
libglobus-openssl-dev libcurl4-openssl-dev libicu-dev libicu44 libpspell-dev \
linux-libc-dev libc-dev-bin libc-bin libc-client2007e-dev eglibc-source \
libkrb5-3 libkrb5-dev libkrb53 libkrb5support0 libncurses5-dev libncurses5 \
ncurses-base ncurses-bin ncurses-term libaio-dev libedit-dev lynx

Certainly some of those are not totally needed if we are only checking to see if things install, but I want to make sure we have lots of bases covered. Now, time to get Apache 2.4. You can skip this portion if you want to only install PHP 5.4.

Apache

For Apache we need three pieces: the Apache Portable Runtime, APR Utils, and the Httpd server itself. Feel free to find a closer mirror. This code will download the latest greatest for today and install it into /usr/local/

# APR
wget http://mirrors.axint.net/apache//apr/apr-1.4.6.tar.gz
tar -xvzf apr-1.4.6.tar.gz
cd apr-1.4.6/
./configure
make
make install
cd ..

# APR Utils
wget http://mirrors.axint.net/apache//apr/apr-util-1.4.1.tar.gz
tar -xvzf apr-util-1.4.1.tar.gz
cd apr-util-1.4.1
./configure --with-apr=/usr/local/apr
make
make install
cd ..

# Apache
wget http://apache.petsads.us//httpd/httpd-2.4.1.tar.gz
tar -xvzf httpd-2.4.1.tar.gz
cd httpd-2.4.1
./configure --enable-file-cache --enable-cache --enable-disk-cache --enable-mem-cache --enable-deflate --enable-expires --enable-headers --enable-usertrack --enable-ssl --enable-cgi --enable-vhost-alias --enable-rewrite --enable-so --with-apr=/usr/local/apr/
make
make install
cd ..

The above worked rather painlessly for me once I knew that I had to install APR and APR Utils before the Httpd server. We will do the configuring of Apache in a bit. Lets install PHP 5.4RC8 first.

PHP

wget http://downloads.php.net/stas/php-5.4.0RC8.tar.gz
tar -xvzf php-5.4.0RC8.tar.gz
cd php-5.4.0RC8
'./configure' '--disable-debug' '--enable-inline-optimization' '--disable-all' '--enable-libxml' '--enable-session' '--enable-xml' '--enable-hash' '--with-pear' '--with-apxs2=/usr/local/apache2/bin/apxs' '--with-layout=GNU' '--enable-filter' '--with-pcre-regex' '--with-zlib' '--enable-simplexml' '--enable-xmlwriter' '--enable-dom' '--with-openssl' '--enable-pdo' '--with-pdo-sqlite' '--with-readline' '--with-sqlite3' '--with-iconv' '--disable-phar' '--with-libedit' '--enable-exif' '--with-bz2' '--with-gettext' '--with-mcrypt' '--with-mhash' '--with-gd' '--with-jpeg-dir' '--with-png-dir' '--with-zlib-dir' '--with-xpm-dir' '--with-xsl' '--with-tidy' '--with-freetype-dir' '--enable-gd-native-ttf' '--enable-mbstring' '--enable-sockets' '--enable-dom' '--enable-xml' '--enable-soap' '--enable-libxml' '--enable-session' '--enable-simplexml' --with-kerberos --with-curl '--with-mysql-sock' '--with-mysql=mysqlnd' '--with-mysqli=mysqlnd' '--with-pdo-mysql=mysqlnd' '--with-config-file-path=/usr/local/etc'

make
make install

PHP has tons of config options. I recommend checking your current install to see what it was built with and add those flags. Once nice thing here is that mysqlnd comes with PHP 5.4 so we do not have to link to an existing MySQL install. Another thing to note is that this sets php’s config directory to /usr/local/etc. Make sure to customize –with-config-file-path to wherever you want to store your php.ini.

Configuration

Speaking of php.ini, lets put one in place now.

cp php.ini-development /usr/local/etc/php.ini

And lets set up where Apache can find our files (unless you like putting things in /usr/local/apache2/htdocs/).

mkdir /var/www/
chgrp -R www-data /var/www/

Ready to configure Apache? I wasn’t! It had been over 4 years since I had done a source compile (I used to use Gentoo linux). Open up /usr/local/apache2/conf/httpd.conf in your favorite editor.

  1. Replace instances of /usr/local/apache2/htdocs with /var/www . There should be two.
  2. Add index.php to the DirectoryIndex line
  3. I uncommented #LoadModule rewrite_module modules/mod_rewrite.so and
  4. #Include conf/extra/httpd-vhosts.conf because I knew I was going to need them for my later testing.
  5. And finally I added 2 lines to make sure we parse the PHP
AddHandler php5-script .php
AddType text/html .php

I wanted to make sure Apache would start on boot so I added it to the main runlevel.

ln -s -T /usr/local/apache2/bin/apachectl /etc/rc2.d/S80apache

To find out what rcX.d you should use just execute runlevel. Shove the number it returns (2 in my case) in for X.

Moment of Truth

Three steps left. First, start up apache. If everything has gone well so far this should cause you no grief.

/usr/local/apache2/bin/apachectl start

Create a test php page:

echo "<?php phpinfo();" | cat > /var/www/index.php

And finally navigate to http://localhost/ on your VM.

Final Notes

I re-ran this process a couple times on copies of the initial VM clone to refine it a bit. It all worked stellar today. YMMV of course. I had to do some additional steps after this to test our ZF application since we use Oracle instead of MySQL. So far I have only found one minor Notice that popped up in 5.4 which was trivial to clean. Now if I could convince the SAs to upgrade to 5.4 once it goes gold…

Enjoy testing your code on PHP 5.4!

ZF Config XML vs Ini Showdown

Back at php|tek11 Rob Allen gave a talk on optimizing Zend Framework. During the tutorial he pointed out how you could cache your application config files so that they are not loaded and parsed at every request. This got me thinking about something that had been bugging me for a long time. What is the best format for your config file?

Back before ZF 1.0 there was a fair bit of confusion on how to do everything “right”, especially setting up a “modular” build. One of the first good examples out there was made by Dasprid, and he used an xml based application config. We are talking back in early 2007 when it was the wild west for ZF. Since then, I only see people using ini files.

Well, here it finally is, the official synthetic Zend_Config benchmark shootout.

Read more »

You’re going the wrong way

Level 19

I am sharing an office with a friend and our large white boards would not fit on the available walls, so we improvised by making them vertical. The instant I saw them installed I knew what had to be done. Click the thumbnail for the full size image.

Update:
I made it onto the front page of EpicWin!! As of Sept 20 there were 642 thumbs up and 31 thumbs down for it (probably the people who are not thinking with portals).

Update2 (20101004):
915 up, 45 down.

OSCONfusion

So I have spent the past week in Portland, OR at the O’Reilly Media’s OSCON 2010 and learned some useful things for my job, but it has also generated a fair bit of dissatisfaction.

The fun talks were more on the geeky side, like how to build a device to monitor the environment. It would be fun tostick a box on my parent’s dock to monitor Cayuga Lake’s water temperature, or better yet to make a small radio telescope and record the data.

In-between the very geeky things was a lot of rather boring stuff, so boring that I wonder what my role is in the programming world. Sure I can build large web-database applications that meet the needs of international health care research. Sure I can add little widgets to display pretty charts. Is this what I want to do? It was often more fun reading the ModRef magazine I brought. It does not help that a lot of people in the programming community think an open bar is the most exciting part of a convention. I really do not want to smell the partially digested alcohol on your breath. It is not pleasant.

Remote Work

Remind me again why I normally sit in front of a computer in Maryland…

Mug

I got my one year employment mug today. It is a nice dark cobalt color with my name and start date on it. I hear at five years you get a cupcake. I think I got the better deal. Too bad there is plenty of free coffee and tea in the break rooms but no free hot chocolate.

Inching toward the edge

It is not a good sign when one of the people supposedly on your development team asks a critical question like “so how do I install the code?” only 2 weeks before the demo.

Time is Time

I just did a quick calculation. Even though we moved further from my office, I am saving about 20 minutes per week in transit time from being on a better bus route. That amounts to 80 hours saved each year. I cannot complain!