Build PHP 7.3.2 on Debian with PGO

Install build dependencies:

apt build-dep php

Configure:

CFLAGS='-O3 -march=native' \
CXXFLAGS="$CFLAGS" \
./configure \
--prefix=$HOME/opt/php-7.3.2 \
--enable-fpm \
--with-fpm-systemd \
--with-openssl \
--with-zlib \
--enable-bcmath \
--with-bz2 \
--enable-calendar \
--with-curl \
--enable-ftp \
--with-gd \
--with-gmp \
--with-gettext \
--with-mhash \
--enable-intl \
--enable-mbstring \
--with-mysqli \
--enable-pcntl \
--with-pdo-mysql \
--with-readline \
--enable-soap \
--enable-sockets \
--with-xsl \
--enable-zip

Build, install the binaries that will be used for profiling:

make -j`nproc` prof-gen
make install

Start your application using PHP's development server:

php -d zend_extension=opcache.so -S localhost:8888 -t /path/to/app

Generate some traffic to collect profiling data:

ab -t 30 http://localhost:8888/

Stop the development server, then save the generated profiles before cleaning the build:

find -name '*.gcda' -exec tar cvf profiles.tar {} +
make clean

Build, install the optimized binaries:

tar xvf profiles.tar
make -j`nproc` prof-use
make install