Build PHP7 without installing

I'm running FreeBSD 11.1 with its stock PHP 5.6.34, which is generally OK since all of my recent PHP code is written for PHP 5 (upgraded from PHP 4, and from PHP 3 before that). However, there are third-party packages such as Laravel that require PHP7, and I have some need/desire to work with such programs. Consequently, I'm trying to use php7mar to identify issues in my PHP code base that need to be resolved before changing to PHP7.

For its syntax checks, php7mar needs a PHP7 binary to use for testing. However, one cannot have PHP5 and PHP7 installed on the same machine at the same time. My solution was to go into the ports tree and make php72 without doing make install. I had to comment out CONFLICTS= php56-* in the Makefile to get it to build, and was concerned when it said it was installing when make finished, but no damage was done. The port build gave me a binary in the working directory that I thought I'd be able to use for php7mar using its --php=" option to specify the location of the CLI binary - but it still complained with
Code:
ERROR!  Syntax checking was selected and a PHP binary lower than 7.0.0-dev was specified.

I tried
Code:
# /usr/ports/lang/php72/work/stage/usr/local/bin/php -r 'echo phpversion()."\n";'
and got a long list of errors about not being able to load PHP7 dynamic modules before the binary printed 7.2.3.

Next I went to the php72-extensions directory and tried a similar make there (including a Makefile edit to comment out IGNORE_WITH_PHP= 56). That failed with
Code:
Unknown extension sodium for PHP 56.
so I added to /etc/make.conf
Code:
DEFAULT_VERSIONS+= php=72
but still got the same result when I tried to build the extensions.

So it seems that in order to build PHP7 and its extensions, PHP 5 has to be removed. Since this is a production server, I pretty obviously cannot do that! What I'm considering is setting up a jail, removing PHP 5 from the jail, and doing the PHP7 build there. Will that work? Can I remove PHP5 from the jail without deinstalling it in the root environment? Is there another way to do this, short of having another machine to build PHP7 on (which isn't an option at the moment)?

----
N.B.: I tried searching the forums for "make php7 without installing" and got a disclaimer at the top of the results saying
The following words were not included in your search because they are too short, too long, or too common: without

after doing the same search using "not" instead of "without" resulted in the "same" warning - "not" was excluded. In both cases, the word exclusion totally changed the meaning of the search, so the results were completely useless. I tried to find an answer here in the forums before asking this question...
 
You may find this post useful https://forums.freebsd.org/threads/multiple-version-of-php.59624/post-353039 and then looking for details in ports(7)

Regarding search - in most cases I don't bother to try site specific search, because googling with "freebsd + search term" gives best results, usually from here or the lists. If you want to narrow search to specific site, you can use site operator, just try "multiple php versions site:forums.freebsd.org" and see.
 
You should create a jail. That's all I know (used to hear pro people here said, I'm never use a jail).
 
Install a FreeBSD jail or a vanilla FreeBSD on a separate machine. Install PHP7 and php7mar on it. Check and fix your code. Scrap it.

There are few ports that would help you set-up a jail, like sysutils/ezjail (ezjail-admin(8)) or sysutils/iocage (iocage(8)), but with some effort you can unpack base system in a subdirectory and use jail(8) directly. Then it is just pkg install php7 ... and mount_nullfs(8) to be able to share your source code between host and jail.

Basically jails also enable you to have multiple PHP versions installed simultaneously: nginx(8) as a reverse proxy and run multiple PHP applications, using different PHP versions, in jails.
 
Yes jail is the way to go. We run PHP 7.1 in the host and 5.6 in a jail.

Some tips for your specific case:

1) Create jail (use same IP as host to avoid private IPs and NAT)
2) Use /etc/fstab.jail to mount the partition with the php code to be accessible from jail
3) You can't run php from host as "jexec jail /usr/local/bin/php" as php will try to load libraries from the host (which has different PHP version) but you have to first use "jexec jail" to chroot inside jail.
 
Back
Top