It is easier than you think! Here is what I did on my Ubuntu 22.04 installation
sudo apt install -y pkg-config build-essential autoconf bison re2c libcurl4-gnutls-dev libxml2-dev libssl-dev libzip-dev libzip4
git clone https://github.com/php/php-src.git
cd php-src
# Take the latest PHP 8.4 tag
git checkout PHP-8.4.6
# Clean up the repository from any temporary build files.
git clean -Xdf
# Build PHP
./buildconf
# With few useful extensions
./configure --disable-all --with-curl --with-iconv --enable-dom --with-libxml --enable-phar --enable-filter --with-openssl --with-zip --with-zlib
make -j4
You can then install PHP in the system with:
sudo make install
Or simply use the executable, CLI is located under ./sapi/cli/php.
If you’re doing local development, then xdebug is a must, let’s add it as well.
git clone git://github.com/xdebug/xdebug.git
cd xdebug
# Let's make sure we're using PHP we just compiled
/usr/local/bin/phpize
./configure --enable-xdebug
make
make install
To confirm you have the right PHP with xdebug review the output of:
php --info