Tales of an IT Nobody

devbox:~$ iptables -A OUTPUT -j DROP

Running parallel versions of PHP – Part 2 May 14, 2009

The hard part is over, now for the easier stuff – for this part you’ll need:

  • Coffee
  • Patience

Now we compile and install:

Now if all goes well – the prefix you used in your configure (--prefix=/whatever)
will have the following directories in it:

The file we care about the most is located in the bin/ directory – called php-cgi.

Apache
First we need to enable the action module in Apache if it isn’t already:

Now we need to modify either a specific config file in the sites-enabled/ directory or your actual apache2.conf , add this line to where you deem appropriate:

* Make sure you change “/home/rovangju/misc/php53” to where you set your --prefix=/whatever/ value is. Leave the /bin at the end.

Next, simply reload apache: /etc/init.d/apache2 force-reload, if done right you shouldn’t get any errors.

We’re almost there!

Ok, now for the magic part, for demonstrative purposes – make a the following file structure in a browser-visible spot on your server:

Fill the index.php files with phpinfo(); – the idea is to just show the php version.

Now place this into php_test/php53/.htaccess:

This will re-map all .php files under that path to the newly compiled php-cgi file I mentioned earlier.

Now point a browser to both of those index files and hopefully you should see the version differences.

Troubleshooting notes:

  • Depending on where you actually put these files – the .htaccess may not be allowed to override the server defaults.
  • Your Apache error log is your friend !
  • If you get the timezone error like I did for strtotime, you can set it in your php.ini
  • Try restarting Apache once more – sometimes .htaccess files can be fiesty.
No Comments on Running parallel versions of PHP – Part 2
Categories: apache php

Running parallel versions of PHP – Part 1

With RC2 of the php5.3 release coming out, I wanted to run the new version alongside the stable version on our development server at M State. I wanted to be able to control this behavior via .htaccess files to control particular projects.

What you’ll need:

  • Reasonable compiling experience
  • Ability to satisfy dependencies
  • Understanding and access to your httpd.conf and to be able to reload/restart apache.

Do NOT compile now unless you completely understand how to install to a directory other than the default!

Start off by downloading and extracting the source and cd into the extracted directory.

Getting ready to configure:

Modules:
Before you configure, make sure you know which modules you want.
These are enabled by the myriad of --with-gd type switches.
If you don’t know what modules you have, run phpinfo(); and look for the configure string – OR you can try the command line tool php-config (or) php5-config if it’s been installed.

Prefix (*important*)
You’re not going to want php to be installed into the default path, this will rewrite your stable php5. Instead you want it to go into a custom directory – You can do this by setting the --prefix option when you run configure

Example: ./configure --prefix=/home/rovangju/misc/php53

Using current php.ini (Optional, recommended)
Change the paths to wherever your php.ini file is located. If you’re running older php and don’t have the conf.d folder – don’t use that line. This step may save you any nuances setup in your php.ini files.

--with-config-file-path=/etc/php5/apache2 \
--with-config-file-scan-dir=/etc/php5/apache2/conf.d \

Configuration summary
Now we’re ready to run the gauntlet of trying to configure and build. Expect to fulfil dependencies. At a minimum our configure will look like this: ./configure --prefix=/path/you/want

When/if your ./configure throws up that a library isn’t found – this is the least fun part when you have to install the dev libraries for those modules. So if your getting an error about libxml2 – You’ll likely want to install libxml2-dev. If you use apt this can be handy: apt-cache search libxml2 | grep "dev" – once you’ve installed it, try the configure again. It took me about half an hour of configure and installing the dev libs …

You can see my configure string as a comment to this post for example.

Continue to Part 2 when your configure doesn’t throw errors!
1 Comment on Running parallel versions of PHP – Part 1
Categories: apache php