Categories
howto

Installing PHP 5.4.0RC8 and Apache 2.4 on Ubuntu 11.10

php54Apache241About 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</pre>
<h3 style="font-family: Georgia, 'Times New Roman', 'Bitstream Charter', Times, serif; line-height: 19px; white-space: normal;"></h3>
<pre>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</pre>
<h3 style="font-family: Georgia, 'Times New Roman', 'Bitstream Charter', Times, serif; line-height: 19px; white-space: normal;"></h3>
<pre>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

</pre>
<h3 style="font-family: Georgia, 'Times New Roman', 'Bitstream Charter', Times, serif; line-height: 19px; white-space: normal;"></h3>
<pre>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'</pre>
<h3 style="font-family: Georgia, 'Times New Roman', 'Bitstream Charter', Times, serif; line-height: 19px; white-space: normal;"></h3>
<pre>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!