Can you recommend any guides for doing this? I have a test server at home I can mess with.
Sure. I don't know what your PHP config specs are but you're welcome to fiddle around with it until you get your desired result. I have 4 versions of PHP installed on my production server for my clients as I would like to avoid having multiple version of extensions installed such as PHP54-CURL, PHP55-CURL, PHP56-CURL and PHP70-CURL in my pkg version listings. My method makes the job much cleaner and I don't have to wait for weeks for latest PHP build to appear in the repo listing.
1) Remove all installed PHP packages or at least run a bare jail environment for clean PHP builds.
2) Install all the required packages for a successful build. You can use the pkg repository for this.
pkg install autoconf bison libxml2 curl jpeg png freetype2 libtool gmp libmcrypt aspell recode re2c
3) Download the PHP source code from the developer's website and untar the file.
4) This is where you may have to reconfigure the settings to install PHP in proper places in your system. Copy and paste the whole configure stuff to the command-line inside PHP directory and press enter.
- prefix is where base PHP executables and libraries will be installed.
- sysconfdir is where php configuration file will be installed.
I'm using LibreSSL and 'with-openssl-dir=/usr' is required otherwise it won't compile. If you're using OpenSSL then remove 'with-openssl-dir=/usr'.
Code:
./configure \
--prefix=/usr/local/php/5.6 \
--sysconfdir=/usr/local/etc/php/5.6 \
--with-config-file-scan-dir=/usr/local/etc/php/5.6 \
--with-fpm-user=www \
--with-fpm-group=www \
--localstatedir=/var \
--with-bz2 \
--with-curl \
--with-freetype-dir=/usr \
--with-gd \
--with-gettext=/usr \
--with-gmp \
--with-iconv \
--with-imap-ssl \
--with-jpeg-dir=/usr \
--with-mcrypt \
--with-mhash \
--with-mysql \
--with-mysqli \
--with-openssl \
--with-openssl-dir=/usr \
--with-pcre-regex \
--with-pear \
--with-pdo-mysql \
--with-pdo-sqlite \
--with-png-dir=/usr \
--with-pspell \
--with-recode=/usr \
--with-sqlite3 \
--with-zlib=/usr \
--with-zlib-dir=/usr \
--disable-all \
--disable-cgi \
--enable-bcmath \
--enable-ctype \
--enable-dom \
--enable-exif \
--enable-fileinfo \
--enable-filter \
--enable-fpm \
--enable-ftp \
--enable-gd-jis-conv \
--enable-gd-native-ttf \
--enable-hash \
--enable-json \
--enable-libxml \
--enable-mbstring \
--enable-mysqlnd \
--enable-opcache \
--enable-pdo \
--enable-phar \
--enable-posix \
--enable-session \
--enable-sockets \
--enable-simplexml \
--enable-tokenizer \
--enable-wddx \
--enable-xml \
--enable-xmlreader \
--enable-xmlwriter \
--enable-zip
5) After configuration is successfully completed and do this:
make install clean
That's it. You have working PHP version but you'll need to configure Nginx or Apache to access the PHP executables.
Sometimes after PHP upgrades, it'll be missing a newer library in
/usr/local/lib because FreeBSD's libraries haven't been updated in their repository yet. It's easy to fix by adding a softlink to an older library. It rarely happens but it's best to test PHP after upgrades to be sure everything is working correctly.
The rest of this information is optional and not required. If you want to have a default PHP version for the whole system then I would recommend doing this:
ln -s /usr/local/php/default/bin/php /usr/local/bin/php
ln -s /usr/local/php/default/bin/php-config /usr/local/bin/php-config
ln -s /usr/local/php/default/bin/phpize /usr/local/bin/phpize
This is the PHP file structure I have in my server.
Code:
/usr/local/php
/usr/local/php/5.6
/usr/local/php/5.6.24 -> 5.6 (softlink)
/usr/local/php/7.0
/usr/local/php/7.0.9 -> 7.0 (softlink)
/usr/local/php/default -> 5.6 (softlink)
If you want to start and stop PHP services in
/usr/local/etc/rc.d and I wrote this script:
Code:
#!/bin/sh
# PROVIDE: php56
# REQUIRE: LOGIN
# KEYWORD: shutdown
#
# Add the following line to /etc/rc.conf to enable php56:
# php56_enable="YES"
#
. /etc/rc.subr
name="php56"
nsub="php-fpm56"
rcvar=php56_enable
vers="5.6"
command="/usr/local/php/${vers}/sbin/php-fpm"
pidfile="/var/run/${nsub}/php-fpm.pid"
required_files="/usr/local/etc/php/${vers}/php-fpm.conf"
sig_stop="QUIT"
sig_reload="USR1"
load_rc_config "$name"
run_rc_command "$1"
Let me know if you need further help configuring Nginx to use specific PHP version. Hope this helps.