How to Compile PHP 8.0 in Debian 10?

On November 26, 2020, the PHP development team released PHP 8.0, PHP 8.0 comes with numerous improvements and new features such as:

  • Union Types
  • Named arguments
  • Match expressions
  • Attributes
  • Constructor Property Promotion
  • Nullsafe Operator
  • Weak Maps
  • Just In Time Compilation
  • and more

For more details about all new features check Migrating from PHP 7.4.x to PHP 8.0.x

Goals

  • Update to the latest version of PHP
  • Get benefits from the latest language features
  • Fix bugs from previous versions
  • Customize the installation process

Prerequisites

This tutorial assumes that:

  • You have some knowledge about GNU/Linux
  • You have Debian GNU/Linux installed
  • You are familiar with the command interpreter
  • You are familiar with the compilation process

Update your OS

$ sudo bash -c 'apt update && apt upgrade' 

Compile/Install

To compile/install PHP we will use the tool Butterfly Builder.

Download Butterfly Builder

You can install Butterfly Builder from GitLab or typing:

$ curl -# -LO https://gitlab.com/sr.libre/butterfly-builder/-/archive/debian10-php8.0/butterfly-builder-debian10-php8.0.tar.gz

If you get an error about missing curl you can install it by

$ sudo apt -y curl

Untar

$ tar xzvf butterfly-builder-debian10-php8.0.tar.gz

Change to the DIR butterfly-builder-debian10-php8.0

$ cd butterfly-builder-debian10-php8.0

The available PHP version while writing this tutorial is 8.0.0. Set the configuration values in the build.ini file according to your needs.

php_version=8.0.0
compression=tar.xz
php_mode=fpm
fpm_user=phpfpm
fpm_group=phpfpm
fpm_listen=9000
web_server=
install_prefix=/usr/
sysinit=systemd
sysinit_versioned=true
databases="mysql sqlite postgre"
php_env=dev

Download the digital signature for version 8.0.0 using the sigd tool, sigd uses the jq tool, install it by executing:

$ sudo apt -y install jq

Execute sigd

$ ./sigd

Compile/Install

./build

Once the installation process is finished, create a info script:

$ echo -e "<?php\nphpinfo();" > info.php

Start the native PHP server:

$ php -t . -S localhost:8080

Put in your browser the IP of the server where the installation was executed http://IP:8080/info.php.

PHP 8.0.0 Info

Conclusions

Now that you’ve learned how to compile PHP you can get all the advantages (bugs fixing, performance improvements and latest features) without waiting for the distribution developers and maintainers add the last stable PHP version to its repository.

How to compile PHP from the source code, 6 (11)

Leave a Comment

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.