"Newspaper" by Mustafa Khayat; https://flic.kr/p/bcFQm4; used under Creative Commons Attribution-NoDerivs 2.0 Generic (CC BY-ND 2.0) license

Notes from three PHP 7 upgrades

As I described late last year, this site runs on PHP 7 built from source. As a result, with each point release, I’ve had to recompile and relink.

Recompiling isn’t particularly challenging, but maintaining symlinks is key, as is building each version independently of the last.

Don’t bork everything

It wasn’t until 7.0.3 that I made a potentially-serious mistake, and fortunately I caught it before running make install. As I noted in my original post, each point release is built alongside the release I’m running, and I symlink the 7.0.0 directory to whichever release is active. Init scripts maintain their 7.0.0 reference, simplifying upgrades.

Since I’ve written out my configuration command in the prior post, I copy from there to build subsequent releases. This last time, I forgot to change the --prefix. Again, I fortunately caught this before installing the build.

Had I missed this, PHP 7 would’ve been broken because in overwriting the 7.0.0 symlink, I’d have lost the symlinks to the active configurations in the associated 7.0.X directory.

To remedy this, I ran the ./configure command again with the correct prefix, then re-ran make to rebuild PHP with the correct path.

Symlinks upon symlinks

So, I have a 7.0.0 symlink that points to the latest working build. The build is only half of my requirement, though. Now it’s time to update some symlinks.

With each release, I don’t want to lose and recreate my PHP configurations. Accordingly, each PHP 7 build contains symlinks to shared configurations found in /etc/; once again, refer to my first PHP 7 post for more details on my setup.

To begin, I symlink the new build to the existing configurations.

cd /usr/local/php7/7.0.3
mv etc etc.dist
ln -s /etc/php7 etc
ln -s /etc/php7.ini lib/php.ini

Again, if any of the above is unclear, see my Hello PHP 7! post.

Making the switch

Now that the new PHP 7 build is ready, switching is a two-step process.

First, update the symlink:

cd /usr/local/php7/
rm 7.0.0
ln -s 7.0.3 7.0.0

Next, restart PHP 7, completing the upgrade:

/etc/init.d/php7 restart

Cleanup

I prefer to wait a period before removing the previous version, lest any issues arise. Switching back is a matter of changing the 7.0.0 symlink as noted above, and the individual builds don’t occupy enough space to warrant an immediate purge.

When the time comes, both the build and source directories should be removed.

Leave a Reply

Your email address will not be published. Required fields are marked *